我写了一个获取天气的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