java.lang.SecurityException异常:不允许启动服务意向

编程入门 行业动态 更新时间:2024-10-18 03:25:07
本文介绍了java.lang.SecurityException异常:不允许启动服务意向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嘿所有安装我的应用程序到模拟器时,我得到这样的:

  

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异常:不允许启动服务意向

本文发布于:2023-11-27 04:06:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636521.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不允许   意向   异常   java   lang

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!