0

How can i open a file using adobe reader. The pdf file is already created from my application when user want to open then the prompt should be open with adobe reader.It is like when we want to share some apps using mobile the prompt occurs as bluetooth etc....I want a code for that.Suggest me some idea.

sheetal
  • 11
  • 1
  • 4

2 Answers2

0

you can use this code, it's perfect for any file format.

File file = new File("Path of file");

String extension=MimeTypeMap.getFileExtensionFromUrl(path);
MimeTypeMap map = MimeTypeMap.getSingleton();
String mimeType=map.getMimeTypeFromExtension(extension);

PackageManager packageManager = activity.getPackageManager();
        Intent testIntent = new Intent(Intent.ACTION_VIEW);
        testIntent.setType(mimeType);
        List<?> list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
        if (list.size() > 0 && file.isFile()) 
        {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            Uri uri = Uri.fromFile(file);
            intent.setDataAndType(uri, mimeType);
            activity.startActivity(intent);
        }
Krunal Indrodiya
  • 782
  • 2
  • 7
  • 19
0

First check that there is an App to receive your 'open_pdf' intent. Do the following to perform the check:

PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;

Then you can perform:

intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(your_file_object);
startActivity(intent);

You can refer this: http://developer.android.com/training/basics/intents/sending.html