2010-07-28 130 views
0

我在应用程序“ServiceDemo”中有一个服务MyService.java。这个应用程序的清单看起来像这样如何执行远程服务

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.moto.dev" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".Sample" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <service android:enabled="true" 
       android:name=".MyService" 
       android:permission="syh.permission.STARTMYSERVICE"> 
     </service> 
     </application> 
     <permission 
     android:protectionLevel="normal" 
     android:label="Start My Receiver" 
     android:description="@string/startMyActivityDesc" 
     android:name="syh.permission.STARTMYSERVICE"> 
     </permission> 
    <uses-sdk android:minSdkVersion="8" /> 

</manifest> 

我有另一个应用程序“CallerService”清单看起来像这样

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.moto.dev" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".CallerService" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

    </application> 

    <uses-permission android:name="syh.permission.STARTMYSERVICE"></uses-permission> 
    <uses-sdk android:minSdkVersion="8" /> 

"src/com/moto/dev/Sample.java"</manifest> 

我从那里我米试图上的点击启动服务活动按钮

Intent intent = new Intent(); 
//path where my service is located in application "ServiceDemo" 
intent.setClassName("com.moto.dev","com.moto.dev.MyService"); 
startService(intent); 

这失败了。说“无法启动服务意图” 我可以知道我哪里出错了。

回答

0

和我的奇迹,出现这个SecurityException:不允许启动服务意图没有许可syh.permission.STARTMYSERVICE虽然它已被明确授予!

0

当你的服务没有意图过滤器,你将需要设置exported标志true在服务清单中

相关问题