chmod失败:android中的EPERM(不允许操作)?
作者:互联网
我想在sdcard或外部SD卡中创建数据库为此我已经尝试了这个代码并使用这个我已经在SD卡中成功创建了数据库,但在logcat中它给了我如下警告
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);
}
}
}
解决方法:
刚刚解决了这个问题.
你必须让你的应用程序加入linux build以授予它SYSTEM权限.
>将此行添加到Android.mk中
LOCAL_CERTIFICATE:=平台
>将其添加到AndroidManifest.xml的清单节点中
机器人:sharedUserId = “android.uid.system”
>生成apk并将其推入/ system / app /
>现在你可以试着跑了
final String command = "chmod 777 /data/ena";
Process p = Runtime.getRuntime().exec(command);
要么
File file = new File("/data/ena");
if (file.exists()) {
boolean result = file.setExecutable(true);
Log.e(TAG, "trpb67, RESULT IS " + result);
}
结果的值应该是真的
标签:android,android-sqlite 来源: https://codeday.me/bug/20191006/1858050.html