chmod failed: EPERM (Operation not permitted) in android?

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

i want to create database in sdcard or external sdcard for this i have try this code and using this i have successfully created database in sdcard but in logcat it give me warning like below

Logcat

07-18 14:18:22.140: W/FileUtils(8595): Failed to chmod(/mnt/sdcard/peakmedia/DB_PMD): libcore.io.ErrnoException: chmod failed: EPERM (Operation not permitted)

DB_Helper.java

public class DB_Helper extends SQLiteOpenHelper {      public DB_Helper(Context context)      {            super(context, Environment.getExternalStorageDirectory().getAbsolutePath()                         + File.separator + DB_Constant.DB.FILE_DIR                         + File.separator + DB_Constant.DB.DATABASENAME, null, DB_Constant.DB.DB_VERSION);      }      @Override     public void onCreate(SQLiteDatabase db)      {         String  query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYFILES_TABLE);         db.execSQL(query);           query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYUSERS_TABLE);         db.execSQL(query);          query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYPLAYLIST_TABLE);         db.execSQL(query);          query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYDEVICE_TABLE);         db.execSQL(query);      }       @Override      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)       {             if(newVersion > oldVersion)             {                     db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYFILES);                 onCreate(db);                  db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYUSERS);                 onCreate(db);                  db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYPLAYLIST);                 onCreate(db);                  db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYDEVICE);                 onCreate(db);              }      } } 

回答1:

Just solved this problem.

You have to let your app join linux build to grant it SYSTEM permission.

  1. add this line into Android.mk

    LOCAL_CERTIFICATE := platform

  2. add this into manifest node of AndroidManifest.xml

    android:sharedUserId="android.uid.system"

  3. Generate apk and push it into /system/app/

  4. Now you can try to run

    final String command = "chmod 777 /data/ena"; Process p = Runtime.getRuntime().exec(command); 

    or

    File file = new File("/data/ena"); if (file.exists()) {     boolean result = file.setExecutable(true);     Log.e(TAG, "trpb67, RESULT IS " + result); } 

    value of result should be true



回答2:

Yesterday I met same problem like Mahesh(appear same warn message, insert data from SQL server to SQLite, 2 tables should receive data in SQLite, but only 1 table received data, another table is empty).

But Today I try to insert data from SQL server into 2 tables of SQLite in SD Card again, this time, 2 table received data.

The only difference is EMULATOR setting.

Enlarge SD card space setting, from few MB to 8GB, reference picture. emulator setting photo

Although warning also appear, but inserting work success.



回答3:

Check whether your device is connected in MTP usb mode. Sometimes a previous connection of MTP mode can cause this problem. Just restart device and check if it works.



回答4:

You have to change the owner (chown) of this folder. Currently the app/you is not the owner of that folder in where you want to install the db.

So you have to do something like

sudo chown -R theuser /mnt/sdcard/peakmedia/DB_PMD 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!