本文主要是介绍Android 自动接听微信语音视频电话、抢红包源代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
这里写目录标题
- 1、创建Service 集成AccessibilityService
- 2、注册无障碍服务
- 3、注册 auto_control_service_config配置文件
- 4、调用前需要开启无障碍服务
1、创建Service 集成AccessibilityService
Service 的onAccessibilityEvent 中监听系统变化,过滤自己感兴趣的消息事件、没什么好说的,直接开始代码
public class AutoHelperServer extends AccessibilityService {public static final String TAG = "zyb";public static final String wechatPackageName = "com.tencent.mm";private boolean startDelay;private long lastExecTimeStamp;@Overrideprotected void onServiceConnected() {super.onServiceConnected();Log.i(TAG, "====建立服务链接====");}@Overridepublic void onAccessibilityEvent(AccessibilityEvent event) {int eventType = event.getEventType();Log.d(TAG, "eventType: " + eventType + "\t PackageName:" + event.getPackageName());Log.d(TAG, "&& event.getSource(): " + event.getSource());if ((eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED || eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) && event.getSource() != null && event.getPackageName() != null) {CharSequence packageName = event.getPackageName();Log.d(TAG, "packageName=: " + packageName);if (!wechatPackageName.equals(packageName)) {return;}if (this.startDelay && System.currentTimeMillis() - this.lastExecTimeStamp < 300L) {Log.d(TAG, "已经接听了没有比较再接听一次了 : " + packageName);return;}this.lastExecTimeStamp = System.currentTimeMillis();this.startDelay = false;CharSequence className = event.getClassName();if (className != null) {Log.d(TAG, "页面->: " + className);}autoConnectWeChatCall(event);} else if (eventType == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED && event.getPackageName() != null) {Log.d(TAG, "通知栏发生变化了...");Log.d(TAG, "eventType: " + eventType + "\t PackageName:" + event.getPackageName());CharSequence className = event.getClassName();if (className != null) {Log.d(TAG, "页面->: " + className);}if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) {if ("com.tencent.mm".equals(event.getPackageName())) {Notification notification = (Notification) event.getParcelableData();PendingIntent pendingIntent1 = notification.contentIntent;Log.d(TAG, "pendingIntent..." + pendingIntent1);try {if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {String title = notification.extras.getString(Notification.EXTRA_TITLE);
这篇关于Android 自动接听微信语音视频电话、抢红包源代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!