【发布时间】:2012-08-17 13:50:53
【问题描述】:
我写了一个获取天气的android服务,AndroidManifest.xml是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.weather"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<service
android:name=".WeatherService"
android:exported="true" >
</service>
</application>
</manifest>
现在,我想让另一个 apk 启动这个服务:
Intent service = new Intent();
service.setClassName("com.my.weather", "com.my.weather.WeatherService");
context.bindService(service, weatherServiceConnection, Context.BIND_AUTO_CREATE);
我收到了错误消息:
E/AndroidRuntime(14068): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.test/com.my.test.MainActivity}: java.lang.SecurityException: Not allowed to bind to service Intent { cmp=com.my.weather/.WeatherService }
我该如何解决这个问题?
其他apk是使用Messenger方式与天气服务通信的。
================================================ ===================================
谢谢大家!
现在我修改我的天气服务的 AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.weather"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<service
android:name=".WeatherService"
android:exported="true"
android:process=":remote" >
<intent-filter>
<action android:name="com.my.weather.WeatherService"></action>
</intent-filter>
</service>
</application>
</manifest>
而我就是用这个方法开始的:
Intent service = new Intent("com.my.weather.WeatherService");
context.bindService(service, weatherServiceConnection, Context.BIND_AUTO_CREATE);
然后我收到警告信息:
W/ActivityManager(131): Unable to start service Intent { act=com.my.weather.WeatherService }: not found
【问题讨论】:
-
看起来不错。您是否尝试过清理 WeatherService 项目并重新安装它?
-
亲爱的大卫,我清理、重建和重新安装时也是如此。