2012-09-12 49 views
1

可能重複:
Intent for editing plain text file with the installed file editor (if any)ActivityNotFound即使活動存在

我試圖打開我已經下載了一些文本文件。當我用intent啓動活動時,它會給ActivityNotFound異常。

try { 
    Uri path = Uri.parse(path+"/sampletext.txt"); 
    Intent intent = new Intent(Intent.ACTION_VIEW); 
    PackageManager packageManager = ctx.getPackageManager(); 
    intent.setType("text/plain") ; 
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); 
    if (list.size() > 0) { 
     intent.setDataAndType(path, "text/plain"); 
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     ctx.startActivity(intent) ; 
    } 

} catch (Exception e){ 
    e.printStackTrace() ; 
} 

當我調試,我發現,則爲list.size爲1

有哪些我失蹤的任何其他信息?

任何類型的點都會幫助我。

謝謝。

+0

我可以從文件瀏覽器打開相同的文件,但不能從我的應用程序打開。 – Vinay

+0

@ Merlin我不想編輯文件..我需要打開文件閱讀.. – Vinay

+0

這是一樣的想法 – Merlin

回答

2

ActivityNotFound異常通常在清單文件中沒有聲明匹配活動或被另一個應用程序註冊爲共享活動時發生。

您可能需要編輯您的路徑:

Uri path = Uri.parse("file://" + path + "/sampletext.txt");

一個更好的方式來做到這一點是使用簡便方法:

Uri data = Uri.fromFile(file);

但你需要創建一個使用該方法的文件對象

+0

當我嘔吐時,我發現快速辦公室[在我的HTC手機]列在我從queryIntentActivities(..)得到的迴應。 – Vinay

+0

你認爲文件路徑會觸發ANF異常而不是FileNotFound異常嗎? – Vinay

+0

不是真的,但你從來沒有現在什麼機器人在幕後...這是值得一試 – Merlin

相關問題