2017-08-25 1 views
0

J'ai essayé d'ouvrir pdf en utilisant pdf reader. mais aucune application n'a été trouvée.Comment détecter Setaction dans l'intention android?

comment puis-je trouver est-il une application disponible avant d'afficher le message.

Je veux ouvrir la fenêtre contextuelle de l'application uniquement s'il existe une application pour ouvrir le fichier pdf, comment puis-je l'ajouter?

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

Regardez ceci: https://stackoverflow.com/questions/15407502/how-to-check-if-an-intent-can-be-handled-from-some-activity –

Répondre

0

Essayez ceci;

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

Après avoir ajouté la package il ouvrira seulement dans Adobe Reader? @ vishal-vaishnav – Rakesh

+0

yaa definetely ... –

+0

Je veux que toute application ouverte disponible. Si aucune application disponible je veux montrer le toast pas besoin de la popup comment l'ajouter? @ Vishal-vaishnav – Rakesh