[Android Studio篇][1] AS开发中遇到问题汇总
1 在android新建文件,提示权限不够,增加权限 修改工程下 main/AndroidMainfest.xml增加
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>(这个是写文件的权限,默认是有读权限的)
<uses-permission
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>(这个是创建文件/文件夹的权限)
但是要注意这两行的位置:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="byd.eagle"
android:versionCode="1"
android:versionName="1.0">
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<application android:icon="@drawable/icon"
android:label="@string/app_name">
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
添加了读写权限后,发现还是报: java.io.FileNotFoundException: /sdcard/12.png (Permission denied)
另外我在网上
后来是:还要给应用添加权限:设置--应用---(test)---权限--存储空间(打开)
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
};
public static void verifyStoragePermissions(Activity activity)
{
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE);
}
}
但是传参数的时候(不对,MainActivity.this)--不知道怎么改了
http://blog.csdn.net/escic/article/details/52774762
http://www.aichengxu.com/xitong/2508579.htm
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
};
public static void verifyStoragePermissions(Activity activity)
{
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE);
}
}