एंड्रॉइड 4.4 +
ऐप्स की अनुमति नहीं हैलिखने(हटाने के लिए, संशोधित ...)उनके पैकेज विशेष निर्देशिका के लिए छोड़कर भंडारण के लिए बाहरी करने के लिए।
के रूप में Android दस्तावेज़ कहता है:
"Apps माध्यमिक बाहरी संग्रहण में उपकरणों, लिखने के लिए अपने पैकेज-विशिष्ट निर्देशिका में छोड़कर के रूप में संश्लेषित अनुमतियों द्वारा अनुमति अनुमति नहीं दी जानी चाहिए।"
हालांकि बुरा वैकल्पिक हल मौजूद (नीचे दिए गए कोड को देखें)। सैमसंग गैलेक्सी एस 4 पर परीक्षण किया गया, लेकिन यह फिक्स सभी उपकरणों पर काम नहीं करता है।इसके अलावा मैं पर भरोसा नहीं करता हूं यह कार्यवाही भविष्य में संस्करणों में उपलब्ध है।
great article explaining (4.4+) external storage permissions change है।
आप more about workaround here पढ़ सकते हैं। वर्कअराउंड स्रोत कोड this site से है।
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();
// change type to image, otherwise nothing will be deleted
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)
{
// Note: check outside this class whether the OS version is >= 11
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 = ? "; // this avoids SQL injection
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) // file present!
{
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 // file isn't in the media database!
{
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;
}
}
स्रोत
2014-05-20 13:39:22
आप की जरूरत है समस्या के बारे में अधिक जानकारी प्रदान करें, जैसे कि आप किस भाषा का उपयोग कर रहे हैं, आप एसडी कार्ड का उपयोग कैसे कर रहे हैं, आदि – Amok
क्या आप डिस्क में बदलावों को फ़्लश कर रहे हैं? –
@Amuck मुझे लगता है कि यह मानना सुरक्षित है कि वह जावा का उपयोग कर रहा है क्योंकि उसने निर्दिष्ट नहीं किया था। –