Jump to content
Android Forum - A Community For Android Users and Enthusiasts

How to pdf file on buttonclick


chandanmahajan
 Share

Recommended Posts

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

 
I always get file not found. 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.
 
 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...