Adding full resolution for image file in android.

I use the following code to add full resolution for image files in android. This code does not work every time. Imagine there are three image files: A.png, B.png and C.png. In some circumstances, the entire file will receive full resolution. In some state, A.png will receive, and in some conditions will receive, or B will receive full permission. I could not find the reason. Please help me 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(); } 
0
android file
source share
1 answer

If you haven’t read it, write permissions from the context that you are using, you will not be able to do chmod from the same context. Go to superuser (su. To do this, you need to root the device), and then you can change the mode. Here is the code. It works. I tested it. Thanks

 void gainRoot() { Process chperm; try { chperm=Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(chperm.getOutputStream()); os.writeBytes("chmod 777 /data/data/com.android.settings/MyApp/A.png\n"); os.flush(); os.writeBytes("chmod 777 /data/data/com.android.settings/MyApp/B.png\n"); os.flush(); os.writeBytes("chmod 777 /data/data/com.android.settings/MyApp/C.png\n"); os.flush(); os.writeBytes("exit\n"); os.flush(); chperm.waitFor(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 

Use the code exactly and check if your device is rooted. This will work. Call the gainRoot () function from oncreate (). Let me know if you have any difficulties. Thanks

+6
source share

All Articles