无法使用mkdir创建文件夹到Android平板电脑的SD卡

时间:2013-06-21 17:30:49

标签: eclipse sd-card eclipse-adt

我有mkdir的问题,即使我已经完成所有必要的操作,仍然会返回false,以下是我的活动代码。

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()返回false。

是的,我有:

  • 包括

    <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

1 个答案:

答案 0 :(得分:0)

两件事。

  • 您的代码为

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

你最好使用this syntax

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

  • 如果您正在调试代码,则可能已卸下外部SD卡。转到设置 - &gt;存储并验证设备上的应用是否可以访问您的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版本。我还怀疑如果您删除该权限,您的问题将会停止)。根据{{​​3}},您无论如何都不需要它,因为您已经授予WRITE_EXTERNAL_STORAGE