私のコードは、名前に "hss"という文字列を持つファイルをすべて削除するためのコードです。これは内部メモリのすべてのファイルで正常に動作しますが、フォルダ内に存在するファイルは削除されません。androidのファイルを削除する適切な方法
どうすればいいですか?括弧内の
if (listFile[i].isDirectory()) {
}
入れて何かが...あなただけの別の方法deleteDirectory
にあなたのdoInBackground
方法のほとんどをリファクタリングし、再帰的にこれを呼び出すことができます。
public class RemoveApkTraces extends Activity {
// getting SDcard root path
File dir = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.done_ui);
// at the end of oncreate
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
new ExplorerDBOperation().execute();
}
}, 300);
}
class ExplorerDBOperation extends AsyncTask<Void, Boolean, Boolean> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = ProgressDialog.show(RemoveApkTraces.this, "Please wait",
"Processing.........");
}
@Override
protected Boolean doInBackground(Void... params) {
String Patternjpg = "hss";
File listFile[] = dir.listFiles();
if (listFile != null) {
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
} else {
if (listFile[i].getName().contains(Patternjpg)) {
// Do what ever u want
listFile[i].delete();
}
}
}
}
return true;
}
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
}
}
@abbieは、ノートを見たことがありますか?私は今のところ近くのIDEを持っていないが、私はあなたが考えを得ることができると思う..あなたがあなたの問題であなたを導くことだと思う、* please-write-code-for-me *サービス... –
見た。答えに感謝します。あなたがこれに答えることができるかどうか疑問に思っています:http://stackoverflow.com/questions/36323872/copy-files-from-assets-folder-to-sd-card-in-android – abbie