不允许启动服务意向未经许可 - 发送者并没有得到权限 [英] Not allowed to start service Intent without permission - sender does not get permissions

查看:150
本文介绍了不允许启动服务意向未经许可 - 发送者并没有得到权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与马克·墨菲的出色Commonsware书的工作 - 但它的很多消化。我建了FakePlayer应用程序(pretends是一个MP3播放器)。它包含一个服务。作为一个学习的经验,我试着写一个简单的应用程序(只有一个按钮),它的点击处理程序:

 意向书I =新意图();
i.setAction(com.example.cwfakeplayer.MyPlayerService);
上下文的背景下= getApplicationContext();
context.startService(ⅰ);

它工作得很好 - 服务开始OK。我发现Eclipse的抱怨在服务上无权,所以我加入2线,Android的更新服务的清单:权限和android:出口:

 <服务
        机器人:名字=MyPlayerService
        机器人:权限=com.example.fakeplayer.permission.MY_PLAYER_PERMISSION
        机器人:出口=真
       &所述;意图滤光器>
            <作用机器人:名字=com.example.fakeplayer.MyPlayerService>< /作用>
       &所述; /意图滤光器>
      < /服务>

我重装播放器应用到设备上(我使用的Galaxy S2)采用调试下蚀。它似乎工作;起动应用引起了许可例外,我的预期。

我然后添加到启动应用程序的清单(给它的权限):

 <清单
  ...
  <采用-SDK ....
  ....
  <使用许可权的android:NAME =com.example.fakeplayer.permission.MY_PLAYER_PERMISSION/>

我重载起动器应用到设备上(使用Eclipse下调试)。仍然得到权限错误在启动应用程序。

我删除从设备这两个应用并重新安装(使用调试...),服务应用程序,然后再起动。仍然得到烫发的错误。

我通过墨菲先生的高级Android的书如何使用远程服务部分工作我的方式,让我意识到这也许不是跨应用工作的最佳途径。

我做了一个亚行外壳dumpsys包',位于启动应用程序,并发现它有'permissionsFixed =假',没有'grantedPermissions部分。我认为这意味着在启动应用程序清单的变化没能拿到添加到应用程序的烫发。但我不知道为什么。作为一个学习的经验,它仅生成混乱到目前为止....

任何线索大大AP preciated!谢谢!


解决方案

  权限和android:

我加入2线,Android的更新服务的清单导出


从技术上说,的android:出口=真正的是多余的,因为具有<意向滤光器> 自动使<服务方式> 导出


  

我删除从设备这两个应用并重新安装(使用调试...),服务应用程序,然后再起动。仍然得到烫发的错误。


您不显示在那里你曾经宣布与&LT的自定义权限;许可> 元素。在实践中,如果您可以控制​​应用程序,把同样的<许可方式> 元素既体现,所以安装的两个应用程序不再是问题的顺序

I'm working with Mark Murphy's excellent Commonsware books - but it's a lot to digest. I built the 'FakePlayer' app (pretends to be an mp3 player). It contains a service. As a learning experience I tried to write a trivial app (has only a button) whose click handler does:

Intent i = new Intent();
i.setAction("com.example.cwfakeplayer.MyPlayerService");
Context context = getApplicationContext();
context.startService(i);

It worked fine - the service start ok. I noticed Eclipse complaining about no permission on the service, so I updated the service's manifest by adding 2 lines, android:permissions and android:exported:

    <service 
        android:name="MyPlayerService"
        android:permission="com.example.fakeplayer.permission.MY_PLAYER_PERMISSION"
        android:exported="true"
       <intent-filter>
            <action android:name="com.example.fakeplayer.MyPlayerService"></action>
       </intent-filter>
      </service>

I reloaded the player app onto the device (I'm using a Galaxy S2) using 'debug' under eclipse. It seemed to work; the starter app caused a permission exception, which I expected.

I then added to the starter app's manifest (to give it the permission):

<manifest
  ...
  <uses-sdk ....
  ....
  <uses-permission android:name="com.example.fakeplayer.permission.MY_PLAYER_PERMISSION" />

I reloaded the starter app onto the device (using debug under Eclipse). Still get the permission error in the starter app.

I removed both apps from the device and reinstalled (using debug...), service app first, then starter. Still get perm error.

I am working my way through the 'how to use a remote service' section of Mr. Murphy's Advanced Android book, so I realized this is not the best way perhaps to work across apps.

I did a 'adb shell dumpsys package', located the starter app, and found it had 'permissionsFixed=false' and no 'grantedPermissions' section. I take this to mean the manifest change in the starter app did not manage to get the perm added to the app. But I have no idea why. As a learning experience, it's generated only confusion so far....

Any clues greatly appreciated! Thanks!

解决方案

I updated the service's manifest by adding 2 lines, android:permissions and android:exported

Technically, android:exported="true" is superfluous, as having the <intent-filter> automatically makes the <service> be exported.

I removed both apps from the device and reinstalled (using debug...), service app first, then starter. Still get perm error.

You do not show where you ever declare the custom permission with the <permission> element. In practice, if you control both apps, put the same <permission> element in both manifests, so the order of installation of your two apps no longer matters.

这篇关于不允许启动服务意向未经许可 - 发送者并没有得到权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆