I am working on an application where I need to open a pdf file on a device,
I really got code on the internet that is similar to most examples. But the fact is, I canβt open the file, and the control goes directly to the Exception part.
Here is the code below:
public class MyPDFDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button OpenPDF = (Button) findViewById(R.id.button); OpenPDF.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { File pdfFile = new File("/sdcard/Determine_RGB_Codes_With_Powerpoint [PDF Library].pdf"); if(pdfFile.exists()) { Uri path = Uri.fromFile(pdfFile); Intent pdfIntent = new Intent(Intent.ACTION_VIEW); pdfIntent.setDataAndType(path, "application/pdf"); pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(pdfIntent); } catch(ActivityNotFoundException e) { Toast.makeText(MyPDFDemo.this, "No Application available to view pdf", Toast.LENGTH_LONG).show(); } } } }); }
When I run this code: I used to view "There is no application to view pdf." Can I view a pdf file for someone.
android pdf
David Brown May 21 '11 at 5:54 am 2011-05-21 05:54
source share