Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package android.test;
- import java.io.File;
- import android.app.Activity;
- import android.content.ActivityNotFoundException;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.Toast;
- public class TestActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button button=(Button)findViewById(R.id.button1);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- File file=new File("/sdcard/bill.pdf");
- if(file.exists())
- {
- Uri path=Uri.fromFile(file);
- Intent intent=new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(path, "application/pdf");
- try
- {
- startActivity(intent);
- }
- catch(ActivityNotFoundException e)
- {
- Toast.makeText(TestActivity.this, "No software for PDF", Toast.LENGTH_SHORT).show();
- }
- }
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment