title: Permission in calling service from another app
body: <p>Possible Duplicates:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/4967962/permission-for-services">Permission for services</a>, </li>
  <li><a href="https://stackoverflow.com/questions/11410718/permission-issue-while-starting-a-service-from-android">Permission issue while starting a service from android</a>,</li>
  <li><a href="https://stackoverflow.com/questions/10474134/exported-service-does-not-require-permission-what-does-it-mean">Exported service does not require permission: what does it mean?</a>, </li>
  <li><a href="https://stackoverflow.com/questions/15468567/not-allowed-to-start-service-intent-without-permission-sender-does-not-get-per">Not allowed to start service Intent without permission</a> etc</li>
  </ul>
  
  <p>I have two applications say App "A" and App "B". App A has one service with custom permission and App B wants to call that service. Following is my code snippet</p>
  
  <p><strong>App A:</strong>: Manifest File</p>
  
  <pre><code>  &lt;service
              android:name="SendService"
              android:permission="android.permission.MyService"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.example.calledactivity.MyServiceCaller" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
  
                  &lt;data android:scheme="sms" /&gt;
                  &lt;data android:scheme="smsto" /&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
  </code></pre>
  
  <p>Here i have secured my service using permission <strong>android.permission.MyService</strong></p>
  
  <p>in <strong>App B</strong>
  Manifest file have following permission </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.MyService"
      android:description="@string/app_name"
      android:label="@string/menu_settings" /&gt;
  </code></pre>
  
  <p>And finally to call Service of App A, i am using following code in App B</p>
  
  <pre><code>Intent i = new Intent("com.example.calledactivity.MyServiceCaller", Uri.parse("sms:2223333"));
                      getApplicationContext().startService(i);
  </code></pre>
  
  <p>When i run this sample i am getting SecurityException with following stack trace </p>
  
  <pre><code>12-05 23:35:41.526: W/dalvikvm(25730): threadid=1: thread exiting with uncaught exception (group=0x40d3cac8)
  12-05 23:35:41.526: W/ActivityManager(752): Permission Denial: Accessing service ComponentInfo{com.example.calledactivity/com.example.calledactivity.SendService} from pid=25730, uid=10159 requires android.permission.MyService
  12-05 23:35:41.536: E/AndroidRuntime(25730): FATAL EXCEPTION: main
  12-05 23:35:41.536: E/AndroidRuntime(25730): java.lang.SecurityException: Not allowed to start service Intent { act=com.example.calledactivity.MyServiceCaller dat=sms:xxxx } without permission android.permission.MyService
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at android.app.ContextImpl.startServiceAsUser(ContextImpl.java:1714)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at android.app.ContextImpl.startService(ContextImpl.java:1686)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at android.content.ContextWrapper.startService(ContextWrapper.java:457)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at com.example.callingactivity.MainActivity$1.onClick(MainActivity.java:29)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at android.view.View.performClick(View.java:4383)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at android.view.View$PerformClick.run(View.java:18097)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at android.os.Handler.handleCallback(Handler.java:725)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at android.os.Handler.dispatchMessage(Handler.java:92)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at android.os.Looper.loop(Looper.java:137)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at android.app.ActivityThread.main(ActivityThread.java:5279)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at java.lang.reflect.Method.invoke(Method.java:511)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
  12-05 23:35:41.536: E/AndroidRuntime(25730):    at dalvik.system.NativeStart.main(Native Method)
  12-05 23:35:41.556: D/InputDispatcher(752): Focused application set to: AppWindowToken{4231fa58 token=Token{4231df58 ActivityRecord{4231dce8 u0 com.sec.android.app.launcher/com.android.launcher2.Launcher}}}
  12-05 23:35:41.556: W/ActivityManager(752):   Force finishing activity com.example.callingactivity/.MainActivity
  12-05 23:35:41.576: W/ContextImpl(752): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1379 com.android.server.am.ActivityStack.startPausingLocked:1408 com.android.server.am.ActivityStack.finishActivityLocked:5920 com.android.server.am.ActivityStack.finishActivityLocked:5834 com.android.server.am.ActivityManagerService.handleAppCrashLocked:9529 
  </code></pre>
  
  <p>I have already gone through many of the threads mentioned above, but none of them were able to solve my problem. So, i have raised this question again. </p>
  
  <p>Thanks</p>