I am using the following code for adding full permission for the image files in android. This code is not working in every time. Imagine there are three image file, A.png,B.png and C.png. In some condition all the file will get the full permission. In some condition A.png will get and in some conditions get or A and B will get the full permission. I was not able find the reason. Please help me to find the reason.
String iconFile = themePrefs.getString(info.activityInfo.name, ""); // Icon file = "/data/data/com.android.settings/MyApp/A.png";
System.out.println("FileExecute " + ico.canExecute()); //always false
System.out.println("FileRead " + ico.canRead()); //always false
System.out.println("FileWrite " + ico.canWrite()); //always false
System.out.println("FileExists " + ico.exists()); //always true
System.out.println("FileisFile " + ico.isFile()); //always true
System.out.println("FileisDirectory " + ico.isDirectory());//always false
Drawable d = null;
FileInputStream fis; // in stream
try {
File ico = new File(iconFile); //creating a file with the path (because only this is working with absolute path)
try {
Runtime.getRuntime().exec("chmod 777 " + iconFile);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("FileExecute " + ico.canExecute()); // Sometimes getting true, Sometimes false
System.out.println("FileRead " + ico.canRead()); // Sometimes getting true, Sometimes false
System.out.println("FileWrite " + ico.canWrite()); // Sometimes getting true, Sometimes false
System.out.println("FileExists " + ico.exists()); // always true
System.out.println("FileisFile " + ico.isFile()); // always true
System.out.println("FileisDirectory " + ico.isDirectory()); // always false
}
catch (OutOfMemoryError e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch(NullPointerException ne) {
ne.printStackTrace();
}
If you don't have read, write permissions from the context you are running, you will not be able to do chmod from the same context. Change to super user(su. For this the device must be rooted) and then you can change the mode. Here is the code. It works. I tested it. Thanks
Use the code exactly and check if your device is rooted. It shhould work. Call gainRoot() from oncreate(). Let me know in case you have any difficulty. Thanks