mercredi 21 janvier 2015

How to invoke cancelAllNotifications(String) method (in android.app.INotificationManager) by reflect

I was trying to cancel target app's notifications on Android, then I read the source code and noticed it may have some trickies to do that. I tried to call this by reflection.



public abstract interface INotificationManager extends IInterface {

public abstract void cancelAllNotifications(String paramString) throws RemoteException;


but not worked well, keep throwing InvocationTargetException when the code run to the last line. I still don't get why. Could you give me some hints please ?


this is my code . Thanks a lot :)



mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

Method getServiceMethod = mNotificationManager.getClass().getMethod("getService");

Object iNotificationManagerObject = getServiceMethod.invoke(mNotificationManager, (Object[]) null);

Class iNotificationManager = Class.forName("android.app.INotificationManager");

Method cancelAllNotificationsMethod = iNotificationManager.getMethod("cancelAllNotifications", new Class[] { String.class});
cancelAllNotificationsMethod.invoke(iNotificationManagerObject, new Object[] { "com.reallyBadApp"});





Aucun commentaire:

Enregistrer un commentaire