Android 从按钮单击窗口小部件打开浏览器

Android 从按钮单击窗口小部件打开浏览器,android,android-widget,broadcastreceiver,Android,Android Widget,Broadcastreceiver,我试图通过点击小部件上的按钮打开浏览器。我使用了一个BroadcastReceiver,从onReceiver我想打开一个浏览器 我得到的错误如下: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? 如果启动活动并形成一个不可见的组件(如BroadcaseReceiver),则需要

我试图通过点击小部件上的按钮打开浏览器。我使用了一个BroadcastReceiver,从onReceiver我想打开一个浏览器

我得到的错误如下:

Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

如果启动活动并形成一个不可见的组件(如BroadcaseReceiver),则需要使用FLAG_activity_NEW_TASK FLAG。这就是错误所说的。这里有一个可能的解决办法

Intent intent = new Intent(<Your action here>);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
或者,您可以先显示通知。这只会在状态栏中显示一条消息,不会中断当前用户的活动,例如游戏。稍后,当用户有时间时,他或她可以单击此通知,然后浏览器将打开

希望这有帮助-->

Button1 = (Button) findViewById(R.id.b1);

String text ="Visit <a href=\"http://manning.com/\">Manning home page</a>";

Button1.setText(Html.fromHtml(text));
Button1.setMovementMethod(LinkMovementMethod.getInstance());

您是否在按钮上设置了PendingEvent?如果在活动中设置了PendingEvent,您的答案将有效,但它是一个使用AppWidgetProvider的小部件。
Button1 = (Button) findViewById(R.id.b1);

String text ="Visit <a href=\"http://manning.com/\">Manning home page</a>";

Button1.setText(Html.fromHtml(text));
Button1.setMovementMethod(LinkMovementMethod.getInstance());