Commit 23f467f4 by amateur

1

1 parent 55019361
......@@ -97,10 +97,18 @@ public class IntentUtils {
}
public static void startOpenFile(Context context, Uri fileUri) {
Intent intent = new Intent(Intent.ACTION_VIEW);
String extension = MimeTypeMap.getFileExtensionFromUrl(fileUri.toString());
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
intent.setDataAndType(fileUri, mimeType);
context.startActivity(intent);
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= 24) {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
String extension = MimeTypeMap.getFileExtensionFromUrl(fileUri.toString());
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
intent.setDataAndType(fileUri, mimeType);
context.startActivity(Intent.createChooser(intent,"选择打开工具"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!