Reputation: 481
I've written this code for training but it's always returning null (I checked the sdcard and file exists, and also checked required permissions).
private class FindRec extends AsyncTask<String, Integer, File>{
ProgressDialog pd = ProgressDialog.show(Albums.this, "Finding...", "");
@Override
protected void onPreExecute() {
pd.show();
}
@Override
protected File doInBackground(String... album) {
File e1 = new File(Environment.getExternalStorageDirectory() + "/bluetooth/" + album + ".zip");
if (e1.exists()) {
return e1;
}
return null;
}
@Override
protected void onPostExecute(File result) {
pd.dismiss();
if (result == null) {
//I always get this toast.
Toast.makeText(getApplicationContext(), "Album Not Found!", Toast.LENGTH_SHORT).show();
} else {
setfile(result);
}
}
then in my oncreate:
...
new FindRec().execute(albumname);
Upvotes: 0
Views: 31
Reputation: 44158
You receive an array of strings in doInBackground, so fetch the first element of that array instead of implicitly converting the array to a string.
File e1 = new File(Environment.getExternalStorageDirectory() +
"/bluetooth/" +
album[0] + ".zip");
Upvotes: 1