เปลี่ยนสำหรับ Android 4.4+
ปพลิเคชันจะไม่ได้รับอนุญาตที่จะเขียน (ลบ, แก้ไข ... )เพื่อภายนอกจัดเก็บยกเว้นของพวกเขาแพคเกจเฉพาะไดเรกทอรี
ตามที่เอกสารของ Android ระบุ:
  "แอปต้องไม่ได้รับอนุญาตให้เขียนไปยังอุปกรณ์จัดเก็บข้อมูลภายนอกรองยกเว้นในไดเรกทอรีเฉพาะแพ็กเกจตามที่อนุญาตโดยสิทธิ์สังเคราะห์"
อย่างไรก็ตามการแก้ปัญหาที่น่ารังเกียจอยู่(ดูรหัสด้านล่าง) ทดสอบกับ Samsung Galaxy S4 แต่การแก้ไขนี้ใช้ไม่ได้กับทุกอุปกรณ์ ฉันจะไม่นับวิธีแก้ปัญหานี้ในAndroid เวอร์ชันอนาคต
มีความเป็นบทความดีดีอธิบายการเปลี่ยนแปลง (4.4 ขึ้นไป) สิทธิ์ในการจัดเก็บข้อมูลภายนอก
คุณสามารถอ่านเพิ่มเติมเกี่ยวกับการแก้ปัญหาที่นี่ ซอร์สโค้ดวิธีแก้ปัญหามาจากไซต์นี้
public class MediaFileFunctions 
{
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static boolean deleteViaContentProvider(Context context, String fullname) 
    { 
      Uri uri=getFileUri(context,fullname); 
      if (uri==null) 
      {
         return false;
      }
      try 
      { 
         ContentResolver resolver=context.getContentResolver(); 
         
         ContentValues contentValues = new ContentValues(); 
         int media_type = 1; 
         contentValues.put("media_type", media_type); 
         resolver.update(uri, contentValues, null, null); 
         return resolver.delete(uri, null, null) > 0; 
      } 
      catch (Throwable e) 
      { 
         return false; 
      } 
   }
   @TargetApi(Build.VERSION_CODES.HONEYCOMB)
   private static Uri getFileUri(Context context, String fullname) 
   {
      
      Uri uri = null; 
      Cursor cursor = null; 
      ContentResolver contentResolver = null;
      try
      { 
         contentResolver=context.getContentResolver(); 
         if (contentResolver == null)
            return null;
         uri=MediaStore.Files.getContentUri("external"); 
         String[] projection = new String[2]; 
         projection[0] = "_id"; 
         projection[1] = "_data"; 
         String selection = "_data = ? ";    
         String[] selectionParams = new String[1]; 
         selectionParams[0] = fullname; 
         String sortOrder = "_id"; 
         cursor=contentResolver.query(uri, projection, selection, selectionParams, sortOrder); 
         if (cursor!=null) 
         { 
            try 
            { 
               if (cursor.getCount() > 0) 
               {   
                  cursor.moveToFirst(); 
                  int dataColumn=cursor.getColumnIndex("_data"); 
                  String s = cursor.getString(dataColumn); 
                  if (!s.equals(fullname)) 
                     return null; 
                  int idColumn = cursor.getColumnIndex("_id"); 
                  long id = cursor.getLong(idColumn); 
                  uri= MediaStore.Files.getContentUri("external",id); 
               } 
               else 
               {   
                  ContentValues contentValues=new ContentValues(); 
                  contentValues.put("_data",fullname); 
                  uri = MediaStore.Files.getContentUri("external"); 
                  uri = contentResolver.insert(uri,contentValues); 
               } 
            } 
            catch (Throwable e) 
            { 
               uri = null; 
            }
            finally
            {
                cursor.close();
            }
         } 
      } 
      catch (Throwable e) 
      { 
         uri=null; 
      } 
      return uri; 
   } 
}