When i am try to share my directory image via share plug in ! Image is not going to share ! Asking me permission what is that ??? Can any one give me solution on it
FlatButton(
onPressed: () async {
Directory dir = await getApplicationDocumentsDirectory();
File testFile = new File("${dir.path}/image.png");
FlutterShareFile.shareImage(dir.path, "image.png", ShareFileType.image);
},
)
I am getting this type of warning :
E/DatabaseUtils( 8123): java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.photogranth.watermark.contentprovider/images/image.png from pid=6574, uid=1000 requires the provider be exported, or grantUriPermission()
E/DatabaseUtils( 8123): at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:742)
E/DatabaseUtils( 8123): at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:615)
E/DatabaseUtils( 8123): at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:606)
E/DatabaseUtils( 8123): at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:520)
E/DatabaseUtils( 8123): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:307)
E/DatabaseUtils( 8123): at android.os.Binder.execTransactInternal(Binder.java:1021)
E/DatabaseUtils( 8123): at android.os.Binder.execTransact(Binder.java:994)
Did you add this to your AndroidManifest.xml file?
<application>
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths"/>
</provider>
</application>
Related
I'm trying to delete song file but it is unable to delete and throws an exception of permission denied but permissions are already granted using permission_handler and required storage permissions are added in AndroidManifest.xml as well. I have also checked path is valid and file exist before delete which return true. Would anyone help me to solve this.
Error on file.delete() line.
Unhandled Exception: FileSystemException: Deletion failed, path = '/storage/0E15-2E06/Music/Call Sound Effect.mp3' (OS Error: Permission denied, errno = 13)
AndroidManifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<application
android:label="Example"
android:name="${applicationName}"
android:icon="#mipmap/ic_launcher"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true" >
Code snippet:
if (await Permission.storage.request().isGranted) {
// Either the permission was already granted before or the user just granted it.
// permission was granted
if (song != null) {
String? path = song.data;
File file = File(path);
bool isExist = await file.exists();
if (isExist) {
await file.delete(recursive: true);
}
}
}
You have to use the permission_handler(https://pub.dev/packages/permission_handler) package and have to mention some permissions in the Androidmanifest.xml file.
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Also, you have to ask Permission of storage before doing storage related operation(In your case deletion of audio file).
final _permissionStatus = await Permission.storage.request();
if(_permissionStatus = PermissionStatus.isGranted){
/// Delete audio file
}else{
/// Permission Denied.
}
I'm trying to share a image with plugin share flutter, but I'm getting the following error:
java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/.../cache/share/image-777.jpg
AndroidManifest.xml:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_path"/>
</provider>
flutter:
final urlImage =
'https://images.tokopedia.net/img/cache/500-square/hDjmkQ/2021/9/13/343063bb-f7c5-468d-9602-9b06ced70bdb.jpg';
final uri = Uri.parse(urlImage);
final response = await http.get(uri);
final bytes = response.bodyBytes;
final temp = await getTemporaryDirectory();
final path = '${temp.path}/image-777.jpg';
File(path).writeAsBytesSync(bytes);
await Share.shareFiles(
[path],
// text: wording + ' ' + url,
// subject: 'Refer your friend',
);
provider_path.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="/" />
<external-files-path
name="external_files"
path="/" />
<cache-path
name="cache"
path="/" />
<external-cache-path
name="external_cache"
path="/" />
<files-path
name="files"
path="/" />
</paths>
I was searching whole day about this error and trying to understand FileProvider, but I have no idea what this error message tries to tell me, i already change '.' to '/' in provider_path.xml or '/cache/share' but still not working . If you want more info/code, write me in the comment.
I've set permissions in the AndroidManifest.xml file
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
I've also added the following lines in the AndroidManifest.xml as specified in the docs
<service
android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false"/>
<receiver
android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmBroadcastReceiver"
android:exported="false"/>
<receiver
android:name="dev.fluttercommunity.plus.androidalarmmanager.RebootBroadcastReceiver"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
In my main.dart file, I've the following lines of codes...
import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await AndroidAlarmManager.initialize();
runApp(MyApp());
await AndroidAlarmManager.periodic(Duration(minutes: 1), 0, syncData);
}
void syncData() async {
print("synching data");
String? uploadedUrl = await S3.uploadToS3();
print(uploadedUrl);
}
What should I add for this to work automatically on reboot? TIA :)
From Android 8.0 You can't use most of the implicit broadcast ,
So your application service will not start on
ACTION_LOCKED_BOOT_COMPLETED or ACTION_BOOT_COMPLETED
for more details
you can use WorkManager instead to sync data to server
here is a good example
I'm trying to fetch some files from the local directory by using the dependency path_provider: ^1.6.27, but was getting an error stating as Unhandled Exception: MissingPluginException(No implementation found for method getExtStorageData on channel path_provider_ex)
The code where I'm fetching
getFiles() async {
directory = (Directory('storage/emulated/0/FolderName')).path;
setState(() {
file = io.Directory('$directory/${widget.folderName}').listSync();
});
List<StorageInfo> storageInfo = await PathProviderEx.getStorageInfo();
}
Getting the error in the line List<StorageInfo> storageInfo = await PathProviderEx.getStorageInfo();
Have mentioned the permissions in the manifest file
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:requestLegacyExternalStorage="true"/>
If you have just added the plugin this may help you.
MissingPluginException
Error: Error: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{c896ebc 5117:org.nativescript.Jztong/u0a11
1} (pid=5117, uid=10111) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
Add this lines in your app/App_Resources/Android/AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
If you are using android v6 you should requires permission at runtime, you can use nativescript-permissions plugin.
var perm = permissions.requestPermission(android.Manifest.permission.WRITE_CONTACTS, "I need write Contact permission!");
perm.then(() => {
//addContact();
}).catch(() => {
alert("Oops, No permissions to write contact!");
});