Android realize QQ grab red envelope plugin _android

Source: Internet
Author: User
Tags gettext int size

Also think of the new year, and then do not know the group to send a lot of red envelopes, so I will be in the online outage of a micro-letter Rob Red Envelopes code modified a bit, realize the QQ Rob Red envelopes! Can support Rob QQ spell luck red envelopes, ordinary red envelopes, password red envelopes, now no longer afraid of the 20 single speed people with me Rob red envelopes!
First look at the Test effect chart:
1. Grab QQ Password Red envelopes

Can see, as long as a red envelope, automatically fill out the password and send out, help you to grab the red envelope!
2. Rob QQ to spell luck red envelopes

Lucky Red envelopes are the same, as long as a red envelope, automatically help you get the red envelopes, is not very cool feeling?
3. Steal the red envelopes sent by QQ friends

As long as a friend or group of people to send a red envelope, it will be the first time you get a red envelope! So as long as within the group to open Plug-ins, grab a red envelope is always a miss! Good nonsense not to say much, also don't boast how much cow good, the following directly to everyone on the code:


The code in/*mainactivity is basically unchanged: */public class Mainactivity extends Appcompatactivity {private final Intent maccessibleintent
  = new Intent (settings.action_accessibility_settings);
  Private Button Switchplugin;  
    @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);  
    Setcontentview (R.layout.activity_main);
    Switchplugin = (Button) Findviewbyid (;
  Updateservicestatus ();
  /* * Open plugin button/public void onbuttonclicked (view view) {startactivity (maccessibleintent);}
    @Overrideprotected void Onresume () {super.onresume ();
  Updateservicestatus ();  
    } private void Updateservicestatus () {Boolean serviceenabled = false; Accessibilitymanager Accessibilitymanager = (accessibilitymanager) getsystemservice (Context.ACCESSIBILITY_SERVICE)
    ; List<accessibilityserviceinfo> accessibilityservices = Accessibilitymanager.getenabledaccessibilityservicelist (accessibilityserviceinfo.feedbAck_generic); for (Accessibilityserviceinfo info:accessibilityservices) {if (Info.getid (). Equals (Getpackagename () + "/.     
        Qqhongbaoservice ")) {serviceenabled = true;    
       } if (serviceenabled) {switchplugin.settext ("close plugin");
     GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);  
       else {switchplugin.settext ("open plugin");
   GetWindow (). Clearflags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Here is the entire code in the mainactivity, is not very few appearance, mainly implements a button to open the Accessibility_service. This plug-in is mainly the use of Accessibilityservice this service to achieve. So the rest of the code is in this service!

public class Qqhongbaoservice extends Accessibilityservice {private static final String wechat_open_en = "OPEN";  
 private static final String wechat_opened_en = "You ' ve opened"; 
 Private final static String Qq_default_click_open = "click to disassemble";  
 Private final static String Qq_hong_bao_password = "password red envelope"; 
 Private final static String Qq_click_to_paste_password = "click enter Password";  
 Private Boolean mluckymoneyreceived;  
 Private String lastfetchedhongbaoid = null;  
 Private long lastfetchedtime = 0;  
 private static final int max_cache_tolerance = 5000;  
 Private Accessibilitynodeinfo Rootnodeinfo;
 Private list<accessibilitynodeinfo> Mreceivenode; @TargetApi (build.version_codes. KitKat) public void recycle (Accessibilitynodeinfo info) {if (info.getchildcount () = = 0) {/* The function of the IF code is: Match " Click on the node that entered the password and click on this node "/If" (Info.gettext ()!=null&&info.gettext (). toString (). Equals (Qq_click_to_paste_ PASSWORD)) {info.getparent (). Performaction (Accessibilitynodeinfo.acTion_click); /* This if code is to match the Send button behind the text edit box and click Send Password/if (Info.getclassname (). toString (). Equals ("Android.widget.Button")      
    ;& Info.gettext (). toString (). Equals ("send")) {info.performaction (Accessibilitynodeinfo.action_click); } else {for (int i = 0; i < Info.getchildcount (); i++) {if (Info.getchild (i)!= n       
      ull) {Recycle (Info.getchild (i)); @TargetApi}}} (Build.version_codes. Jelly_bean) @Override public void Onaccessibilityevent (Accessibilityevent event) {This.rootnodeinfo = Event.g    
  Etsource ();   
   if (Rootnodeinfo = = null) {return;   
  } Mreceivenode = null;    
  Checknodeinfo (); /* If a red envelope has been received and has not been poked open/if (mluckymoneyreceived && (mreceivenode!= null)) {int size = Mreceivenode.     
    Size ();        
if (Size > 0) {String id = gethongbaotext (mreceivenode.get (size-1));      Long now = System.currenttimemillis ();       
      if (This.shouldreturn (ID, now-lastfetchedtime)) return;        
      lastfetchedhongbaoid = ID;        
      Lastfetchedtime = Now;         
      Accessibilitynodeinfo Cellnode = Mreceivenode.get (size-1);        
      if (Cellnode.gettext (). toString (). Equals ("Password red envelopes are taken apart")) {return;      
      } cellnode.getparent (). Performaction (Accessibilitynodeinfo.action_click); if (Cellnode.gettext (). toString (). Equals (Qq_hong_bao_password)) {Accessibilitynodeinfo Rownode = getrootinactive         
      Window ();           
       if (Rownode = = null) {LOG.E (TAG, "Noteinfo is null");          
      else {recycle (rownode);      
     } mluckymoneyreceived = false;  
  }} private void Checknodeinfo () {if (Rootnodeinfo = = null) {return; }/* Chat session window, traversing sectionPoint Match "Click to disassemble", "Password red envelope", "Click Input Password" * * list<accessibilitynodeinfo> nodes1 = this.findaccessibilitynodeinfosbytexts (  
  This.rootnodeinfo, New String[]{qq_default_click_open, Qq_hong_bao_password, Qq_click_to_paste_password, "send"});    
    if (!nodes1.isempty ()) {String nodeId = integer.tohexstring (System.identityhashcode (this.rootnodeinfo));     
    if (!nodeid.equals (lastfetchedhongbaoid)) {mluckymoneyreceived = true;   
     Mreceivenode = nodes1;  
   } return; 
   The private string Gethongbaotext (Accessibilitynodeinfo node) {/* Gets the text on the red envelope */string content;    
     try {accessibilitynodeinfo i = node.getparent (). Getchild (0); 
     Content = I.gettext (). toString ();  
       catch (NullPointerException NPE) {return null;
  } return content;  
   Private Boolean Shouldreturn (String ID, long duration) {//id is empty if (id = null) return true; Name and Cache inconsistency if (Duration < max_cache_tolerance && ID.Equals (lastfetchedhongbaoid)) {return true;
  return false; Private list<accessibilitynodeinfo> findaccessibilitynodeinfosbytexts (Accessibilitynodeinfo nodeInfo,   
      String[] Texts {for (String text:texts) {if (text = = null) continue;  
      list<accessibilitynodeinfo> nodes = nodeinfo.findaccessibilitynodeinfosbytext (text); if (!nodes.isempty ()) {if (Text.equals (wechat_open_en) &&!nodeinfo.findaccessibilitynodeinfosbytext (    
        wechat_opened_en). IsEmpty ()) {continue;   
      return nodes;
  Return to New arraylist<> ();
 @Override public void Oninterrupt () {}}

Qqhongbaoservice's entire code is also here, the code is not much. First of all, in this service is mainly through Findaccessibilitynodeinfosbytext this method to obtain the node we need, and then with Performaction (accessibilitynodeinfo.action_ Click this method to hit the red envelope node, the key idea is probably so! In addition, if it is password red envelopes, we need to follow the steps above to stamp the red envelopes, and then through Performaction (Accessibilitynodeinfo.action_click) to click the input password, and finally click to send to achieve! Qqhongbaoservice need to be registered in the Androidmanifest.xml file,
Registered <application> nodes are shown below:

Overall, just the micro-letter to rob the red envelopes of the code to do a small amount of modification, here to thank you for your great god of micro-letter Rob Red Envelopes The contribution of the source code! Finally, I hope this article can be helpful to everyone, in the fight against red envelopes in the death of a single dog, no longer afraid of your 20 years of single skill speed!!!

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.