How do I use the PDFViewer.jar library in android? - java

I am trying to use the PDFViewer.jar library to read pdf into my application android pdf reader.
I wonder how to use to read pdf form the resources in asset folder.
it required to "PATH TO PDF GOES HERE"
Intent intent = new Intent(this, YourPdfViewerActivity.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "PATH TO PDF GOES HERE");
startActivity(intent);`

It's explaining quite good and works for me.
http://upadhyayjiteshandroid.blogspot.com/2013/03/android-pdf-viewer-application.html?showComment=1397014240605#c4120910608580621305

Yes path is required
Intent intent = new Intent(this, YourPdfViewerActivity.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "file:///android_asset/pdf_name.pdf");
startActivity(intent);

Related

Share Image to Snapchat

I want to share image to snapchat but giving me "Sorry! You can only share images and videos"
I tried this code but doesnt work Android share image on snapchat
I have this intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.setPackage("com.snapchat.android");
int n = Integer.parseInt(number.getText().toString());
Uri uri = Uri.fromFile(new File(db.getimage(n))); //This is retrieving the Uri path from DB
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Open Snapchat"));
the type that you are setting for the setType method is not correct,
if you want to support any format of Image, I suggest you first get the format of Image And after that pass the correct parameter to the setType() method.
for getting a file extension you can use this link:
link
For sharing data in snapchat, there is a kit available in their official website called Creative Kit.
Also you can find the Doc and Tutorials here.

How to use intent settype to search text file of custom file extension

I m using following code to open search intent to search text file in external storage:
private void performFileSearch()
{
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*text/*");
startActivityForResult(intent,READ_REQUEST_CODE);
}
But now I am going to create text file of custom file extension, for example textfile.tre,
this file is not search able by this intent.
So i change type to :
intent.setType("*/*");
Now intent is showing all the files. But I want to show only .tre file. What can be done?
Thanks
But I want to show only .tre file
Sorry, but that is not possible. Android, like the Web, works on MIME types, not file extensions.

Open file from specific folder with Intent.ACTION_OPEN_DOCUMENT

I would like to open the file picker at a specific path. The user should be able to pick any file on the phone, but the SAF should show a specific folder first. I tried the following but it always opens the downloads folder. Thanks!
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath());
intent.setDataAndType(uri,"image/*");
startActivityForResult(intent, 1);
you need to use the extra EXTRA_INITIAL_URI

Is there way to share *.json file via Intent or something else?

In my app I need to share *.json file to other app (messenger, google disk, etc). How can I do this via Intent or something else?
But when I trying to do this via Intent, I have some problems.
override fun shareBackupData(path: String) {
val uri = Uri.parse(path)
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.putExtra(Intent.EXTRA_STREAM, uri)
shareIntent.type = "*/*"
startActivity(Intent.createChooser(shareIntent, "Choose"))
}
When I run this code, I choose app to share and then I see toast "unsupported attachment"
I had similar problems with this and I found this article where it recommends us to use FileProvider.
What it does is :
FileProvider is a special subclass of ContentProvider that facilitates secure sharing of files associated with an app by creating a content:// Uri for a file instead of a file:/// Uri.
I recommend you to take a look to the article and also if you want code, take a look at this Stackoverflow post
i think you can use the file as ExtrtaStream the following code is sharing image file you can change it to your json file
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
final File photoFile = new File(getFilesDir(), "foo.jpg");//change it with your file
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
startActivity(Intent.createChooser(shareIntent, "Share image using"));

When trying to open a file with Intent getting 'Media not found' error

I download a file and save it as a temporary file using
File outputDir = context.getCacheDir();
File f = File.createTempFile(FILE_TYPE_PREFIX, "." + extension,outputDir);
f.exists() says that the file exists and as well I set f.setReadable(true, false); to be able to read it.
The I start a new Intent
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(f), mimeType);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
the f returns
/data/user/0/com.app.name/cache/PP_278545395.png
and after Uri.fromFile()
file:///data/user/0/com.app.name/cache/PP_278545395.png
As I try to open the file, it opens the Gallery but tells me "Media not found".
Any ideas why this issue exists?
getCacheDir() is part of internal storage for your app. Other apps do not have access to it. Use FileProvider to publish that content to other apps.

Categories