首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在我的应用程序中设置"android.uid.system“后无法访问SD卡?

在我的应用程序中设置"android.uid.system“后无法访问SD卡?
EN

Stack Overflow用户
提问于 2011-07-13 20:38:38
回答 5查看 7K关注 0票数 4

这是一个奇怪的问题。如果我没有将android.uid.system设置为SD卡,我的应用程序可以成功访问SD卡。但是在将android.uid.system设置为它之后,我的应用程序不能访问SD卡。此时,异常发生了:07-13 09:11:24.999: INFO/System.out(9986): create file happen exception--->java.io.IOException: Permission denied。我检查我在正确的位置写了正确的权限:

代码语言:javascript
运行
复制
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />. 

因为在我的应用程序中使用forceStopPackage,所以我需要将android.uid.system添加到清单中。并且我已经在make文件中编写了LOCAL_CERTIFICATE := platform。谁能解释这个奇怪的问题。在设置android.uid.system后,我的应用程序属于系统进程,它应该有更多的权力访问SD卡。这是我的主意。以下是我的代码:

代码语言:javascript
运行
复制
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() );
        }

    }

我的应用程序在仿真器上运行,他的目标版本是2.3。非常感谢。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2011-07-14 13:43:18

请阅读以下内容:link1

这个link2

票数 5
EN

Stack Overflow用户

发布于 2011-07-13 20:49:47

使用Environment.getExternalStorageDirectory().getAbsolutePath()而不是"/mnt/sdcard"获取路径

票数 0
EN

Stack Overflow用户

发布于 2011-07-13 20:50:26

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

这不会起作用:File share = new File("/mnt/sdcard", "test.txt");

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6679011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档