I am trying to pick a file like docs or pdf from my app and send the file to my server using okhttp. I am getting a uri from using an intent
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, FILE_PICKER_REQUEST_CODE);
I am unable to get the full path of the file for creating a file.
I need paths like this
/storage/emulated/0/document/admin.pdf
All I need is a file that I can send to the server by any means.Help please.
Related
I'm trying to open a file from assets with an application using the code below:
String fileUri = "file:///android_asset/extensions/file.novabackup";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(fileUri), "application/octet-stream");
intent.setPackage("com.teslacoilsw.launcher");
startActivity(intent);
However, it does nothing and simply returns me to the MainActivity. I've also granted READ and WRITE access.
Hello I wish to upload a csv file in android but somehow this code segment doesn't work for csv file.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/csv");
startActivityForResult(intent, OPEN_REQUEST_CODE);
You should probably use ACTION_GET_CONTENT instead of ACTION_OPEN_DOCUMENT, and you'll need to add CATEGORY_OPENABLE to the Intent.
See the selected answer at Android Intent choose CSV for import
I would like to open a Text file launcher from my application.
I have a byte[]/base64 data, that needs to be launch in an app based on their extension. I tried launching a text file using below code, but im unable to do so. Could any one please help me on this? Here is my code:
Uri myUri = Uri.parse(mActionResponse.getAttachmentData()); //mActionResponse.getAttachmentData() will return byte []
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setDataAndType(myUri, "text/plain");
context.startActivity(intent);
FYI i dont want to save the file in device storage.
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 created a pdf file in my application and successfully stored that in sdCard, now i want to store the pdf not in my sdcard but in Internal storage as shown here but when i open an intent for pdf readers as:
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
Log.v("Path",file.getAbsolutePath()); // Path data/data/com.cloudchowk.his.patient/files/LIPID PROFILE1300000403.pdf
i.setDataAndType(uri, "application/pdf");
startActivity(i);
The PDF reader shows an error The document path is not valid.
I have tried this on two devices one was rooted and one was not, but it was not working on any of them. What should i do ? any ideas?
Get the path and create URI
File internalFile = getFileStreamPath("pdf path");
Uri file = Uri.fromFile(internalFile);
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(file, "application/pdf");
startActivity(i);
To make a file from internal storage available to other apps the cleanest approach is to use a content provider.
Luckily, Android comes with FileProvider – an implementation that might just serve your needs.
You don't need to implement code, you just need to specifiy the provider in your manifest.