File.exists在USB-Stick上

时间:2014-12-13 12:22:00

标签: android usb

我想检查USB记忆棒上是否存在某个文件,通过OTG-Adapter插入。 以下代码返回始终为false,无论发生什么。删除if子句时可以打开该文件。

File usb_dir = Environment.getExternalStorageDirectory();
File myFile = new File(usb_dir+ "/update.apk");

if (myFile.exists()==true) {
    final Intent promptInstall = new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.parse("file:///mnt/usb_storage/update.apk"), "application/vnd.android.package-archive");
    promptInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(promptInstall);

} else if (myFile.exists()==false){
    Toast.makeText(getApplicationContext(), "Not working!", Toast.LENGTH_LONG).show();
}

即使这不起作用:

 String usb_dir = Environment.getExternalStorageDirectory().getAbsolutePath();
 File myFile = new File(usb_dir+ "/update.apk");

有人可以帮助我吗?

0 个答案:

没有答案