Android 7.0 读写权限

AndroidManifest.xml 注册
    package="com.example.cheng.notepad">
   
   
            android:allowBackup="true"

App中需要动态获取(新建一个类)

public class AppPermission {

    public static boolean isGrantExternalRW(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && activity.checkSelfPermission(
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

            activity.requestPermissions(new String[]{
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE
            }, 1);

            return false;
        }

        return true;
    }
}

 

 

你可能感兴趣的:(Android)