代碼如下:
Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(filePath)), type); context.startActivity(intent);
異常信息提示如下:
03-20 16:46:48.760: E/AndroidRuntime(30325): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///storage/sdcard0/e-books/Books/book/課堂/PPT/第2章 移動終端.ppt typ=application/vnd.ms-powerpoint flg=0x10000000 }
經過:在有的手機,可以打開ppt文件,在我自己的手機打不開,調試后發現上面的錯誤信息。
原因:手機沒有安裝可以打開ppt文件的應用,會出現上面的問題。
解決方法:為了避免有的手機沒有安裝打開相應文件的應用,應該在startActivity那里做一個try catch,彈出一個toast做提示