I don't know that if this question will be marked as not useful or something like that, but I am really curious about it so thought this would be the best place to ask.
Is it impossible to delete files from internal memory of a non-rooted phone without rooting it? I tried deleteFile(uri.toString()) where uri is the file path, added a log Log.e("msg", "deleted") just below of it which is also displaying in the logcat, but the problem is that the file still exists after all of these. What to do?
Update: This is my code:
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) { }
}
}
}
It is impossible if non-rooted. you can only delete files in /data/data/your_package_name.