I want to delete all file in camera folder of my internal smartphone's storage before it goes off!
How can i do?
namespace App1
{
[Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView (Resource.Layout.Main);
Button delete = FindViewById<Button>(Resource.Id.deleteid);
delete.Click += delegate
{
File dir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim), "/Camera");
if (dir.IsDirectory)
{
int i = 0;
string[] children = dir.List();
while ( i < children.Length)
{
var file = new File(dir, children[i]).Delete();
i++;
}
Toast.MakeText(this, "The folder exist", ToastLength.Short).Show();
}
else
{
Toast.MakeText(this, "Not Works", ToastLength.Short).Show();
}
};
}
}
}
I tried to use this code to delete the content of folder but the app crashes.
You need to create receiver for listen a shutdown event. For this needs you should implement class Service and don't foget to add following lines in manifest file:
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
Also, for delete users data, make shure that you have permissions to do that:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.