I am trying to read image paths from the storage and i keep getting the SecurityException here:
Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=31409, uid=10053 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
I am compiling against api 23 and have the permissions clearly stated in my Manifest as a direct child of my Manifest. I understand as well that the new runtime permissions state you have to ask for permission during runtime when you want to access the storage. When i write this line that would begin the check for the permission i get a cannot resolve issue in the IDE:
ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
cannot resolve symbol Manifest.permission.READ_EXTERNAL_STORAGE. The only Manifest.permission that i can clearly state in my code is Manifest.permission.C2D_MESSAGE without getting a cannot resolve error. Is there something else i need to compile to have access to the other permissions in code?
Just to be clear this is the block of code that is giving me the SecurityException:
public List<String> getCameraImagesFull(Context context) {
Cursor cursor = null;
String[] star = {"*"};
ArrayList<String> result = new ArrayList<>();
cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, star, null, null, MediaStore.MediaColumns.DATE_ADDED + " DESC");
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
result.add(path);
} while (cursor.moveToNext());
}
cursor.close();
}
return result;
}
this is the line that throws the exception:
cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, star, null, null, MediaStore.MediaColumns.DATE_ADDED + " DESC");
And here are all the permissions stated in my manifest:
<permission
android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
i am just wondering how i go about requesting that permission so i can get the image paths. This all works when i compile against any Lollipop build, just with the new runtime permissions on Marshmallow im getting the SecurityExeption. Any and all help is appreciated, thanks in advance
cannot resolve symbol Manifest.permission.READ_EXTERNAL_STORAGE
You need to add an import statement for android.Manifest, the same way you do with any other Java class.
The only Manifest.permission that i can clearly state in my code is Manifest.permission.C2D_MESSAGE without getting a cannot resolve error
There is no such value (C2D_MESSAGE) in android.Manifest.permission. I don't even know where there is a Manifest class, with a permission inner class, with a field named C2D_MESSAGE.
Related
This code worked on previous versions of android, but no longer seems to work on N.
I want to delete a media file, given the content URI of the file. I query the content provider for the path of the file. On android N, this seems to return a filename of the following form:
/storage/1143-1403/DCIM/Camera/20171019_185604.mp4
On previous versions of Android, the path would been a direct path to the SD Card. (And the real file can actually be found in the /sdcard/DCIM/Camera directory).
The problem: when I call new File(path).delete(), the delete fails. It succeeds in previous versions of Android.
Manifest permissions are:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
I have requested the following permissions, and they have been granted:
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
...
Manifest.permission.MODIFY_AUDIO_SETTINGS,
There is no Manifest.permission flag for WRITE_INTERNAL_STORAGE.
I'm guessing "/storage/1143-1403/DCIM/Camera" is some kind of fused file system.
Calling file = file.getAbsoluteFile().getCanonicalFile(); does not change the path or otherwise improve the situtation.
i work on a app (> 4.4) and my boss would like to save the configuration of the APN into the SQLite (our database).
As this, if the APN is lost for a reason we can retrieve easily these information and configure it ..
well, i've try some code but actually NOTHING work ...
I have this error message
Java.Lang.SecurityException: No permission to write APN settings: Neither user 10081 nor current process has android.permission.WRITE_APN_SETTINGS.
Of course, i have added to the manifest the correct RIGTH as this
<uses-permission android:name="android.permission.READ_APN_SETTINGS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_APN_SETTINGS"></uses-permission>
<uses-feature android:name="android.hardware.telephony" android:required="false" />
And here is it my code, it's with xamarin android but if you have some code with android , no matter i can find the translatation ..
Android.Net.Uri APN_TABLE_URI = Android.Net.Uri.Parse("content://telephony/carriers");
//path to preffered APNs
Android.Net.Uri PREFERRED_APN_URI = Android.Net.Uri.Parse("content://telephony/carriers/preferapn");
//
Android.Database.ICursor cursor = ctx.ContentResolver.Query(PREFERRED_APN_URI, null, null, null, null);
Thanks guys for all your time you spend here for to share your knowledge
try to add these two permissions:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I'm trying to load a Database file from my SD card,but is giving exception.
Below is the exception
org.sqlite.database.sqlite.SQLiteException: not an error (code 0): Could not open the database in read/write mode.
And here is my code:
public void csr_test_1() throws Exception
{
DB_PATH=new File("/storage/sdcard1/sk2.db");
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_PATH, null);
String res = "";
Cursor c = db.rawQuery("SELECT synsetid, w2.lemma FROM sense LEFT JOIN word AS w2 ON w2.wordid=sense.wordid WHERE sense.synsetid IN (SELECT sense.synsetid FROM word AS w1 LEFT JOIN sense ON w1.wordid=sense.wordid WHERE w1.lemma='"+ "life" + "') AND w2.lemma<>'" + "life" + "'", null);
if( c!=null ){
boolean bRes;
for(bRes=c.moveToFirst(); bRes; bRes=c.moveToNext()){
String x = c.getString(0);
res = res + "." + x;
}
}else{
}
test_result("csr_test_1.1", res, ".one.two.three");
db.close();
test_result("csr_test_1.2", db_is_encrypted(), "unencrypted");
}
These are the permission i'm using
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.vending.BILLING" />
![enter image description here][1]
![enter image description here][2]
Please help me out... Thanks
This exception is thrown if sqlite3_db_readonly() returns non-zero. It can return non-zero if
the database file is read-only, or
the database file does not exist.
(Reference)
You have a hardcoded path "/storage/sdcard1/sk2.db" - it's likely a database does not exist there. Use variables from Environment to access your external storage instead of hardcoded paths.
add this permission to your AndroidManifest.xml.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
please use both permission in manifest file
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
In case you still get this error even after you included:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
and you also implemented Runtime permissions then it almost certainly is a problem related to the way Android manages files from External SD Card. For more info check my answer here:
https://stackoverflow.com/a/46383795/1502079
if your sdk>N ,it must request write and read permission like this
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE},
1);
I realize even I do not have
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
in my `AndroidManifest.xml
String path = Images.Media.insertImage(((Activity)MainView.this.getContext()).getContentResolver(), screenCaptureBitmap, "Title", "Description");
still able to write image file to location /mnt/sdcard/DCIM/Camera. May I know why is it so?
maybe in depend on the content provider MediaStore, you through it to insert, it's a RPC invoke. and the MediaStore provider in source code: packages/providers/MediaProvider, in it's manifest define the permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />,
may be it's the reason.
ALL,
Here is my code:
Cursor cur = getContentResolver().query(ContactsContract.Groups.Content_URI, null, null, null, null );
Apparently this code throws security exception on my HTC phone.
Does anybody knows how to get group names on Android?
Thank you.
Have you added permissions in manifest file ? If not then add belew line of code in your manifest file.
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>