Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Development

Reply
Highlighted
Regular Contributor
Posts: 83
Registered: ‎12-09-2010
My Device: Not Specified
Accepted Solution

Opening a PDF from android runtime application

[ Edited ]

HEllo,

I'm trying to open a PDF from my Android app on a BB10 Z10 phone (10.2.1).

It purpose me  to use "File Viewer"  with adobereader logo, but nothing happen when I click on it.

I've tried to put files on different storages and directory but I've got  the same problem with no errors :

 

Public storage

 

public static String getDefaultPath() {
		return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()+"/";
}

 And internal storage :

public static String getDefaultPath() {
		return context.getFilesDir().getAbsolutePath()+"/";
}

 

Here is my code to open the pdf, it works well on Android :

 

File file = new File(path);
if (file.exists()) {

	try {
		Toast.makeText(context, "Trying to open " +path+" => "+ file.getName(), Toast.LENGTH_LONG).show();

		Uri fileUri = Uri.fromFile(file);
		Intent i = new Intent(Intent.ACTION_VIEW);
		i.setData(fileUri);
		i.setType("application/pdf");
		 i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		context.startActivity(i);

	} catch (Exception e) {
		Logger.getInstance().LogException(e);
		Toast.makeText(context, "Unable to pen file..." + e.getMessage() + " " + e.getClass().getName(), Toast.LENGTH_LONG).show();

	}
} else {
	Toast.makeText(context, "File not found..." + file.getName(), Toast.LENGTH_LONG).show();

}

 

 

I can't see my device into DDMS, there is nothing, how can i debug to check if system return me an error when I try to open pdf ?

 

Thanks for you help !

Best,

Ricken

 

Regular Contributor
Posts: 83
Registered: ‎12-09-2010
My Device: Not Specified

Re: Opening a PDF from android runtime application

I've resolved my problem.

There was actually two problems, the first is that I must use public storage for adobereader being able to access my pdf file, so I solved it by copying pdf to public cache dir before openning it and then I can keep all others files protected.

 

The other problem is pretty strange and seems to be a bug, I've replaced  :

i.setData(fileUri);
i.setType("application/pdf");
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

 

with just :

i.setDataAndType(fileUri, "application/pdf");

 And now pdf is correctly  opened by adobereader Smiley Happy