在动态壁纸推出浏览器的意图 [英] launch browser intent in live wallpaper
问题描述
我想在 onTouchEvent
加载Android浏览器VIEW意图。基本上,我创建了一个动态壁纸,如果我点击它,然后我想打开浏览器中查看意图与指定的URI。
我曾尝试以下里面 onTouchEvent
开放的URI = Uri.parse(http://www.google.com);
意向意图=新意图(Intent.ACTION_VIEW,URI);
startActivity(意向);
但我收到以下错误:
android.util.AndroidRuntimeException:从外部调用startActivity()
一个Activitycontext需要FLAG_ACTIVITY_NEW_TASK标志。这真的是你想要的吗?
另一种方法是,我有创建一个活动及其的onCreate
方法中我尝试以下code:
公共无效的onCreate(捆绑冰柱){
super.onCreate(冰柱); 浏览器=新的WebView(本);
的setContentView(浏览器);
browser.loadUrl(http://commonsware.com);
}
和尝试按如下方式通过自定义的意图消息加载这个活动,但还是我收到了同样的错误。
意向意图=新意图(ACTION);
startActivity(意向);//在这里我没有用过背景下,作为同时建立动态壁纸我
//不知道这里获取上下文
我已经解决了这个问题,我自己用下面的code:
意向意图=新意图(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(android.net.Uri.parse(http://www.gmail.com));
startActivity(意向);
I am trying to load BROWSER VIEW intent in android within onTouchEvent
. Basically I have created a live wallpaper and if I click on it then I want to open BROWSER VIEW intent with a specified uri.
I have tried following code inside onTouchEvent
Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
but I am getting the following error:
android.util.AndroidRuntimeException: Calling startActivity() from outside of
an Activitycontext requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Another approach is that I have create one activity and inside its onCreate
method I tried following code:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
browser=new WebView(this);
setContentView(browser);
browser.loadUrl("http://commonsware.com");
}
and tried to load this activity via custom intent message as follows, but still I am getting the same error
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
I have solved the problem on my own with the following code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(android.net.Uri.parse("http://www.gmail.com"));
startActivity(intent);
这篇关于在动态壁纸推出浏览器的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!