看到网上一个demo,贴来求教一下:public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "aaa.jpg");
Uri imgUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri);
startActivity(intent);
}
});
}
}布局就一个按钮,不贴了
manifest添加拍照和写文件权限,跑起来,然后问题来了,手机6.0的,没有动态申请权限,居然麻溜地打开了相机还把照片存下来了,想请问大神这是什么黑科技
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "aaa.jpg");
Uri imgUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri);
startActivity(intent);
}
});
}
}布局就一个按钮,不贴了
manifest添加拍照和写文件权限,跑起来,然后问题来了,手机6.0的,没有动态申请权限,居然麻溜地打开了相机还把照片存下来了,想请问大神这是什么黑科技
File file = new File(Environment.getExternalStorageDirectory(), "aaa.jpg");
这个代码 访问 文件 是需要 配置的
1:
res目录下 添加一个xml 文件夹 在增加一个文件 test.xml 名字无所谓
2:复制下面代码
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path path="Android/data/你的包名/" name="files_root" />
<external-path path="." name="external_storage_root" />
<external-path path="psyphoto/" name="images"/>
</paths>3:AndroidManifest增加
<provider
android:authorities="com.example.jin.fileprovidertest.fileprovider"
android:name="android.support.v4.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/test"/>
</provider>
在试试你的代码