im building a media downloading application and im facing the problem where im able to download media in virtual device but not in real device ,ive tried troubleshooting it nothing worked!
i checked the permission manager in my device permission manager its showing no requested permision from the app although i have requested storage permission
but in my virtual device its showing that i have requested the permission
here is my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
android:minSdkVersion="30" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application
android:label="downloader"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
here im requesting for permission
checkPermission() async {
var status = await Permission.storage.status;
if (!status.isGranted) {
status = await Permission.storage.request();
}
if (status.isGranted) {
print('permission already granted');
// You can start the download or access storage
} else {
checkPermission();
}
}
my compilesdkversion is 33
downloading logic
download(name, link) async {
checkPermission();
NotificationService().showNotification(id: 0, title: 'Download Started');
var response = await http.get(Uri.parse(link));
final file = File('/storage/emulated/0/Download/$name.m4a');
await file.writeAsBytes(response.bodyBytes);
NotificationService().showNotification(
id: 1, title: 'Downloaded', body: '$name downloaded successfully');
MediaScanner.loadMedia(path: '/storage/emulated/0/Download/$name.m4a');
print('downloaded');
}