从非 root phone 的内部存储中删除文件

Deleting files from internal storage of a non-rooted phone

我不知道这个问题是否会被标记为无用或类似的东西,但我真的很好奇所以认为这是最好的提问地点。

是否无法从非 root 的 phone 的内部存储器中删除文件而不对其进行 root?我尝试了 deleteFile(uri.toString()) ,其中 uri 是文件路径,在它的正下方添加了一个日志 Log.e("msg", "deleted") ,它也显示在logcat,但问题是在所有这些之后文件仍然存在。怎么办?

更新: 这是我的代码:

public class MainActivity extends Activity {

    ListView list ;
    ListAdapter listAdapter;
    ArrayList<String> listTest;
     String name;
     Uri uri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        list = (ListView)findViewById(R.id.list);
        listTest = new ArrayList<String>( );

        Scanner(Environment.getRootDirectory()+"/");

         if(listTest.size() != 0)
            {
                listAdapter=new ListAdapter(getApplicationContext(),listTest);
                list.setAdapter(listAdapter);

                list.setOnItemClickListener(new OnItemClickListener() 
                {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
                {

                     name = (String) ((TextView) view).getText();


                    view.setSelected(true);


                    uri = Uri.parse(listTest.get(position).toString());
                    File fl = new File(uri.toString());
                    deleteFile(uri.toString());
                    Log.e("msg", "deleted");
                    Toast.makeText(getApplicationContext(), name+".apk"+" is deleted from internal storage", Toast.LENGTH_SHORT).show();
                    /*if(fl.exists())
                    {
                        fl.delete();
                        Log.e("msg", "deleted");
                        Toast.makeText(getApplicationContext(), name+".apk"+" is deleted from internal storage", Toast.LENGTH_SHORT).show();
                    }*/


                    list.setSelection(position);




                }});





            }




    }


      private void Scanner(String path) {
            // TODO Auto-generated method stub
            {
                try 
                {
                        File fl = new File(path);
                        File[] listOfFiles = fl.listFiles();              

                        for (File listOfFile : listOfFiles)
                         {
                            String s = listOfFile.getName();

                            if(s.endsWith(".apk"))
                            {


                            // store file name in listSoundNames
                            int pos = s.lastIndexOf(".");
                            if (pos > 0)
                            {
                              name = s.substring(0, pos);

                            }
                            listTest.add(name);

                            }


                            /////////////////////////////////
                            File f = new File(path+s+"/");
                            if (f.exists() && f.isDirectory()) {
                            Scanner(path+s+"/");
                            }
                            ////////////////////////////////


                        }



                }
            catch (Exception e) { }
            }

            }
}

非root是不可能的。您只能删除 /data/data/your_package_name.

中的文件