Die Erlaubnis in der service-Aufruf aus einer anderen app

Mögliche Duplikate:

Ich habe zwei Anwendungen sagen die App "A" sowie die App "B". App hat ein service mit benutzerdefinierte Berechtigung und App B aufrufen möchte, service. Folgendes ist mein code-snippet

App Ein:: Manifest-Datei

  <service
            android:name="SendService"
            android:permission="android.permission.MyService">
            <intent-filter>
                <action android:name="com.example.calledactivity.MyServiceCaller" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:scheme="sms" />
                <data android:scheme="smsto" />
            </intent-filter>
        </service>

Hier habe ich gesichert mein service mit Erlaubnis android.die Genehmigung.MyService

in App B
Manifest-Datei haben folgende Berechtigung

<uses-permission android:name="android.permission.MyService"
    android:description="@string/app_name"
    android:label="@string/menu_settings" />

Und schließlich zu nennen der Service der App, ich benutze folgenden code in App B

Intent i = new Intent("com.example.calledactivity.MyServiceCaller", Uri.parse("sms:2223333"));
                    getApplicationContext().startService(i);

Wenn ich dieses Beispiel bin ich immer SecurityException mit folgenden stack trace

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 

Habe ich bereits schon viele von den threads erwähnt, aber keiner von Ihnen waren in der Lage, mein problem zu lösen. Also, ich habe diese Frage wieder.

Dank

InformationsquelleAutor Sulabh Gupta | 2013-07-11

Schreibe einen Kommentar