1

[This question may be duplicate, but i din't find what i am looking for]

[Read]How can we open files like ppt, doc, pps, rtf, etc. in Android?

I am having PPT files. In my app, i have a list view which display the PPT file list available in my private app folder. In click of particular file, i want to open corresponding PPT file for reading in my App.

The App which i am creating is just like collection of PPTs and reading them one by one.

Please provide any API/Example/Links.

Community
  • 1
  • 1
Sandy
  • 6,285
  • 15
  • 65
  • 93

2 Answers2

4

You need to use other application to open your ppt files , Make sure that file location you are providing is accessible to other application. Try with following :

 final Uri uri = Uri.fromFile(file); 
    final Intent intent = new Intent(Intent.ACTION_VIEW); 
    intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); 

    PackageManager pm = getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
    if(list.size() > 0)
       startActivity(context, intent);

Available application will be shown to user and user can choose application which can open.

Ashish Patil
  • 374
  • 4
  • 20
Satty
  • 1,352
  • 1
  • 12
  • 16
0
private void openPPT(final String path) {
    File file = new File(path);
    Uri uri ;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                uri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", file);
            } else {
                uri = Uri.fromFile(file);
            }

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setDataAndType(path, "application/vnd.ms-powerpoint");
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, "Application not found", Toast.LENGTH_SHORT).show();
    }
}
Satyawan Hajare
  • 1,112
  • 11
  • 10
  • Use above code is useful for read and open ppt file in android use fileprovider for Build.VERSION.SDK_INT >= Build.VERSION_CODES.M add Provider path in Android Manifext. – Satyawan Hajare Apr 03 '19 at 10:03