Android 4.2.2无法创建目录

时间:2017-06-24 10:41:35

标签: java android

创建目录错误版本4.2.2 Google Api 下载音乐和错误

  

6.0工作   极少数用户可以返回此错误。该目录不存在或无法读取。

FATAL EXCEPTION: main                                                                           java.lang.IllegalStateException: Unable to create directory: /mnt/sdcard/muzikcaddesi
                                                                                 at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:503)
                                   at com.mp3player.searchonline.SongFragment$3$1.onClick(SongFragment.java:158)
                                                                                 at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:941)
                                                                                 at android.widget.AdapterView.performItemClick(AdapterView.java:298)
                                                                                 at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
                                                                                 at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
                                                                                 at android.widget.AbsListView$1.run(AbsListView.java:3423)
                                                                                 at android.os.Handler.handleCallback(Handler.java:725)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                 at android.os.Looper.loop(Looper.java:137)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                                                 at dalvik.system.NativeStart.main(Native Method)
06-24 10:35:54.133 4183-4196/com.muzikcaddesi.muzikcaddesi E/GAv4: Successfully bound to service but never got onServiceConnected callback

我的权限控制

 if (ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

            ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_INTERNET);
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.READ_PHONE_STATE}, 1);
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_INTERNET);
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.ACCESS_NETWORK_STATE}, 3);
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.INTERNET}, 4);
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.WRITE_SETTINGS}, 5);
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.WAKE_LOCK}, 6);
        }else{

我的清单

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="25" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

1 个答案:

答案 0 :(得分:0)

1.请检查/mnt/sdard是否存在且可以写入;

2.请检查/mnt/sdcard/muzikcaddesi是否已作为文件存在;

3.请检查您设备的SD卡路径是否为/mnt/sdcard。您是否使用Environment.getExternalStorageDirectory().getPath())获取SD卡路径?

4.或者你可以使用另一种方法setDestinationInExternalFilesDir