Here is the intent I use to open a word file:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_EDIT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(fileUri, MimeTypeMap.getSingleton().getFileExtensionFromUrl(fileUri));
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
mContext.startActivity(intent);
I feth the fileUri using this line:
FileProvider.getUriForFile(context, "my authority", file);
File is opened correctly in both Microsoft word app and OfficeSuite app, but in both apps, the file is in read only mode and I cannot edit the file directly. When I open that word file with a file manager app like ES File Explorer, the file is in read write mode and edit is enabled.
I tried both ACTION_VIEW and ACTION_EDIT and the same happened.
Related
I have a file stored in my App's storage like this:
/storage/emulated/0/Android/data/com.example.myapp/files/App files/90210_John_s_Resume.pdf
the 90210 at the beginning is a file ID for internal purposes only, and I give the user the option to save this file to Downloads folder, where I remove the 90210 prefix. But I also provide the user to preview the file using ACTION_VIEW intent. This causes an issue where the file name in the previewed app still has the 90210 prefix. Is there a way to overcome this?
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri fileUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", finalFile);//NO I18N
intent.setDataAndType(fileUri, URLConnection.guessContentTypeFromName(fileUri.toString()));
context.startActivity(intent);
I'm trying to use Intent ACTION_GET_CONTENT to open an application such as (File Manager, File explorer etc...). However once I am in the File Manager, I am only able to open the file. The Copy to.. and Move to... capabilities are not shown when opening File Manager app using this method. Is ACTION_GET_CONTENT only used for opening files?
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath());
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
Here is the image showing the open option only:
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);
I have a doc file on sdcard.
I want to open it in read-only mode. Also I don't want the document viewer to save the file.
The intent to open the file is as follows:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("/sdcard/test.doc");
file.setReadOnly();
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION );
intent.setDataAndType(Uri.fromFile(file), "application/msword");
startActivity(intent);
But when the file opens in quickOffice, the file is still editable.
Please suggest how should I make the file ready-only to any document viewer and how should I prevent file from saving.
It is probably because your app does not have root access. File permissions can be changed by root access only.
I want my app to open a plain text file with any of the file editors installed on my terminal, but I keep getting this exception:
ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT dat=file:///sdcard/folder/file.txt }
First I thought that I have no File editor installed, but if I use ASTRO file manager, I can get to open the file both with "File Editor" and "QuickOffice", so I think the problem is that I'm not using the right code...
Here is the code
Intent intent = new Intent(Intent.ACTION_EDIT);
Uri uri = Uri.parse("file:///sdcard/folder/file.txt");
intent.setDataAndType(uri, "plain/text");
startActivity(intent);
What is more surprising is that if I use the path of a file that doesn't exist, it keeps raising the same exception...
Thanks
The MIME type is text/plain.