2013-07-07 31 views
1

嗨有沒有辦法讓操作系統打開一個文件,其預定義程序?android dev通過操作系統打開文件

我不知道它可能是什麼樣的文件,也許是一張照片,txt什麼。 我想發出一個命令給操作系統,讓它打開文件(我有文件路徑)與任何程序的操作系統需要。它可能是這樣的情況,操作系統打開對話框,要求用戶選擇一個程序來打開文件(這對我來說很好)。

感謝

回答

0

這是通過Intent您需要設置的操作和數據來完成。

//from inside an Activity 
Intent i = new Intent(Intent.ACTION_VIEW); 
i.setData(Uri.fromFile(theFileYouMentioned)); 
try{ 
    startActivity(i); 
} 
catch(ActivityNotFoundException) { 
    //user doesn't have an app that can open this type of file 
}