2017-08-25 11 views
0

私はpdfリーダーを使用してpdfを開こうとしました。 しかし、アプリケーションが見つかりませんでした。意図のアンドロイドでの設定を検出する方法は?

メッセージを表示する前に、使用可能なアプリケーションが見つかっていますか。

私はどのアプリケーションをpdfファイルを開くために存在する場合のみ、アプリケーションポップアップを開きたいのですが、どのように追加できますか?

Intent target = new Intent(); 
target.setType("application/pdf"); 
target.setData(Uri.parse(attachment)); 
target.setAction(Intent.ACTION_GET_CONTENT); 
Intent intent = Intent.createChooser(target, "Open File"); 
+0

これを見て:https://stackoverflow.com/questions/15407502/how-to-check-if-an-intent-can-be-handled-from-some-activity –

答えて

0

これを試してください。

Uri path = Uri.fromFile(file); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.parse(attachment), "application/pdf"); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

try { 
     startActivity(intent); 
    } 
    catch (ActivityNotFoundException e) { 
     Toast.makeText(OpenPdf.this, "No Application Available to View PDF", 
         Toast.LENGTH_SHORT).show(); 
    } 
+0

ので、追加した後、パッケージは、それだけのAdobe Readerで開くでしょうか?@ vishal-vaishnav – Rakesh

+0

yaa definetely ... –

+0

私はそれが開いている任意のアプリをご利用ください。もし利用可能なアプリがない場合、私はトーストを表示したいのですが、ポップアップを追加する必要はありません?@ vishal-vaishnav – Rakesh

関連する問題