Android实现微信自动抢红包的程序.docx
- 文档编号:14185615
- 上传时间:2023-06-21
- 格式:DOCX
- 页数:11
- 大小:17.12KB
Android实现微信自动抢红包的程序.docx
《Android实现微信自动抢红包的程序.docx》由会员分享,可在线阅读,更多相关《Android实现微信自动抢红包的程序.docx(11页珍藏版)》请在冰点文库上搜索。
Android实现微信自动抢红包的程序
Android实现微信自动抢红包的程序
简单实现了微信自动抢红包的服务,原理就是根据关键字找到相应的View,然后自动点击。
主要是用到AccessibilityService这个辅助服务,基本可以满足自动抢红包的功能,但是有些逻辑需要优化,比如,拆完一个红包后,必须手动点击返回键,才能进行下一次自动抢红包。
AndroidManifest.xml
xmlversion="1.0"encoding="utf-8"?
>
android=" package="com.jackie.webchatenvelope"> android: allowBackup="true" android: icon="@mipmap/ic_launcher" android: label="@string/app_name" android: theme="@style/AppTheme"> android: name=".MainActivity" android: label="@string/app_name"> name="android.intent.action.MAIN"/> name="android.intent.category.LAUNCHER"/> android: enabled="true" android: exported="true" android: label="@string/app_name" android: name=".EnvelopeService" android: permission="android.permission.BIND_ACCESSIBILITY_SERVICE"> name="android.accessibilityservice.AccessibilityService"/> android: name="android.accessibilityservice" android: resource="@xml/envelope_service_config"/> envelope_service_config.xml xmlversion="1.0"encoding="utf-8"? > android=" android: accessibilityEventTypes="typeNotificationStateChanged|typeWindowStateChanged" android: accessibilityFeedbackType="feedbackGeneric" android: accessibilityFlags="" android: canRetrieveWindowContent="true" android: description="@string/accessibility_description" android: notificationTimeout="100" android: packageNames="com.tencent.mm"/> activity_main.xml android=" xmlns: tools=" android: layout_width="match_parent" android: layout_height="match_parent" android: paddingBottom="@dimen/activity_vertical_margin" android: paddingLeft="@dimen/activity_horizontal_margin" android: paddingRight="@dimen/activity_horizontal_margin" android: paddingTop="@dimen/activity_vertical_margin" tools: context=".MainActivity"> * *抢红包外挂服务 */ publicclassEnvelopeServiceextendsAccessibilityService{ staticfinalStringTAG="Jackie"; /** *微信的包名 */ staticfinalStringWECHAT_PACKAGENAME="com.tencent.mm"; /** *红包消息的关键字 */ staticfinalStringENVELOPE_TEXT_KEY="[微信红包]"; Handlerhandler=newHandler(); @Override publicvoidonAccessibilityEvent(AccessibilityEventevent){ finalinteventType=event.getEventType(); Log.d(TAG,"事件---->"+event); //通知栏事件 if(eventType==AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED){ List if(! texts.isEmpty()){ for(CharSequencet: texts){ Stringtext=String.valueOf(t); if(text.contains(ENVELOPE_TEXT_KEY)){ openNotification(event); break; } } } }elseif(eventType==AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED){ openEnvelope(event); } } /*@Override protectedbooleanonKeyEvent(KeyEventevent){ //returnsuper.onKeyEvent(event); returntrue; }*/ @Override publicvoidonInterrupt(){ Toast.makeText(this,"中断抢红包服务",Toast.LENGTH_SHORT).show(); } @Override protectedvoidonServiceConnected(){ super.onServiceConnected(); Toast.makeText(this,"连接抢红包服务",Toast.LENGTH_SHORT).show(); } privatevoidsendNotificationEvent(){ AccessibilityManagermanager=(AccessibilityManager)getSystemService(ACCESSIBILITY_SERVICE); if(! manager.isEnabled()){ return; } AccessibilityEventevent=AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); event.setPackageName(WECHAT_PACKAGENAME); event.setClassName(Notification.class.getName()); CharSequencetickerText=ENVELOPE_TEXT_KEY; event.getText().add(tickerText); manager.sendAccessibilityEvent(event); } /** *打开通知栏消息 */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) privatevoidopenNotification(AccessibilityEventevent){ if(event.getParcelableData()==null||! (event.getParcelableData()instanceofNotification)){ return; } //以下是精华,将微信的通知栏消息打开 Notificationnotification=(Notification)event.getParcelableData(); PendingIntentpendingIntent=notification.contentIntent; try{ pendingIntent.send(); }catch(PendingIntent.CanceledExceptione){ e.printStackTrace(); } } @TargetApi(Build.VERSION_CODES.JELLY_BEAN) privatevoidopenEnvelope(AccessibilityEventevent){ if("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI".equals(event.getClassName())){ //点中了红包,下一步就是去拆红包 checkKey1(); }elseif("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI".equals(event.getClassName())){ //拆完红包后看详细的纪录界面 //nonething }elseif("com.tencent.mm.ui.LauncherUI".equals(event.getClassName())){ //在聊天界面,去点中红包 checkKey2(); } } @TargetApi(Build.VERSION_CODES.JELLY_BEAN) privatevoidcheckKey1(){ AccessibilityNodeInfonodeInfo=getRootInActiveWindow(); if(nodeInfo==null){ Log.w(TAG,"rootWindow为空"); return; } List for(AccessibilityNodeInfon: list){ n.performAction(AccessibilityNodeInfo.ACTION_CLICK); } } @TargetApi(Build.VERSION_CODES.JELLY_BEAN) privatevoidcheckKey2(){ AccessibilityNodeInfonodeInfo=getRootInActiveWindow(); if(nodeInfo==null){ Log.w(TAG,"rootWindow为空"); return; } List if(list.isEmpty()){ list=nodeInfo.findAccessibilityNodeInfosByText(ENVELOPE_TEXT_KEY); for(AccessibilityNodeInfon: list){ Log.i(TAG,"-->微信红包: "+n); n.performAction(AccessibilityNodeInfo.ACTION_CLICK); break; } }else{ //最新的红包领起 for(inti=list.size()-1;i>=0;i--){ AccessibilityNodeInfoparent=list.get(i).getParent(); Log.i(TAG,"-->领取红包: "+parent); if(parent! =null){ parent.performAction(AccessibilityNodeInfo.ACTION_CLICK); break; } } } } }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 实现 自动 红包 程序