Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. protected void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3. setContentView(R.layout.activity_main);
  4.  
  5. File fileBrochure = new File("/sdcard/fleetman.pdf");
  6. if (!fileBrochure.exists())
  7. {
  8. CopyAssetsbrochure();
  9. }
  10.  
  11. /** PDF reader code */
  12. File file = new File("/sdcard/fleetman.pdf");
  13.  
  14. Intent intent = new Intent(Intent.ACTION_VIEW);
  15. intent.setDataAndType(Uri.fromFile(file),"application/pdf");
  16. intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  17. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  18. try
  19. {
  20. getApplicationContext().startActivity(intent);
  21. }
  22. catch (ActivityNotFoundException e)
  23. {
  24. Toast.makeText(MainActivity.this, "NO Pdf Viewer", Toast.LENGTH_SHORT).show();
  25. }
  26. }
  27.  
  28. //method to write the PDFs file to sd card
  29. private void CopyAssetsbrochure() {
  30. AssetManager assetManager = getAssets();
  31. String[] files = null;
  32. try
  33. {
  34. files = assetManager.list("");
  35. }
  36. catch (IOException e)
  37. {
  38. Log.e("tag", e.getMessage());
  39. }
  40. for(int i=0; i<files.length; i++)
  41. {
  42. String fStr = files[i];
  43. if(fStr.equalsIgnoreCase("fleetman.pdf"))
  44. {
  45. InputStream in = null;
  46. OutputStream out = null;
  47. try
  48. {
  49. in = assetManager.open(files[i]);
  50. out = new FileOutputStream("/sdcard/" + files[i]);
  51. copyFile(in, out);
  52. in.close();
  53. in = null;
  54. out.flush();
  55. out.close();
  56. out = null;
  57. break;
  58. }
  59. catch(Exception e)
  60. {
  61. Log.e("tag", e.getMessage());
  62. }
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement