简体   繁体   中英

How to create an intent to open .doc file using Polaris Viewer on Android?

I am trying to open a .doc file from my SD card using Polaris Viewer. I keep on getting a message saying "This document cannot be opened".

weird thing is that I CAN open it from elsewhere. I have ES File Explorer on my phone and I can open through there. It does it via Polaris Viewer so the file is obviously okay.

The only thing I can think of is that I have a problem with my intent. Is there any way to see exactly what intent ES File Explorer sent?

This is my code (textOpenUri is a full path name of the file to be opened):

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(textOpenUri, "application/msword");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);

I did a small test (just to make sure it is not defaulting to some other app) using:

List<ResolveInfo> list = getActivity().getPackageManager().queryIntentActivities(intent,0);

and I get back Polaris as the only app that can deal with the intent.

    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri = Uri.fromFile(file);
    intent.setDataAndType(uri, "application/msword");
    this.startActivity(intent);
    startActivity(intent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM