• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

how to open pdf in android

Hi All,

I am very new to android application. Developing one application where I want to open pdf on button click. I am running my application on emulator also on android phone. Could anybody guide me on this? how to achieve this functionality in detail?

After searching on google, It seems that we need to create raw folder.

Here is the code from the activity class which gets called after button click:

File file = new File("android.resource://com.example.hellogridview/raw/test.pdf");
if (file.exists()) {
Uri targetUri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/pdf");
try {
Toast.makeText(FullImageActivity.this, "in try testing more", Toast.LENGTH_SHORT).show();
startActivity(intent);

}
catch (ActivityNotFoundException e) {
Toast.makeText(FullImageActivity.this, "in catchtesting more", Toast.LENGTH_SHORT).show();
Toast.makeText(FullImageActivity.this, "No Application Available to View PDF", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(FullImageActivity.this, "file not found", Toast.LENGTH_SHORT).show();
}



Could anybody let me know where I should create the raw folder? or if anybody could provide me the sample application which is running successful will be highly appricated. Thanks in Advance.
 
Welcome to the forums chandanmahajan!! Sorry, I personally cant help you with your question, just wanted to welcome you aboard!! We do have a pretty good search function, maybe give that a try?
 
Hi All,

I am very new to android application. Developing one application where I want to open pdf on button click. I am running my application on emulator also on android phone. Could anybody guide me on this? how to achieve this functionality in detail?

After searching on google, It seems that we need to create raw folder.

Here is the code from the activity class which gets called after button click:

File file = new File("android.resource://com.example.hellogridview/raw/test.pdf");
if (file.exists()) {
Uri targetUri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/pdf");
try {
Toast.makeText(FullImageActivity.this, "in try testing more", Toast.LENGTH_SHORT).show();
startActivity(intent);

}
catch (ActivityNotFoundException e) {
Toast.makeText(FullImageActivity.this, "in catchtesting more", Toast.LENGTH_SHORT).show();
Toast.makeText(FullImageActivity.this, "No Application Available to View PDF", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(FullImageActivity.this, "file not found", Toast.LENGTH_SHORT).show();
}



Could anybody let me know where I should create the raw folder? or if anybody could provide me the sample application which is running successful will be highly appricated. Thanks in Advance.

Let me add my "welcome" to LilBit's, chandanmahajan.

That's quite a project, perhaps if you do search around as she suggests you'll land in the Development area here at Android Forums:

Android Development - Android Forums

.. a great place to post your query. :)
 
Back
Top Bottom