android how to make accessible data folder content to other application - android

I want to open a pdf file saved in application data folder using pdf viewer application. How can i make accessible data folder content to other application. Some code snippet will help me lot.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType( Uri.parse("content://" + pdf_path), "application/pdf" );
startActivity(intent);

File file = new File(“/sdcard/read.pdf”);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),”application/pdf”);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
You can access pdf file from external memory by this.make sure you are giving correct path of it.

First of all make sure your .pdf file has, MODE_WORLD_READABLE Permission like,
Now to access .pdf file from application data folder means, /data/data/<package_Name>/
Use, getFilesDir() which returns the path of Application data directory,
Then,
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(getFilesDir()+ "pdf_path")),"application/pdf" );
startActivity(intent);

Related

Is there a way to open a file stored in andorid assets with a specific application?

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.

How to open default gallery app with particular album or folder?

Every example i found on net is opening gallery and get images from gallery as result. My need is i don't want result or images to my app. I just want to trigger gallery app with showing particular folder of images. My App Have separate folder to save images. i need to navigate users directly to that path.
Try this code. It will retrieve view pictures under storage/emulated/0/Pictures/AppPics You can change the file path according to your directory path.
File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File file = new File(sdDir, "AppPics");
if (file.isDirectory())
listFile = file.listFiles();
EDIT: To open your folder using intent
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.withAppendedPath(Uri.fromFile(file), "/AppPics"), "image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
You can try like this,
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = [Uri for your folder];
intent.setDataAndType(uri, "image/*");
startActivity(Intent.createChooser(intent, "Open [App] images"));

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);

Show local PDF-File with external app

I would like to open a local PDF file with a pre-installed PDF-viewer via Share-Intent like this:
Uri uri= Uri.parse("file:///android_asset/manual.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setType("application/pdf");
startActivity(intent);
The app-picker is shown, when I click on Adobe PDF it doesn't show the PDF-file however.
Am I doing something wrong, or is it simply not possible?
This worked for me,
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/directory/"+theNamesOfFiles)),"application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
You have 2 options:
Put the file in a public storage where the PDF viewer app can access it
Use a ContentProvider class to give that PDF viewer access to a private file.
See:
How to copy files from 'assets' folder to sdcard?
http://developer.android.com/guide/topics/providers/content-provider-creating.html

Trouble Storing pdf in internal storage and viewing it from adobe

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.

Categories

Resources