Frequently Asked Question
How to handle link (url) annotation?
Last Updated 11 months ago
To open a link annotation (url), you need to implement the listener PDFLayoutListener and in the method OnPDFOpenURI, you can either open the system intent or a custom one...
To open using the system intent:
@Override public void OnPDFOpenURI(String uri) { try { Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse(uri); intent.setData(content_url); startActivity(intent); } catch(Exception e){ } }
To open using a custom intent:
@Override public void OnPDFOpenURI(String uri) { try { Intent intent = new Intent(this, WebViewAct.class); intent.putExtra("URL", uri); startActivity(intent); } catch(Exception e) { } }
WebViewAct:
public class WebViewAct extends Activity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); WebView mWebView = new WebView(this); mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); setContentView(mWebView); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl(getIntent().getStringExtra("URL")); } }