【发布时间】:2026-02-15 19:45:01
【问题描述】:
我正在尝试在onTouchEvent 内的android 中加载BROWSER VIEW 意图。基本上我已经创建了一个动态壁纸,如果我点击它然后我想用指定的 uri 打开 BROWSER VIEW 意图。
我在onTouchEvent中尝试了以下代码
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
【问题讨论】:
标签: android live-wallpaper wallpaper