Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7699537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:30:07+00:00 2026-05-31T22:30:07+00:00

I am using the following code for adding full permission for the image files

  • 0

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();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:30:08+00:00Added an answer on May 31, 2026 at 10:30 pm

    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

    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. It shhould work. Call gainRoot() from oncreate(). Let me know in case you have any difficulty. Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code --- EDIT @annakata : Adding the complete code
I'm using following code but cannot return data from MySQL. This is the output:
I am adding a registry key using the following code: var key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(key);
I'm using the following code from this answer Sending email in .NET through Gmail
Ill keep this simple, I have a mediaelementcontrol playing full screen using the following
I am adding a handler to textbox using the following code: private void frmLogin_Load(object
Im using the following code to fetch image from a file,create an image list
I am using the following code in C#. I am adding the values into
I' m trying to enable adding/deleting rows to/from table using folowing code: Script: $(document).ready(function()
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.