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.
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 have some problems in my App.
I just wanna read file in sdcard, so I put the file in /storage/sdcard/abcd (the folder I made by adb) in emulator.
File name is "1.14P", and I verify it is in that path. Its permission is 770.
But my problem is, I can't access sdcard by Application.
sampleFile = new File (Environment.getExternalStorageDirectory(), "abcd/1.14P");
sampleFile.exists() //return false
sampleFile2 = new File (Environment.getExternalStorageDirectory(), "tttt");
sampleFile2.mkdir() //return false
Sdcard is mounted well, I thought.
String state = Environment.getExternalStorageState(); //return "mounted"
I give the permission but I can't access to sdcard. Here is my manifest.xml. (part)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hu.test004" >
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
...(Activities)
I can't understand why it happens. Please give me some favor. Thanks.
SOLVED::I've got it!
The problem is, I declared permissions in capital letter, so App doesn't grant permissions.
I change
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>
to
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
and permission granted.
Thank you for your favor all.
I think the "," is part of the problem. The other is the "exists()" is for directories, not files.
See here:
new File(path) always actually creates a file on android?
contrary to the docs:
http://developer.android.com/reference/java/io/File.html
you may want to use isFile() instead.
Could you try adding "/" in front of your names??
e.g. "/abcd/1.14P"
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 am not able to display html page kept in sdcard on webview. I have tried using this two methods:
webPage.loadUrl("file://"+ Environment.getExternalStorageDirectory()+"/page1.html");
and
webPage.loadUrl("content://com.android.htmlfileprovider"+
Environment.getExternalStorageDirectory()+"/page1.html");
Please Guide.
Try This.
webPage.loadUrl("file://"+Environment.getExternalStorageDirectory()+"/page1.html");
You forgot to add slash.
Add Internet Permission and Read External Permission.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>