views:

49

answers:

1

I have a service MyService.java in Application "ServiceDemo". The manifest of this application looks like this

<?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> 

I have another application "CallerService" manifest looks like this

<?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> 

I have an activity from where I m trying to start the service on the click of the button

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

This fails to work. Says "unable to start service intent" May I know where I am going wrong.

A: 

and to my wonder, there comes this SecurityException: Not allowed to start service Intent without permission syh.permission.STARTMYSERVICE while it has been explicitly granted!!

Sheikh Aman