0

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 enter image description here

but in my virtual device its showing that i have requested the permission enter image description here

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');
  }
  • What is Android version of used devices? – blackapps Aug 27 '23 at 18:14
  • virtual device where its working fine is android 11 , and the physical device where its not working is android 13 – Raj Tripathi Aug 27 '23 at 19:05
  • Those storage permissions are not needed for Android 13. You have write permission by default. – blackapps Aug 27 '23 at 19:30
  • i have thought about it but then why download isnt working on android 13 and its working android 11 – Raj Tripathi Aug 28 '23 at 10:23
  • As you did not post any downloading or file creating code and or logcat errors nobody can help you. – blackapps Aug 28 '23 at 10:28
  • i have just added it below please check – Raj Tripathi Aug 28 '23 at 11:04
  • Well... which errors do you get? What goes wrong exactly? You let us guess. – blackapps Aug 28 '23 at 11:12
  • i dont get any error it just doesnt downloads i have tried using try method to find error but im getting nothing , as far a i know its something related to storage permission – Raj Tripathi Aug 28 '23 at 11:22
  • If you think that it is a storage permission problem then do not download to a location for which you -usually- need a permission. Download to an app specific directory instead like (in Java) getFilesDir() or getExternalFilesDir(). You could aso just try to create only a file without downloading anything. – blackapps Aug 28 '23 at 11:24
  • i will do a dummy download using another app and lets see if its something related to my app or some version problem – Raj Tripathi Aug 28 '23 at 11:29
  • Did you log response to see what you got? – blackapps Aug 28 '23 at 11:29
  • i think i have found the reason check this https://stackoverflow.com/questions/74949341/how-can-i-save-files-on-android-13-api-33-by-using-flutter-dart – Raj Tripathi Aug 28 '23 at 11:37

0 Answers0