public class NotificationHook {
private static final String TAG = "NotificationHook";
public static void hook(XC_LoadPackage.LoadPackageParam lpparam) {
Log.e(TAG, "NotificationHook start");
try {
final Class clazz = XposedHelpers.findClass("android.app.NotificationManager", lpparam.classLoader);
XposedHelpers.findAndHookMethod(clazz, "notify", String.class, int.class, Notification.class, new XC_MethodHook() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Log.e(TAG, "MethodHookParam:" + param.toString());
Object[] args = param.args;
Notification notification = (Notification) param.args[2];
Log.e(TAG, "notification:" + notification.toString());
CharSequence tickerText = notification.tickerText;
Log.e(TAG, "notification.tickerText:" + tickerText);
//获得包名 wx的contentView ==null
// String aPackage = notification.contentView.getPackage();
// Log.e(TAG,"notification.contentView.getPackage:"+aPackage);
Bundle extras = notification.extras;
String title = (String) extras.get("android.title");
String text = (String) extras.get("android.text");
Log.e(TAG, "notification.extras:title=" + title + " text:" + text);
param.setResult(null);
super.beforeHookedMethod(param);
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
}
});
} catch (Throwable e) {
Log.e(TAG, "hook: ", e);
}
Log.e(TAG, "NotificationHook end");
}
}
如图:接收到对应的消息,但是不会有通知栏提示。