2014-06-14 71 views
1

我试图从sdcard中删除一个图像文件。以下代码可以正常使用模拟器,但是当我在Nexus手机上测试它时,每个已删除图像的文件夹中都存在一个黑框。所以,在以下有关类似问题的帖子,我的代码如下所示。 我刚刚开始学习android编程,并陷入了困境。我真的很感谢你的帮助。android如何在删除后删除sd卡文件夹中删除图像的黑框?

`

String sdcard_path=Environment.getExternalStorageDirectory().getAbsolutePath()+"/Expense_image"; 
    File cacheFile =new File (sdcard_path,imageLocation); 
    if(cacheFile.exists()){ 

               boolean deleted=cacheFile.delete(); 

               Log.i("Deletion check","deleted:"+deleted); 
               sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); 

}

Manifest.xml文件:

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

<activity 
       android:name=".deleteRecord" 
       android:label="@string/app_name" > 
      <intent-filter> 
      <action android:name="com.refat.myexpensev1.DELETERECORD" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.intent.action.MEDIA_MOUNTED" /> 
     <data android:scheme="file" /> 
    </intent-filter> 
    </activity> 

回答

0

作为API的LVL 19 Intent.ACTION_MEDIA_MOUNTED广播已被弃用,不再允许。

您还缺少权限。 将清单中的<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />添加到手机的外部目录中。

+0

我已经在清单文件中添加了该权限,它删除了模拟器中的文件,没有任何黑框,但没有在真实的设备中。请告诉我可能的解决方案。 – user3737716

+0

你的API是什么? – Boggartfly

+0