ローカルストレージのアクセス権が欲しい場合は次の通り
var permissions = cordova.plugins.permissions;
// permissions.requestPermission(permissions.CAMERA, successPermission, errorPermission);
// permissions.requestPermission(permissions.READ_EXTERNAL_STORAGE, successPermission, errorPermission);
permissions.requestPermission(permissions.WRITE_EXTERNAL_STORAGE, successPermission, errorPermission);
function errorPermission(err) {
console.warn('permission is not turned on');
}
function successPermission(status) {
if (!status.hasPermission) errorPermission();
}
AndroidManifest.xml
画像や動画のストレージにアクセスする場合、Android 10以降にあわす場合「android:requestLegacyExternalStorage=”true”」を設定する必要がある。
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="xxxx.domain.apps" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:requestLegacyExternalStorage="true" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="org.apache.cordova.camera.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/camera_provider_paths" />
</provider>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>