通过xposed hook 类 android.app.NotificationManager 中的 notify 函数来获取消息通知栏的消息。
package com.example.hook_notificationmanager;
import android.app.Notification;
import android.os.Build;
import android.os.Bundle;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
import android.app.Notification;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
public class HookTest implements IXposedHookLoadPackage{
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable{
final Class clazz = XposedHelpers.findClass(
"android.app.NotificationManager", lpparam.classLoader
);
XposedBridge.log("Hook 测试0");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
XposedHelpers.findAndHookMethod(clazz, "notify", String.class, int.class, Notification.class,
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
XposedBridge.log("methodHookParam.args: " + Arrays.toString(param.args));
Notification a = (Notification) param.args[2];
// String aPackage = a.contentView.getPackage();
String title = "";
String text = "";
String url = "";
XposedBridge.log("Hook 测试");
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT){
XposedBridge.log("Hook 测试1");
XposedBridge.log("tickerText1: " + a.tickerText);
XposedBridge.log("title1: " + a.extras.get("android.title"));
XposedBridge.log("text1: " + a.extras.get("android.text"));
XposedBridge.log("object notification: " + a.toString());
}
}
});
}
}
}
参考连接:
https://www.jianshu.com/p/3cbda88bb1f9
https://www.jianshu.com/p/622737e9469f
https://blog.youkuaiyun.com/hardworkingant/article/details/78323073 # 原理