欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Android实现微信自动抢红包的程序,android实现抢红包,简单实现了微信自动抢红包

来源: javaer 分享于  点击 6159 次 点评:278

Android实现微信自动抢红包的程序,android实现抢红包,简单实现了微信自动抢红包


简单实现了微信自动抢红包的服务,原理就是根据关键字找到相应的View, 然后自动点击。主要是用到AccessibilityService这个辅助服务,基本可以满足自动抢红包的功能,但是有些逻辑需要优化,比如,拆完一个红包后,必须手动点击返回键,才能进行下一次自动抢红包。

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.jackie.webchatenvelope" >    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name=".MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <service            android:enabled="true"            android:exported="true"            android:label="@string/app_name"            android:name=".EnvelopeService"            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">            <intent-filter>                <action android:name="android.accessibilityservice.AccessibilityService"/>            </intent-filter>            <meta-data                android:name="android.accessibilityservice"                android:resource="@xml/envelope_service_config"/>        </service>    </application></manifest>```envelope_service_config.xml```xml<?xml version="1.0" encoding="utf-8"?><accessibility-service xmlns:android="http://schemas.android.com/apk/res/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```java<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/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">    <Button        android:id="@+id/start"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:padding="10dp"        android:layout_centerInParent="true"        android:textSize="18sp"        android:text="打开辅助服务"/></RelativeLayout>

MainActivity.java

package com.jackie.webchatenvelope;  import android.app.Activity;  import android.content.Intent;  import android.os.Bundle;  import android.view.Menu;  import android.view.MenuItem;  import android.view.View;  import android.widget.Button;  import android.widget.Toast;  public class MainActivity extends Activity {      private Button startBtn;      @Override      protected void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.activity_main);          startBtn = (Button) findViewById(R.id.start);          startBtn.setOnClickListener(new View.OnClickListener() {              @Override              public void onClick(View v) {                  try {                      //打开系统设置中辅助功能                      Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);                      startActivity(intent);                      Toast.makeText(MainActivity.this, "找到抢红包,然后开启服务即可", Toast.LENGTH_LONG).show();                  } catch (Exception e) {                      e.printStackTrace();                  }              }          });      }      @Override      public boolean onCreateOptionsMenu(Menu menu) {          // Inflate the menu; this adds items to the action bar if it is present.          getMenuInflater().inflate(R.menu.menu_main, menu);          return true;      }      @Override      public boolean onOptionsItemSelected(MenuItem item) {          // Handle action bar item clicks here. The action bar will          // automatically handle clicks on the Home/Up button, so long          // as you specify a parent activity in AndroidManifest.xml.          int id = item.getItemId();          //noinspection SimplifiableIfStatement          if (id == R.id.action_settings) {              return true;          }          return super.onOptionsItemSelected(item);      }  }

EnvelopeService.java

None
相关栏目:

用户点评