java.lang.SecurityException异常:不允许启动服务意向 [英] java.lang.SecurityException: Not allowed to start service Intent
问题描述
嘿所有安装我的应用程序到模拟器时,我得到这样的:
ERROR / AndroidRuntime(465):了java.lang.RuntimeException:无法启动接收com.myPackage.Widget.MYWidget:java.lang.SecurityException异常:不允许启动服务意向{CMP = com.myPackage / .Widget。进myWidget $ MyWidgetService}未经许可android.permission.BIND_REMOTEVIEWS
块引用>下面是从我的清单中的code
<! - 广播接收器将处理AppWidget更新 - >
<接收机器人:Widget.MYWidgetNAME =机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.appwidget.action.APPWIDGET_UPDATE/> <! - 广播接收器,也将处理我们的自我创建的动作 - >
<作用机器人:名字=com.temp.package.Widget.MYWidget.ACTION_WIDGET_LEFT_RECEIVER/>
<作用机器人:名字=com.temp.package.Widget.MYWidget.ACTION_WIDGET_PROGRESSBAR_RECEIVER/>
&所述; /意图滤光器>
<元数据机器人:名字=android.appwidget.provider
机器人:资源=@ XML / mywidget_widget_provider/> < /接收器>
<服务机器人。Widget.MYWidget $ MyWidgetServiceNAME =
机器人:权限=android.permission.BIND_REMOTEVIEWS
机器人:出口=真/>
<使用许可权
机器人:名字=android.permission.BIND_REMOTEVIEWS>< /使用许可权>这是我的code
公共类进myWidget扩展AppWidgetProvider {
@覆盖
公共无效的onUpdate(上下文的背景下,AppWidgetManager appWidgetManager,INT [] appWidgetIds){ 意图svcIntent =新意图(背景下,MyWidgetService.class); //svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
context.startService(svcIntent);
}公共静态类MyWidgetService延伸服务
{
@覆盖
公共无效调用onStart(意向意图,诠释startId)
{
super.onStart(意向,startId);
//更新窗口小部件
RemoteViews远程视窗= buildRemoteView(本); //推送更新主屏幕
pushUpdate(远程视窗) //没有更多的更新,因此停止服务和免费资源
stopSelf();
} 公共RemoteViews buildRemoteView(上下文的背景下)
{
RemoteViews remoteViews =新的RemoteViews(context.getPackageName(),R.layout.widget_layout); //做的东西
返回remoteViews;
} @覆盖
公共无效onConfigurationChanged(配置NEWCONFIG)
{
INT oldOrientation = this.getResources()getConfiguration()方向。; 如果(newConfig.orientation!= oldOrientation)
{
//更新窗口小部件
RemoteViews远程视窗= buildRemoteView(本); //推送更新主屏幕
pushUpdate(远程视窗)
}
} 私人无效pushUpdate(RemoteViews远程视窗)
{
组件名进myWidget =新的组件名(这一点,MyWidget.class);
AppWidgetManager经理= AppWidgetManager.getInstance(本);
manager.updateAppWidget(进myWidget,远程视窗)
} @覆盖
公众的IBinder onBind(意向为arg0)
{
// TODO自动生成方法存根
返回null;
}
}
解决方案摆脱
安卓权限=android.permission.BIND_REMOTEVIEWS
机器人:出口=真从
<服务与GT;
元素,既不这里需要。这应该清理你的问题。hey all when installing my app to the emulator I get this:
ERROR/AndroidRuntime(465): java.lang.RuntimeException: Unable to start receiver com.myPackage.Widget.MYWidget: java.lang.SecurityException: Not allowed to start service Intent { cmp=com.myPackage/.Widget.MYWidget$MyWidgetService } without permission android.permission.BIND_REMOTEVIEWS
here is the code from my manifest
<!-- Broadcast Receiver that will process AppWidget updates --> <receiver android:name=".Widget.MYWidget" android:label="@string/app_name"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <!--Broadcast Receiver that will also process our self created action --> <action android:name="com.temp.package.Widget.MYWidget.ACTION_WIDGET_LEFT_RECEIVER" /> <action android:name="com.temp.package.Widget.MYWidget.ACTION_WIDGET_PROGRESSBAR_RECEIVER" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/mywidget_widget_provider" /> </receiver> <service android:name=".Widget.MYWidget$MyWidgetService" android:permission="android.permission.BIND_REMOTEVIEWS" android:exported="true" /> <uses-permission android:name="android.permission.BIND_REMOTEVIEWS"></uses-permission>
this is my code
public class MyWidget extends AppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Intent svcIntent = new Intent(context, MyWidgetService.class); //svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME))); context.startService(svcIntent); } public static class MyWidgetService extends Service { @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); // Update the widget RemoteViews remoteView = buildRemoteView(this); // Push update to homescreen pushUpdate(remoteView); // No more updates so stop the service and free resources stopSelf(); } public RemoteViews buildRemoteView(Context context) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); //do stuff return remoteViews; } @Override public void onConfigurationChanged(Configuration newConfig) { int oldOrientation = this.getResources().getConfiguration().orientation; if(newConfig.orientation != oldOrientation) { // Update the widget RemoteViews remoteView = buildRemoteView(this); // Push update to homescreen pushUpdate(remoteView); } } private void pushUpdate(RemoteViews remoteView) { ComponentName myWidget = new ComponentName(this, MyWidget.class); AppWidgetManager manager = AppWidgetManager.getInstance(this); manager.updateAppWidget(myWidget, remoteView); } @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } }
解决方案Get rid of:
android:permission="android.permission.BIND_REMOTEVIEWS" android:exported="true"
from your
<service>
element, as neither are needed here. This should clear up your problem.这篇关于java.lang.SecurityException异常:不允许启动服务意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!