如何为我的应用程序提供SD的写入权限。我有Android 5.1.1,我的设备是Sony XPeria。
出现错误是下一个: https://paste.originersmc.com/10/
答案 0 :(得分:0)
请查看此Google指南:Demo page
基本上,您需要的只是清单中的此权限:
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
答案 1 :(得分:0)
您也可以在运行时请求权限,因此定义权限也是必要的。
您可以通过以下方式申请Runtime Permisison。
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
答案 2 :(得分:0)
For 5.1.1 you need to just Add permission to manifest xml
<manifest>
//For Write to External storage
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
//For Read from External storage
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
...
<application>
...
<activity>
...
</activity>
</application>
</manifest>
But later than 6.0 you need to add permission runtime too.