I have an app that downloads files to folder selected by the user.
I get access to the folder using :
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(intent,REQUEST_PICK_FOLDER_TO_DOWNLOAD);
create the downloaded file with
DocumentFile newFile = destDir.createFile(mime, file.getFileName());
I need to share the file. For example if this is a text file, pdf or word doc user can open it in the appropriate app.
File URI seems pretty strange:
"content://com.android.externalstorage.documents/tree/primary%3Amy_logs/document/primary%3Amy_logs%2Fford-f-150-raptor-2019-491746%20(1).jpg"
But it is a file created with createFile and I am able to write the contents.
I am not sure FileProvider can help as the dest folder is any folder on the device.
I am not sure is there anyway to share that URI with any other app?
Thank you very much!
V
Related
I want to show downloaded file in File Manager by giving the File absolute Path.I read a lot about it and find same thing
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(file.getAbsolutePath());
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
And it results to view only recent files that has been viwed. Please guide to Open File Manager while navigating it to file whose absolute path has been given.
I read a lot about it and find same thing
ACTION_GET_CONTENT has little to do with a file manager.
Please guide to Open File Manager while navigating it to file whose absolute path has been given.
There is nothing on Android for this, sorry.
I am new in android Java.
I am trying to share an image in android application using Phonegap. I get new class "Share" as CordovaPlugin, code is follow...
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
Uri uri = Uri.parse("file:///android_asset/www/sharethis.png");
share.putExtra(Intent.EXTRA_STREAM, uri);
cordova.getActivity().startActivityForResult(share, 0);
Above code is not working, it showing like this ...
is think i cant get Exact image file location.
My file location
I tried bellow code also, But not work,
String imagePath = Environment.getExternalStorageDirectory()
+ "/assets/www/sharethis.png";
Android asset folder is private to your app so you can't share files from there directly. You need to copy the file from assets to a public directory in the filesystem and then send the share intent pointing to the public file
I am new in android Java. I am trying to share an image in android application using Phonegap. I get new class "Share" as CordovaPlugin, code is follow...
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
Uri uri = Uri.parse("file:///android_asset/www/sharethis.png");
share.putExtra(Intent.EXTRA_STREAM, uri);
Above code is not working, it showing like this ...
is think i cant get Exact image file location. My file location
I tried bellow code also, But not work,
String imagePath = Environment.getExternalStorageDirectory()
+ "/assets/www/sharethis.png";
Please Help
Android asset folder is private to your app so you can't share files from there directly. You need to copy the file from assets to a public directory in the filesystem and then send the share intent pointing to the public file. Have a look here
I have application which generate PDF, then I put in folder A, how can I open and exploring all files in folder A when clicked button (showing new Intent)? I wish that my preview like when click My Files >> Folder A >> [files].
Doe this code help?
original source
String folderPath = Environnement.getExternalStorageDirectory()+"/A";
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
Uri myUri = URI.parse(folderPath);
intent.setType("file/*");
startActivity(intent);
This function will get you the sdcard root :
getExternalStoragePublicDirectory()
After getting the root you can create or open a folder.
to create a folder use
mkdir()
or
mkdirs()
functions.
to get all the files from that folder you can use File object.
Here is the example source code for file explorer in android :
https://github.com/mburman/Android-File-Explore
Its very straightforward forward code
I have to build an Android application which shows a list of pdf files. These pdf files should be secured, in other words - the user of the app should not be able to get a copy of the pdf content by any means (copy/cut/print...etc). My questions now are
How should I ship the content of the pdf file along with .apk file.
If we send the content of the file in a diff format (raw/byte code), how should I convert the file back to pdf and where should I place the file on the installed machine such that it is secure.
FYI, I will be locking down current version of Adobe Redaer as the pdf viewer to view the pdf files as it doesn't allow copy/paste/print.
This is the first Android app that I am developing. So, I'm a kind of Android newbie. Any help would be greatly appreciated.
Thanks,
Navin
Probably you should store it in the res/raw folder
You can copy this(these) pdf file(s) into assets folder, thus your files will be the part of your application and can not be accessible outside, and you can also treat them as normal files (i.e. open with any pdf viewer in your case). Whenever you want to get access to context file you can call context.getAssets() .
Hope this information helps.
Update : Here is the code I am using to open a file in downloads directory, this code can open the pdf file in any compatible pdf reader if installed on phone, Tested with Adobe Reader. You will need a URI of the pdf file in assets folder to run the code.
String fileName = pdfUrl.substring(pdfUrl.lastIndexOf("/"));
Log.i("fileName", "" + fileName);
File file = new File("/sdcard/download" + fileName);
// File file = new
// File("/sdcard/download/airtel_latest000.mp3");
Intent intent;
if (file.exists()) {
Uri path = Uri.fromFile(file);
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
downloaded = true;
} else {
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(pdfUrl));
downloaded = false;
}
try {
startActivityForResult(intent, 5);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}