2012-03-14 66 views
0

我有一些麻煩讓Adobe Reader應用程序打開我的SD卡中的PDF ... 這是我目前正在嘗試。意圖URI傳輸問題

Intent intent = new Intent(Intent.ACTION_VIEW); 
String aux = Environment.getExternalStorageDirectory() + "/mhtemp/jazz.pdf"; 
intent.setDataAndType(Uri.parse(aux), "application/pdf"); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
try { 
    startActivity(intent); 
    } 
catch (ActivityNotFoundException e) { continues.... 

當我繼續做這件事時,我從Adobe閱讀器得到一條通知:「文件無法打開」。不過,我使用fileviewer進行了檢查,該文件確實存在於我創建的文件夾中。最重要的是,如果我嘗試從文件查看器中打開它,它就可以工作!我不知道我做錯了這裏的意圖......

回答

2

試試你的文件路徑轉換爲開放的正確,像這樣:

Intent intent = new Intent(Intent.ACTION_VIEW); 
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "/mhtemp/jazz.pdf")); 
intent.setDataAndType(uri, "application/pdf"); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
try { 
    startActivity(intent); 
    } 
catch (ActivityNotFoundException e) { continues....