0

即使我已经完成了所有必要的操作,我仍然遇到这个 mkdir 问题,以下是我的活动代码。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    File folder = new File(Environment.getExternalStorageDirectory().toString() + "/myappfolder" );

    boolean maked = folder.mkdir();
    System.out.println("the folder is maked or not? "+maked);

    setContentView(R.layout.activity_main);


    }

folder.mkdir() 返回错误。

是的,我有:

  • 包括

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    

    在我的清单中。

  • 我还确保我的 SD 卡中不存在该文件夹。

  • 在我的一个项目中它显示

06-22 01:23:58.130: W/ActivityManager(143): 没有找到用于权限撤销的内容提供者: file:///data/local/tmp/simulation.apk

  • 我什至尝试将它从我的电脑上拔下,以防 SD 卡安装到我的桌面上。
  • 我也试过 sumsung Galaxy s3

我主要使用acer A100 ICS 出厂数据重置平板电脑。我怀疑有什么东西阻止了我的平板电脑允许我在 SD 卡上写字

如果有人能提出解决方案,我将不胜感激

以下是我的logcat

06-22 04:33:55.850: D/AndroidRuntime(18556): >>>>>> AndroidRuntime START        com.android.internal.os.RuntimeInit <<<<<<
06-22 04:33:55.850: D/AndroidRuntime(18556): CheckJNI is OFF
06-22 04:33:56.030: D/AndroidRuntime(18556): Calling main entry com.android.commands.pm.Pm
06-22 04:33:56.030: D/AndroidRuntime(18556): Shutting down VM
06-22 04:33:56.040: D/dalvikvm(18556): GC_CONCURRENT freed 100K, 83% free 454K/2560K, paused 0ms+0ms
06-22 04:33:56.040: D/dalvikvm(18556): Debugger has detached; object registry had 1 entries
06-22 04:33:56.590: D/AndroidRuntime(18570): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
06-22 04:33:56.590: D/AndroidRuntime(18570): CheckJNI is OFF
06-22 04:33:56.760: D/AndroidRuntime(18570): Calling main entry com.android.commands.pm.Pm
06-22 04:33:56.770: W/ActivityManager(143): No content provider found for permission revoke: file:///data/local/tmp/myapp.apk
06-22 04:33:56.780: W/ActivityManager(143): No content provider found for permission revoke: file:///data/local/tmp/myapp.apk
06-22 04:33:56.850: I/PackageManager(143): Running dexopt on: com.android.myapp
06-22 04:33:57.150: D/dalvikvm(18581): DexOpt: load 41ms, verify+opt 183ms
06-22 04:33:57.230: I/ActivityManager(143): Force stopping package com.android.myapp uid=10071
06-22 04:33:57.320: D/PackageManager(143): New package installed in /data/app/com.android.myapp-1.apk
06-22 04:33:57.320: W/PackageManager(143): Unknown permission android.permission.READ_EXTERNAL_STORAGE in package com.android.myapp
06-22 04:33:57.440: D/PackageManager(143): generateServicesMap(android.accounts.AccountAuthenticator): 3 services unchanged
06-22 04:33:57.450: I/Launcher(1776): setLoadOnResume
06-22 04:33:57.470: D/dalvikvm(18159): GC_FOR_ALLOC freed 227K, 8% free 6680K/7239K, paused 17ms
06-22 04:33:57.490: D/SyncManager(143): setIsSyncable: Account {name=chinchyekoo@gmail.com, type=com.google}, provider com.google.android.gallery3d.GooglePhotoProvider -> 0
06-22 04:33:57.490: D/SyncManager(143): setIsSyncable: already set to 0, doing nothing
06-22 04:33:57.520: D/PackageManager(143): generateServicesMap(android.content.SyncAdapter): 18 services unchanged
06-22 04:33:57.570: D/BackupManagerService(143): Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.android.myapp flg=0x10000010 (has extras) }
06-22 04:33:57.570: V/BackupManagerService(143): addPackageParticipantsLocked: com.android.myapp
06-22 04:33:57.660: D/dalvikvm(143): GC_EXPLICIT freed 1056K, 24% free 11640K/15239K, paused 6ms+7ms
06-22 04:33:57.670: D/AndroidRuntime(18570): Shutting down VM
06-22 04:33:57.680: D/dalvikvm(18570): GC_CONCURRENT freed 101K, 83% free 459K/2560K, paused 0ms+0ms
06-22 04:33:57.680: D/jdwp(18570): Got wake-up signal, bailing out of select
06-22 04:33:57.680: D/dalvikvm(18570): Debugger has detached; object registry had 1 entries
06-22 04:33:57.680: I/AndroidRuntime(18570): NOTE: attach of thread 'Binder Thread #3' failed
06-22 04:33:57.830: D/dalvikvm(1776): GC_CONCURRENT freed 2458K, 47% free 10173K/19079K, paused 2ms+6ms
06-22 04:33:57.840: D/dalvikvm(17407): GC_CONCURRENT freed 276K, 6% free 7177K/7559K, paused 16ms+3ms
06-22 04:33:57.930: D/dalvikvm(1776): GC_FOR_ALLOC freed 994K, 47% free 10233K/19079K, paused 32ms
06-22 04:33:58.020: D/dalvikvm(1776): GC_FOR_ALLOC freed 769K, 45% free 10581K/19079K, paused 21ms
06-22 04:33:58.080: D/AndroidRuntime(18593): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
06-22 04:33:58.080: D/AndroidRuntime(18593): CheckJNI is OFF
06-22 04:33:58.090: D/dalvikvm(1776): GC_CONCURRENT freed 5K, 38% free 11836K/19079K, paused 2ms+3ms
06-22 04:33:58.180: D/dalvikvm(1776): GC_CONCURRENT freed 1398K, 37% free 12143K/19079K, paused 1ms+4ms
06-22 04:33:58.290: D/dalvikvm(1776): GC_FOR_ALLOC freed 2316K, 42% free 11191K/19079K, paused 25ms
06-22 04:33:58.370: D/AndroidRuntime(18593): Calling main entry com.android.commands.am.Am
06-22 04:33:58.370: I/ActivityManager(143): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.android.myapp/.MainActivity} from pid 18593
06-22 04:33:58.420: D/AndroidRuntime(18593): Shutting down VM
06-22 04:33:58.420: I/AndroidRuntime(18593): NOTE: attach of thread 'Binder Thread #3' failed
06-22 04:33:58.420: D/dalvikvm(18593): GC_CONCURRENT freed 102K, 81% free 489K/2560K, paused 0ms+1ms
06-22 04:33:58.430: D/jdwp(18593): Got wake-up signal, bailing out of select
06-22 04:33:58.430: D/dalvikvm(18593): Debugger has detached; object registry had 1 entries
06-22 04:33:58.470: D/dalvikvm(18604): Late-enabling CheckJNI
06-22 04:33:58.490: I/ActivityManager(143): Start proc com.android.myapp for activity com.android.myapp/.MainActivity: pid=18604 uid=10071 gids={1015}
06-22 04:33:58.570: D/OpenGLRenderer(18507): Flushing caches (mode 1)
06-22 04:33:58.580: D/OpenGLRenderer(18507): Flushing caches (mode 0)
06-22 04:33:58.660: I/System.out(18604): folder newed going to make folder
06-22 04:33:58.660: I/System.out(18604): here/mnt/sdcard/myappfolder
06-22 04:33:58.660: I/System.out(18604): the folder is maked or not? false
06-22 04:33:58.680: D/dalvikvm(1776): GC_CONCURRENT freed 2487K, 47% free 10154K/19079K, paused 2ms+47ms
06-22 04:33:58.710: D/dalvikvm(18239): GC_CONCURRENT freed 339K, 6% free 6935K/7367K, paused 3ms+4ms
06-22 04:33:58.760: D/libEGL(18604): loaded /system/lib/egl/libEGL_tegra.so
06-22 04:33:58.780: D/libEGL(18604): loaded /system/lib/egl/libGLESv1_CM_tegra.so
6-22 04:33:58.810: D/dalvikvm(1776): GC_FOR_ALLOC freed 675K, 46% free 10318K/19079K, paused 35ms
06-22 04:33:58.830: D/libEGL(18604): loaded /system/lib/egl/libGLESv2_tegra.so
06-22 04:33:58.870: D/OpenGLRenderer(1776): Flushing caches (mode 1)
06-22 04:33:58.870: D/OpenGLRenderer(18604): Enabling debug mode 0
06-22 04:33:58.910: D/dalvikvm(1776): GC_FOR_ALLOC freed 642K, 46% free 10474K/19079K, paused 46ms
06-22 04:33:58.940: D/OpenGLRenderer(1776): Flushing caches (mode 0)
06-22 04:33:58.970: I/ActivityManager(143): Displayed com.android.myapp/.MainActivity: +516ms
06-22 04:33:59.000: D/dalvikvm(1776): GC_FOR_ALLOC freed 941K, 47% free 10204K/19079K, paused 41ms
06-22 04:33:59.010: I/dalvikvm-heap(1776): Grow heap (frag case) to 11.236MB for 1286224-byte allocation
06-22 04:33:59.050: D/dalvikvm(1776): GC_CONCURRENT freed 31K, 41% free 11429K/19079K, paused 2ms+4ms
06-22 04:34:00.210: E/DigitalAppWidgetUpdateService(17962): onReceive():948: screen mode = ORIENTATION_PORTRAIT
06-22 04:34:00.250: D/dalvikvm(17962): GC_CONCURRENT freed 321K, 8% free 6809K/7367K, paused 1ms+2ms
4

1 回答 1

0

两件事情。

  • 您的代码读取

    File folder = new File(Environment.getExternalStorageDirectory().toString() + "/myappfolder" );

你最好使用这种语法

File folder = new File(Environment.getExternalStorageDirectory().toString() , "myappfolder" );

  • 如果您正在调试代码,则外部 SD 卡可能已被卸载。转到设置-> 存储并验证您的 SD 卡是否可以被您设备上的应用程序访问。

看到你的 logcat 后,一件事似乎给你带来了麻烦。您的 logcat 中有这一行:

06-22 04:33:57.320: W/PackageManager(143): Unknown permission  
 android.permission.READ_EXTERNAL_STORAGE in package com.android.myapp

这意味着您实际上在清单方面遇到了问题(您的目标是尚未实现该权限的 Android 版本。我还怀疑如果您删除该权限,您的麻烦就会停止)。根据权限的描述,您无论如何都不需要它,因为您已经授予WRITE_EXTERNAL_STORAGE.

于 2013-06-21T17:54:15.680 回答