我写获取天气的机器人服务和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