当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How to see PDF content on same view (layout)

问题描述:

I am able to read pdf file, but I have one problem

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button OpenPDF = (Button) findViewById(R.id.button);

OpenPDF.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v)

{

File pdfFile = new File("/sdcard/Test.pdf");

if(pdfFile.exists())

{

Uri path = Uri.fromFile(pdfFile);

Intent pdfIntent = new Intent(Intent.ACTION_VIEW);

pdfIntent.setDataAndType(path, "application/pdf");

pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

try

{

startActivity(pdfIntent);

}

catch(ActivityNotFoundException e)

{

Toast.makeText(PDFTest.this, "No Application available to view pdf", Toast.LENGTH_LONG).show();

}

}

}

});

}

Am using the above code, when I click Button it takes me to another view where PDF content is visible. I dont want to use two activities. But I want to see the pdf content on same view. How to do that. How to stop navigating to next view.

My XML file is:

`<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

<Button android:text="Button"

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

</Button>

</LinearLayout>

`

Can anyone help me on this context.

网友答案:

You need to use a Library not an Intent. Try the open source library muPDF

分享给朋友:
您可能感兴趣的文章:
随机阅读: