I want to use MediaPlayback service (achieved in music app) in framework level, steps is:
added these codes in a java file (also add IMediaPlaybackService.aidl in the same directory) based in /frameworks/base/core/java/com/android:
private IMediaPlaybackService mMediaPlaybackService = null;
private boolean isServiceConn = false;
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
mMediaPlaybackService = IMediaPlaybackService.Stub.asInterface(service);
isServiceConn = true;
}
public void onServiceDisconnected(ComponentName className) {
}
};
public void funcXXX() {
...
if(isServiceConn == false) {
mContext.bindService(new intent("com.android.music.MediaPlaybackService"), mConnection, Context.BIND_AUTO_CREATE);
}
...
}
public void onClick(View v) {
try {
mMediaPlaybackService.prev();// play previous track
} catch(RemoteException ex) {
}
}
the service binded successfully and the value of mMediaPlaybackService is corrected, but when i click a button and execute the statement "mMediaPlaybackService.prev()", the progrem will crash, the logcat dump is:
E/AndroidRuntime( 259): java.lang.SecurityException: Binder invocation to an incorrect interface
E/AndroidRuntime( 259): at android.os.Parcel.readException(Parcel.java:1327)
E/AndroidRuntime( 259): at android.os.Parcel.readException(Parcel.java:1281)
E/AndroidRuntime( 259): at com.android.internal.widget.IMediaPlaybackService$Stub$Proxy.prev(IMediaPlaybackService.java:457.
Please suggest what could be going wrong here, and any help will be highly appreciated. It will be also helpful if you briefly explain how to use bindService or IPC.