Professional Documents
Culture Documents
Package Import Import Import Import Import Import Import Import Import Import Import Import Public Class Extends
Package Import Import Import Import Import Import Import Import Import Import Import Import Public Class Extends
pdfreader;
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.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.example.mahmod.pdfreader.R;
public class MainActivity extends Activity {
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button.setOnClickListener(new OnClickListener() {
@Override
try {
if (pdfFile.exists()) {
objIntent.setDataAndType(path, "VBCodes.pdf");
objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objIntent);
} else {
Toast.makeText(MainActivity.this, "File NotFound",
Toast.LENGTH_SHORT).show();
} catch (ActivityNotFoundException e) {
Toast.makeText(MainActivity.this,
.show();
} catch (Exception e) {
e.printStackTrace();
});
XML Code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="124dp"
android:textColor="@android:color/black"
android:textSize="20sp" />
<Button
android:id="@+id/bPressMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
</RelativeLayout>