简体   繁体   English

在我的应用程序中设置“android.uid.system”后无法访问sdcard?

[英]It can't access the sdcard after setting “android.uid.system” in my application?

This is a strange problem.这是一个奇怪的问题。 My Application can access the sdcard successfully if I don't set android.uid.system to it.如果我没有设置android.uid.system ,我的应用程序可以成功访问 SD 卡。 But after setting android.uid.system to it, my application can't access the sdcard.但是在将android.uid.system设置为它之后,我的应用程序无法访问 sdcard。 At this time, the exception take place: 07-13 09:11:24.999: INFO/System.out(9986): create file happen exception--->java.io.IOException: Permission denied .此时发生异常: 07-13 09:11:24.999: INFO/System.out(9986): create file happen exception--->java.io.IOException: Permission denied I check I write the right permission in the right place:我检查我在正确的地方写了正确的权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />. 

Because use forceStopPackage in my application, I need to add android.uid.system to the manifest.因为在我的应用程序中使用forceStopPackage ,所以我需要将android.uid.system添加到清单中。 And I have written LOCAL_CERTIFICATE:= platform in the make file.我已经在 make 文件中写LOCAL_CERTIFICATE:= platform Who can explain this strange problem.谁能解释这个奇怪的问题。 After setting android.uid.system , my application is belong the system process which should have more power to access the sdcard.设置android.uid.system后,我的应用程序属于系统进程,应该有更多的权力来访问 sdcard。 This is my idea.这是我的想法。 The following are my code:以下是我的代码:

public void setPackage(String dir){

        System.out.println( "setPackage dir=="+dir  );
        File share=new File("/mnt/sdcard","test.txt");
        if(!share.exists()){
             try{
            share.createNewFile();

        }catch(Exception e){
            System.out.println( "creat file happen exception--->" +e.toString() );
        }
      }
         try{
           if(share!=null){
                System.out.println( "create file is not null"  );
                    FileOutputStream fops=new FileOutputStream(share);

                    fops.write(dir.getBytes());
                    fops.flush();
                    fops.close();
        }
        }catch(Exception e){
                System.out.println( "write Exception-->" +e.toString() );
        }

    }

And My application run at the emulator and his target version is 2.3.我的应用程序在模拟器上运行,他的目标版本是 2.3。 Thank you very much.非常感谢。

Please read this: link1请阅读: link1

and this link2这个链接2

You can see in android source code: frameworks\base\core\java\android\os\Environment.java, it have a function:您可以在 android 源代码中看到:frameworks\base\core\java\android\os\Environment.java,它有一个 function:

private static void throwIfSystem() {
    if (Process.myUid() == Process.SYSTEM_UID) {
        Log.wtf(TAG, "Static storage paths aren't available from AID_SYSTEM", new Throwable());
    }
}

This function would be called getExternalStorageDirectory() , hence app with system uid can't access sdcard if you don't hack aosp.这个 function 将被称为getExternalStorageDirectory() ,因此如果您不破解 aosp,具有系统 uid 的应用程序将无法访问 sdcard。

Use Environment.getExternalStorageDirectory().getAbsolutePath() to get the path, NOT "/mnt/sdcard"使用Environment.getExternalStorageDirectory().getAbsolutePath()获取路径,而不是"/mnt/sdcard"

Use: File share = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"test.txt");使用: File share = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"test.txt");

This won't work: File share = new File("/mnt/sdcard", "test.txt");这不起作用: File share = new File("/mnt/sdcard", "test.txt");

android.uid.system make your app bind system, but sdcard observered by system also, then if your app delete this, it can access the sdcard. android.uid.system 使您的应用程序绑定系统,但系统也观察到sdcard,然后如果您的应用程序删除它,它可以访问sdcard。 it seems它似乎

delete this line in your xml file:android:sharedUserId="android.uid.system"ystem删除 xml 文件中的这一行:android:sharedUserId="android.uid.system"ystem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android:sharedUserId =“ android.uid.system”从SDCard获取文件 - android:sharedUserId=“android.uid.system” Obtaining Files from SDCard 以android.uid.system用户身份进行测试 - Testing as android.uid.system user 当sharedUserId =“ android.uid.system”时,AudioDeviceCallback失败 - AudioDeviceCallback fails when sharedUserId=“android.uid.system” 如果将shareduserId设置为“ android.uid.system”,则无法运行Android单元测试 - cannot run android unit test if I set the shareduserId as “android.uid.system” 使用 android:sharedUserId=&quot;android.uid.system&quot; 属性获取 SystemProperties.java 类 - Getting SystemProperties.java class using android:sharedUserId="android.uid.system" attributes 我无法通过系统设置在Android应用上更改语言 - I can't change language on my android app by system setting 无法从SDCARD Android应用程序读取文件 - Can't read file from SDCARD Android Application 如何在Android系统上使用phonegap访问SDCARD中的图片 - How to access the picture in SDCARD with phonegap on Android system Android - 如何在启动后在/ sdcard上启动应用程序 - Android - How to start an application on the /sdcard after boot UID无权访问Android应用程序上的URI错误 - No permission for UID to access URI error on Android Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM