Guest User

Untitled

a guest
Oct 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. public class FacturaActivity extends Activity {
  2.  
  3. (...)
  4.  
  5. public void downloadInvoice(View view) {
  6. File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename);
  7. Intent intent = new Intent(Intent.ACTION_VIEW);
  8. intent.setDataAndType(Uri.fromFile(file),"application/pdf");
  9. intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
  10. startActivity(intent);
  11. }
  12. }
  13.  
  14. <uses-permission android:name="android.permission.INTERNET" />
  15. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  16.  
  17. <uses-sdk
  18. android:minSdkVersion="8"
  19. android:targetSdkVersion="8" />
  20.  
  21. <application
  22. android:allowBackup="true"
  23. android:icon="@drawable/ic_launcher"
  24. android:label="@string/app_name"
  25. android:theme="@style/AppTheme"
  26. android:name="###.MyApplication" > <!--cant show complete name-->
  27. <activity
  28. android:name="###.MainActivity"
  29. android:label="@string/app_name" >
  30. <intent-filter>
  31. <action android:name="android.intent.action.MAIN" />
  32.  
  33. <category android:name="android.intent.category.LAUNCHER" />
  34. </intent-filter>
  35. </activity>
  36.  
  37. <activity
  38. android:name=".FacturaActivity" >
  39. </activity>
  40.  
  41. </application>
  42.  
  43. 07-03 15:49:13.094: E/AndroidRuntime(1032): FATAL EXCEPTION: main
  44. 07-03 15:49:13.094: E/AndroidRuntime(1032): java.lang.IllegalStateException: Could not execute method of the activity
  45. (...)
  46. 07-03 15:49:13.094: E/AndroidRuntime(1032): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/201209_F2012212782.PDF typ=application/pdf flg=0x40000000 }
  47. 07-03 15:49:13.094: E/AndroidRuntime(1032): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
  48. 07-03 15:49:13.094: E/AndroidRuntime(1032): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
  49. 07-03 15:49:13.094: E/AndroidRuntime(1032): at android.app.Activity.startActivityForResult(Activity.java:2817)
  50. 07-03 15:49:13.094: E/AndroidRuntime(1032): at android.app.Activity.startActivity(Activity.java:2923)
  51.  
  52. File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename);
  53. Intent target = new Intent(Intent.ACTION_VIEW);
  54. target.setDataAndType(Uri.fromFile(file),"application/pdf");
  55. target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
  56.  
  57. Intent intent = Intent.createChooser(target, "Open File");
  58. try {
  59. startActivity(intent);
  60. } catch (ActivityNotFoundException e) {
  61. // Instruct the user to install a PDF reader here, or something
  62. }
  63.  
  64. String dir="/Attendancesystem";
  65.  
  66. public void displaypdf() {
  67.  
  68. File file = null;
  69. file = new File(Environment.getExternalStorageDirectory()+dir+ "/sample.pdf");
  70. Toast.makeText(getApplicationContext(), file.toString() , Toast.LENGTH_LONG).show();
  71. if(file.exists()) {
  72. Intent target = new Intent(Intent.ACTION_VIEW);
  73. target.setDataAndType(Uri.fromFile(file), "application/pdf");
  74. target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
  75.  
  76. Intent intent = Intent.createChooser(target, "Open File");
  77. try {
  78. startActivity(intent);
  79. } catch (ActivityNotFoundException e) {
  80. // Instruct the user to install a PDF reader here, or something
  81. }
  82. }
  83. else
  84. Toast.makeText(getApplicationContext(), "File path is incorrect." , Toast.LENGTH_LONG).show();
  85. }
Add Comment
Please, Sign In to add comment