Android micro-Credit automatic grab Red Envelopes plug-in optimization and implementation _android

Source: Internet
Author: User

Another series of hobbies
There are many examples and codes of automatic strong red envelopes on the Internet, and the author also makes some optimizations.
Let's talk about your two strengths.
1. Can be in the chat interface automatically strong not dependent on the notification bar push
2. Can be in the screen when the time to light up the screen automatically rob (currently only measured flyme)
First figure:

Code Transfer Gate:
Https://github.com/AndroidMsky/WXhongbao
Welcome to the Stars.

Principle:

Through the Accessibilityservice Monitor to hear status bar notification, for analog clicks, get the View node in the screen to receive the Red envelope list and click the last one.
If you do not pass the status bar notification, the Accessibilityevent 2048 event is changed through the view

public static final int type_window_content_changed = 0x00000800;

Every time you receive a new message, you get a callback for that time:

public void Onaccessibilityevent (Accessibilityevent event) {
  int eventtype = Event.geteventtype ();
  if (auto)
   log.e ("aaaaaaaa", "event" + EventType);
  Switch (eventtype) {
   //when notification bar changes
   2048:
    pubclassname = Event.getclassname (). toString ();

    LOG.E ("Aaaaaaaa", "There are 2048 events" + Pubclassname + auto);

    if (!auto && pubclassname.equals ("Android.widget.TextView") && All) {
     log.e ("Aaaaaaaa", " There are 2048 events identified "+ Auto + pubclassname";
     Getlastpacket (1);
    }
    if (auto && wxmain) {
     getlastpacket ();
     Auto = false;
    }

    Break

So when you accept it, go and deal with it and click to receive a red envelope. However, this method will be called frequently, we will add a "Android.widget.TextView" event class filter, and then will be very frequent calls, will be more late performance power consumption.
Then add a Boolean all flag bit, let the user control whether the chat interface can also Rob Red envelopes mode.
In order not to repeatedly collect the number of red envelopes in the last interface when the red envelopes increase the time to collect:

private void Getlastpacket (int c) {

  log.e ("Aaaaaaaa", "New Method" + parents.size ());
  Accessibilitynodeinfo RootNode = Getrootinactivewindow ();
  Recycle (rootnode);
  LOG.E ("Aaaaaaaa", "last++" + lastbagnum + "Current page red envelope number" + parents.size ());
  if (parents.size () > 0 && wxmain) {
   log.e ("aaaaaaaa", "page is greater than O and in the Micro-Interface");
   if (Lastbagnum < Parents.size ())
    Parents.get (Parents.size ()-1). Performaction (Accessibilitynodeinfo.action_ CLICK);
   Lastbagnum = Parents.size ();
   Parents.clear ();
  }
 

At present, through the plug-in after a few red envelopes, a chat interface suddenly sent the first red envelopes (no notice bar) will have a certain probability to receive, and then continue to hair on the normal, should be empty problem, the bug author is also in the change logic.

Lighting the Screen method (with the password is certainly not possible):

private void WakeAndUnlock2 (Boolean b)
 {
  if (b)
  {
   //Get Power Manager Object
   pm= (PowerManager) Getsystemservice (context.power_service);

   Gets the Powermanager.wakelock object, followed by the parameter | To indicate that two values are passed in at the same time, and the last is the tag
   wl = Pm.newwakelock for debugging (Powermanager.acquire_causes_ WAKEUP | Powermanager.screen_bright_wake_lock, "BRIGHT");

   Light up the screen
   wl.acquire ();

   Get the keyboard lock manager Object
   km= (Keyguardmanager) Getsystemservice (context.keyguard_service);
   KL = Km.newkeyguardlock ("UnLock");

   Unlock
   kl.disablekeyguard ();
  }
  else
  {
   //Lock screen
   kl.reenablekeyguard ();

   Release Wakelock, turn off the light
   wl.release ();
  }

 

Receive a red envelope message on the notification bar set the flag to automatically pick up, pick up the function:

if (Content.contains ("[Micro-Red Envelopes]")) {
       if (event.getparcelabledata ()!= null &&
         event.getparcelabledata () instanceof Notification) {
        Notification Notification = (Notification) event.getparcelabledata ();
        Pendingintent pendingintent = notification.contentintent;
        try {
         auto = true;
         WakeAndUnlock2 (true);
         Pendingintent.send ();
         LOG.E ("Demo", "Enter micro-letter" + Auto + event.getclassname (). toString ());
        catch (Exception e) {
         e.printstacktrace ();}}}
      

Click on the interface control method:(different micro-version control ID is not the same as my 6.3.25) if you do not know how to obtain this ID can see the following reference to the last one, the right side of the Resource-id is this ID

Click ("Com.tencent.mm:id/bag");

To set up a chat pick switch in the activity:

public void Start (View v) {
  if (airaccessibilityservice.all) {
   airaccessibilityservice.all = false;
   ((button) v). SetText ("Monitor + Close in Dialog");
  } else {
   Airaccessibilityservice.all = true;
   ((button) v). SetText ("Monitor + Open in Dialog");
  }

 

Accessibilityservice is really a crane, you can use Accessibilityservice or root Android phone to do too much, or good or bad, but after all, the technology is not guilty.

At the same time, I also recommend my article:

Android phone changes to camera, automatically picks up QQ phone

Please pay attention to the author. Comments and discussions are welcome. Welcome to Pat Bricks. If you think this article is helpful to you, welcome to the reward, welcome star,fork my GitHub. Like the author can also be follow. Also count as a support to the author. This article GitHub code links
Https://github.com/AndroidMsky/WXhongbao

Also read a lot of information thank the road Heroes
Reference articles:

Android wake, unlock screen Code instance

Android realizes micro-letter automatic Red Envelope program

Android Accessibilityservice Implement micro-letter grab Red Envelopes Plugin

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.