Issue
I have implemented the android daydream service in which I have played a video from asserts , I have put a button there and onclick listener I want to open a webview with a link, every things goes right but I can't able to deal with the webview as when I clicks the button this message appear
Unfortunatley App has stopped
and the error message that appears in log is
AndroidRuntime(827): FATAL EXCEPTION: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity con text requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
I have created the webview in the xml file
my code for calling webview is:
final WebView webView = (WebView)this.findViewById(R.id.webView1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
vv.stopPlayback();
vv.setVisibility(View.GONE);//for media player
webView.setVisibility(View.VISIBLE);
webView.loadUrl("http://www.google.com");
}
});
Solution
After a lot of search i found answer of my question here is the link that helps me most
basically i just put this class code in my android dreamservice
private class LinkLauncher extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
return true;
}
and uses the webview as follow
WebView webview = (WebView) findViewById(R.id.webView1);
webview.setVisibility(View.VISIBLE);
webview.setWebViewClient(new LinkLauncher());
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.loadUrl("http://www.google.com");
i write answer that might help anyone else. thanks
Answered By - Tahir Mehmood
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.