Loading

Tuesday, August 2, 2011

View PDF file by starting activity with intent of ACTION_VIEW

By starting activity with intent of ACTION_VIEW, for "application/pdf", we can ask the installed PDF ready to open PDF file from our app.

View PDF file by starting activity with intent of ACTION_VIEW

package com.exercise.AndroidReadPDF;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class AndroidReadPDFActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

String path = "/sdcard/AndroidUsersGuide-2.3.4.pdf";
File targetFile = new File(path);
Uri targetUri = Uri.fromFile(targetFile);

Intent intent;
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/pdf");

startActivity(intent);
}
}

SHARE TWEET

Thank you for reading this article View PDF file by starting activity with intent of ACTION_VIEW With URL http://x-tutorials.blogspot.com/2011/08/view-pdf-file-by-starting-activity-with.html. Also a time to read the other articles.

0 comments:

Write your comment for this article View PDF file by starting activity with intent of ACTION_VIEW above!