文件模式失败:EPERM(不允许的操作)的机器人? [英] chmod failed: EPERM (Operation not permitted) in android?

查看:4609
本文介绍了文件模式失败:EPERM(不允许的操作)的机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建数据库中的SD卡或外置SD卡为了这个,我已经尝试此code和使用这个我已经成功地创建了数据库中的SD卡,但在它的logcat给我警告像下面

的logcat

  

07-18 14:18:22.140:W /文件实用程序(8595):无法   文件模式(到/ mnt / SD卡/ peakmedia / DB_PMD):libcore.io.ErrnoException的:chmod   失败:EPERM(操作不允许)

DB_Helper.java

 公共类DB_Helper扩展SQLiteOpenHelper
{

    公共DB_Helper(上下文的背景下)
    {
        超(背景下,Environment.getExternalStorageDirectory()。getAbsolutePath()
                       +文件分割符+ DB_Constant.DB.FILE_DIR
                       +文件分割符+ DB_Constant.DB.DATABASENAME,空,DB_Constant.DB.DB_VERSION);

    }

    @覆盖
    公共无效的onCreate(SQLiteDatabase DB)
    {
        查询字符串=的String.Format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYFILES_TABLE);
        db.execSQL(查询);


        查询=的String.Format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYUSERS_TABLE);
        db.execSQL(查询);

        查询=的String.Format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYPLAYLIST_TABLE);
        db.execSQL(查询);

        查询=的String.Format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYDEVICE_TABLE);
        db.execSQL(查询);

    }

     @覆盖
     公共无效onUpgrade(SQLiteDatabase分贝,INT oldVersion,诠释静态网页)
     {
            如果(动态网页> 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构建授予IT系统的权限。

  1. 添加此行到Android.mk

    LOCAL_CERTIFICATE:=平台

  2. 加入到这一的Andr​​oidManifest.xml

    舱单节点

    安卓sharedUserId =android.uid.system

  3. 生成APK并将其推入/系统/应用/

  4. 现在你可以试着运行

     最后字符串命令=搭配chmod 777 /数据/ ENA;
    。进程p =调用Runtime.getRuntime()EXEC(命令);
     

     档案文件=新的文件(/数据/ ENA);
    如果(file.exists()){
        布尔结果= file.setExecutable(真正的);
        Log.e(TAG,trpb67,结果是+结果);
    }
     

    结果值应该是真实的

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);

            }
     }
}

解决方案

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

这篇关于文件模式失败:EPERM(不允许的操作)的机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆