0

I am developing an Android app, where I need to open my pdf file in a popup window. My code is:

ImageView brobutton=(ImageView)layout.findViewById(R.id.imageView3);
brobutton.setOnClickListener(new OnClickListener() {
                                                   }
});

I already have developed an app to open pdf in emulator with this code:

final String googleDocsUrl = "http://docs.google.com/viewer?url=";
WebView mWebView=new WebView(SubProducts.this);                                         mWebView.getSettings().setJavaScriptEnabled(true);
WebSettings webSettings = mWebView.getSettings();
webSettings.setPluginState(PluginState.ON);
mWebView.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url){                                                          
        view.loadUrl(image_urlpdf);
        return false; // then it is not handled by default action
    }
});
mWebView.loadUrl((googleDocsUrl + image_urlpdf));

under the onclick of button I need to open my pdf.Any one suggest me with good idea. Thanks in advance.

Pedro Gonzalez
  • 1,429
  • 2
  • 19
  • 30
Neeha
  • 727
  • 3
  • 9
  • 21

2 Answers2

1

You need to modify your app to open PDF. Either pass some flag using intents to alert that your app need to open popup for showing PDF.

Check this thread for how to show activity as dialog Android Activity as a dialog

Community
  • 1
  • 1
Sulabh Gupta
  • 642
  • 1
  • 7
  • 20
  • thanq sulabh gupta.passing intent from dialog is same as passing intent from class i.e., like intent intent=new Intent(Present.this,forward.class);startActivity(intent); – Neeha Apr 01 '13 at 14:03
  • Yes, You can use following code in your first app to call second app (which is opening PDF file) Intent intent = new Intent(getBaseContext(), SignoutActivity.class); intent.putExtra("isDialog", true); startActivity(intent) And in your second app which is showing PDF, you can get it like getIntent().getBooleanExtra("isDialog"); – Sulabh Gupta Apr 02 '13 at 03:46
  • @ sulabh Gupta..I have followed your code.but it is not opening in pop up.wats wrong??? – Neeha Apr 02 '13 at 05:14
  • @SHAIKAFEEZA : have you changed the activity style in manifest for showing dialog? like **** This theme is required to show activity as dialog. You can also set it from code file like **setTheme(android.R.style.Theme_Dialog);** I hope you have not overridden any other theme for that activity in code. – Sulabh Gupta Apr 02 '13 at 07:06
  • yes Sulabh Gupta i did that.It is not showing any thing.i.e.,just showing activity name.I did the "pdf regarding" code under onCreate but still not opening. – Neeha Apr 02 '13 at 07:12
  • Are you able to see blank dialog? If so, check your code to read PDF file. And you can remove activity name by using **requestWindowFeature(Window.FEATURE_NO_TITLE)** – Sulabh Gupta Apr 02 '13 at 07:16
  • thanq Sulabh Gupta.Iam using same code as posted in question to open pdf.And that code exactly works for me to open pdf with out dialog.plz have a look at that. – Neeha Apr 02 '13 at 07:22
0

You could load your PDF file in the custom dialog. Tutorial for creating the custom dialog - http://www.mkyong.com/android/android-custom-dialog-example/

naveen
  • 36
  • 3
  • thanq naveen.Ok with custo dialogue but how to open pdf under that?? – Neeha Apr 01 '13 at 12:23
  • As you mentioned in the question you are loading a PDF file in a webview, in the same way you could create a webview in the custom dialog and display the PDF. – naveen Apr 01 '13 at 12:27
  • can you provide me how to start pdf activity in dialog with example? – Neeha Apr 01 '13 at 14:31