Hi All,

I am trying to make an application which can access the
MediaPlaybackService , so I have copied the IMediaPlaybackService.aidl
in my app's com.android.music path and tried to bind with the
MediaPlaybackService as below .


public class TestMusicPlaybackAppService extends Service {

    /* Description for playback service interface */
    IMediaPlaybackService mPlaybackService = null;

    public TestMusicPlaybackAppService() {
        System.out.println("TestMusicPlaybackAppService() constructor
call");
    }
          @Override
            public void onCreate() {
                super.onCreate();
                System.out.println("Service onCreate() call!");

                if (mPlaybackService == null) {
                    Intent i = new Intent();
        
i.setClassName("com.android.music","com.android.music.MediaPlaybackService");
                    System.out.println("Binding to MediaPlaybackService.");
                    bindService(i, connection, Context.BIND_AUTO_CREATE);
                }

            }


        @Override
        public IBinder onBind(Intent arg0) {
                // TODO Auto-generated method stub
                return null;
        }

         // Create ServiceConnection to existing MediaPlaybackService
        ServiceConnection connection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name, IBinder
service) {
            mPlaybackService =
IMediaPlaybackService.Stub.asInterface(service);
           System.out.println("MediaPlaybackService is connected!");

           try {
                        System.out.println("Album Id: 
"+mPlaybackService.getAlbumId());
                        System.out.println("Album 
Name:"+mPlaybackService.getAlbumName());
                        System.out.println("Artist
Name:"+mPlaybackService.getArtistName());
                        
System.out.println("IsPlaying:"+mPlaybackService.isPlaying());
                } catch (RemoteException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            mPlaybackService = null;
            System.out.println("MediaPlaybackService is
disconnected!");

        }
    };


}

But this code is generating securtiy exception "Not allowed to bind to
service Intent { cmp=com.android.music/.MediaPlaybackService }"


12-16 19:51:58.018: ERROR/AndroidRuntime(1846): FATAL EXCEPTION: main
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):
java.lang.RuntimeException: Unable to create service
com.android.samsung.TestMusicPlaybackApp.TestMusicPlaybackAppService:
java.lang.SecurityException: Not allowed to bind to service Intent
{ cmp=com.android.music/.MediaPlaybackService }
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
android.app.ActivityThread.handleCreateService(ActivityThread.java:
1930)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
android.app.ActivityThread.access$2500(ActivityThread.java:117)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:982)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
android.os.Handler.dispatchMessage(Handler.java:99)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
android.os.Looper.loop(Looper.java:123)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
android.app.ActivityThread.main(ActivityThread.java:3644)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
java.lang.reflect.Method.invokeNative(Native Method)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
java.lang.reflect.Method.invoke(Method.java:507)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:849)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
dalvik.system.NativeStart.main(Native Method)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846): Caused by:
java.lang.SecurityException: Not allowed to bind to service Intent
{ cmp=com.android.music/.MediaPlaybackService }
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
android.app.ContextImpl.bindService(ContextImpl.java:875)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
android.content.ContextWrapper.bindService(ContextWrapper.java:347)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
com.android.samsung.TestMusicPlaybackApp.TestMusicPlaybackAppService.onCreate(TestMusicPlaybackAppService.java:
31)
12-16 19:51:58.018: ERROR/AndroidRuntime(1846):     at
android.app.ActivityThread.handleCreateService(ActivityThread.java:
1920)

Could some one tell me what is missing in my code ? Should I need to
add any permission tag in the manifest file ?

Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to