Guest User

Untitled

a guest
Jan 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. package android.test;
  2.  
  3. import java.io.File;
  4.  
  5. import android.app.Activity;
  6. import android.content.ActivityNotFoundException;
  7. import android.content.Intent;
  8. import android.net.Uri;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.Toast;
  13.  
  14. public class TestActivity extends Activity {
  15. /** Called when the activity is first created. */
  16. @Override
  17.  
  18. public void onCreate(Bundle savedInstanceState) {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.main);
  21. Button button=(Button)findViewById(R.id.button1);
  22. button.setOnClickListener(new View.OnClickListener() {
  23.  
  24. @Override
  25. public void onClick(View v) {
  26. // TODO Auto-generated method stub
  27. File file=new File("/sdcard/bill.pdf");
  28. if(file.exists())
  29. {
  30. Uri path=Uri.fromFile(file);
  31. Intent intent=new Intent(Intent.ACTION_VIEW);
  32. intent.setDataAndType(path, "application/pdf");
  33.  
  34. try
  35. {
  36.  
  37. startActivity(intent);
  38. }
  39. catch(ActivityNotFoundException e)
  40. {
  41. Toast.makeText(TestActivity.this, "No software for PDF", Toast.LENGTH_SHORT).show();
  42. }
  43. }
  44. }
  45. });
  46. }
  47. }
Add Comment
Please, Sign In to add comment