我让用户选择自己的下载位置,但一旦选择,该文件仍会被下载到常量值" HOME"。 我认为这个值需要替换为用户选择的下载位置,但我不知道如何。
感谢您帮助我。
//choose download location//
public void onClick(final View v) {
switch (v.getId()) {
case R.id.pick_location_dialog_ok: {
if (listener != null) {
final EditText path = (EditText) findViewById(R.id.pick_location_dialog_path);
final String loc = path.getText().toString();
listener.onDownloadLocationChanged(loc);
}
dismiss();
}
break;
case R.id.pick_location_dialog_cancel: {
dismiss();
}
break;
case R.id.pick_location_dialog_choose_path: {
//
}
break;
}
}
//applies onDownloadLocationChanged//
public void onDownloadLocationChanged(final String newLocation) {
final Settings settings = new Settings(this);
final String original = settings.getDownloadsLocation();
if (!newLocation.equals(original)) {
new File(newLocation).mkdirs();
settings.setDownloadsLocation(newLocation);
final SettingsMenuItem item = (SettingsMenuItem) findViewById(R.id.settings_download_location);
item.setValue(newLocation);
final AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setTitle(R.string.app_name);
b.setMessage(R.string.settings_auto_check_updates);
b.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int which) {
new MoveFilesTask(SettingsActivity.this, original, newLocation).execute();
dialog.dismiss();
}
});
b.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int which) {
dialog.dismiss();
}
});
b.create().show();
}
}
}
//
//
//excutes download with choosen path, replace Constants.HOME with chosen download location//
final File parentDir = new File(Constants.HOME, title);
if (!parentDir.exists())
parentDir.mkdirs();
final File file = new File(parentDir, (filename));
notification = new ProgressNotification(DownloaderService.this, file);
super.onStart(intent, startId);
new Thread()
{
public class Constants {
//
public static final File HOME = new File(Environment.getExternalStorageDirectory(),
"homeloc");
//
}
答案 0 :(得分:0)
我自己解决了,这是正确的代码:
@Override
public void onStart(final Intent intent, final int startId) {
//
final Settings settings = new Settings(this);
final File parentDir = new File(settings.getDownloadsLocation() + "/", title);
//
}