简体   繁体   English

SD卡路径在Android中正确的路径?

[英]SdCard path correct path in android?

I don't know if the problem is the incorrect sdcard path or something else, but in my application i have a button that onClick it create a copy of the app folder in the sdcard (of course needs root). 我不知道问题是否出在错误的sdcard路径或其他东西上,但是在我的应用程序中,我有一个按钮,onClick它会在sdcard中创建app文件夹的副本(当然需要root)。 To me it works, i have stock android 4.4 with nexus 5 and it creates a folder named BackupApps in where there is the folder app with all apk files but some users tells me that the folder is not created. 对我来说,它起作用了,我有带有nexus 5的库存android 4.4,它在其中创建了一个名为BackupApps的文件夹,其中有包含所有apk文件的文件夹app ,但有些用户告诉我未创建该文件夹。 Here the code: 这里的代码:

first; 第一; i created the path in sdcard with the new folder that will created: 我在sdcard中使用将创建的新文件夹创建了路径:

final File customfolder=new File(Environment.getExternalStorageDirectory().toString()+File.separator+"BackupApps");

then the onClick code: 然后是onClick代码:

copy.setOnClickListener(new OnClickListener() {         
            public void onClick(View v){        
                        Process checkroot = null;
                        String rootcheck ="su";
                        String cd = "cd /";
                        String comando ="su cd cp -av /data/app "+customfolder;
                        customfolder.mkdir();
                        try {
                            Process copy = Runtime.getRuntime().exec(comando);
                            Toast.makeText(getActivity(), appmanagerfragment.this.getResources().getString(R.string.toastcopysi), 
                                    Toast.LENGTH_LONG).show();
                            Log.v("All In One Copia tag","Ok, folder copied in "+customfolder);

                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }                  

        });

any idea? 任何想法?

I do not think your commando is correct, becuse su cd cp... makes no real sense. 我不认为您的commando是正确的,因为su cd cp...没有任何实际意义。 You should remove cd from commando 您应该从commando删除cd

At first, there is a constructor for File, File(String,String) , that adds the separator by itself. 首先,有一个File的构造函数File(String,String) ,它自己添加了分隔符。

At second, I'm not sure there's su in a non-rooted android. 第二,我不确定非root用户的android中是否有su In addition, some command line keys may not be supported in Android, for example, ls -l works, but 'ls -lF' does not. 此外,Android可能不支持某些命令行键,例如ls -l可以,但是'ls -lF'不可以。 I suggest you run adb shell and perform the commands from the command line; 我建议您运行adb shell并从命令行执行命令。 when you know they do what you want, you move them to the code. 当您知道他们在做什么时,就将其移至代码中。

BTW, shell commands in the command line are separated with ; 顺便说一句,命令行中的shell命令用;分隔; .

In general, I if the task is to copy a directory, I suggest (pardon) searching google with "copy directory java" or "copy directory android stackoverflow" and borrowing someone else's code. 通常,如果任务是复制目录,我建议(原谅)使用“复制目录java”或“复制目录android stackoverflow”搜索Google并借用他人的代码。 For example, this or this . 例如, thisthis And add the permission to write to sd card to your application. 并将写入SD卡的权限添加到您的应用程序。 (BTW, this may be the reason why the subprocess failed.) (顺便说一句,这可能是子流程失败的原因。)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM