我正在尝试在Android的onTouchEvent
中加载浏览器视图意图。基本上,我已经创建了一个动态壁纸,如果我点击它,我想打开带有指定URI的浏览器视图意图。
我已经尝试使用以下代码:
Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
但是我遇到了以下错误:
android.util.AndroidRuntimeException: Calling startActivity() from outside of
an Activitycontext requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
另一种方法是我创建了一个活动,在其
onCreate
方法中,我尝试了以下代码:public void onCreate(Bundle icicle) {
super.onCreate(icicle);
browser=new WebView(this);
setContentView(browser);
browser.loadUrl("http://commonsware.com");
}
我尝试通过自定义意图消息加载此活动,如下所示,但仍然遇到相同的错误。
Intent intent = new Intent(ACTION);
startActivity(intent);
// over here I have not used context, as while creating live wallpaper I
// don't know here to get the context