I want to use a PDFViewer in my Android app. FirstActivity I load my PDF file into list view, this code is:
Public class MainActivity ActionBarActivity {Final StringBuffer sb = New StringBuffer () is extensively; Private list view mainlist view; Private array adapter & lt; String & gt; List adapter; String file path; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.fragment_main); MainListView = (ListView) findViewById (R.id.mainListView); Last Array List & lt; String & gt; List = New Arrestist & lt; String & gt; (); Last file storage = Environment .getExternalStorageDirectory (); File file = new file (storage, "/ folder /"); If (file.exists () & File.isDirectory ()) {for (string s: file.list ()) {sb.append (s + ""); List.addAll (Arrays.asList (s)); }} List Adapters = New Arrayadapter & lt; String & gt; (This, R. Late Splello, R.Id. Rotequestview, List); MainListView.setAdapter (listAdapter); MainListView.setOnItemClickListener (New OnItemClickListener) {Public Zero onItemClick (AdapterView & LT;? & Gt; arg0, see ARG1, integer ARG2, long arg3) {string filepath = new file ("/ folder /" + List.get (ARG2 ). GetAbsolutePath (); openPdfIntent (filepath);}}); } Private Zero openPdfIntent (String Path) {{Last intention intent = new intent (main activity.This, second activity class); Intent.putExtra (PdfViewerActivity.EXTRA_PDFFILENAME, path); StartActivity; } Hold (exception e) {e.printStackTrace (); }}}}
The secondActivity pdf file shows, but I have the error "file is not found", this code is:
public class SecondActivity extends PdfViewerActivity {@Override Public Zero onCreate (savedInstanceState) {// TODO auto-created method stub super.onCreate (savedInstanceState); } Public int gets preceded image resistor () {back RDRY qualified. Left_arrow; } Public int getNextPageImageResource () {Return R.drawable.right_arrow; } Public int getZoomInIgeageResource () {back R.drawable.zoom_in; } Public int getZoomOutImageResource () {back R.drawable.zoom_out; } Public int getPdfPasswordLayoutResource () {return R.layout.pdf_file_password; } Public int getPdfPageNumberResource () {Returns R.layout.dialog_pagenumber; } Get public int PdfPasswordEditField () {back to R.id.etPassword; } Public int getPdfPasswordOkButton () {Return R.id.btOK; } Public int getPdfPasswordExitButton () {back R.id.btExit; } Get public int PdfPageNumberEditField () {Return R.id.pagenum_edit; }}
How can I solve this problem?
After the
you use the following code in your task named openPdfIntent () using the built-in application from your device
Example:
Public Zero openPdfIntent (string filePath) {Ury Path = Uri.fromFile (filepath); Intended pdfIntent = new intent (Intent.ACTION_VIEW); PdfIntent.setDataAndType (path, "application / pdf"); PdfIntent.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP); Try {StartActivity (pdfIntent); } Catch (ActivityNotFoundException e) {UDF.getdialog ("You do not have an application for PDF viewer.", Activity); }}
No comments:
Post a Comment