欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

自动刷抖音极速版得红包金币(APP实现)

程序员文章站 2022-04-11 15:33:45
...

   上回我们用python实现了自动刷抖音的功能(https://blog.csdn.net/u012539700/article/details/100058939),这回我们用android app的形式来实现自动刷抖音,这样就可以不用连接电脑啦。

  原理很简单,使用android无障碍里面的AccessibilityService就可以啦。

   首先在res目录下新建一个xml文件夹,然后命名一个simulatekey.xml文件,填入以下内容:

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFeedbackType="feedbackGeneric"
    android:accessibilityFlags="flagReportViewIds|flagRetrieveInteractiveWindows"
    android:canRetrieveWindowContent="true"
    android:description="@string/simulate_key_description"
    android:notificationTimeout="100"
    />

其中description就是会显示在你去无障碍里面开启服务的地方的提示文字。

清单文件里面增加配置:

  <service
            android:name=".simulatekey.SimulateKeyService"
            android:enabled="true"
            android:exported="true"
            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/simulatekey" />
        </service>

接下来是判断无障碍服务是否开启:

  public static boolean isAccessibilitySettingsOn(Context mContext) {
        int accessibilityEnabled = 0;
        final String service = mContext.getPackageName() + "/" + SimulateKeyService.class.getCanonicalName();
        try {
            accessibilityEnabled = Settings.Secure.getInt(
                    mContext.getApplicationContext().getContentResolver(),
                    android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
            Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
        } catch (Settings.SettingNotFoundException e) {
            Log.e(TAG, "Error finding setting, default accessibility to not found: "
                    + e.getMessage());
        }
        TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

        if (accessibilityEnabled == 1) {
            Log.v(TAG, "***ACCESSIBILITY IS ENABLED*** -----------------");
            String settingValue = Settings.Secure.getString(
                    mContext.getApplicationContext().getContentResolver(),
                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
            if (settingValue != null) {
                mStringColonSplitter.setString(settingValue);
                while (mStringColonSplitter.hasNext()) {
                    String accessibilityService = mStringColonSplitter.next();

                    Log.v(TAG, "-------------- > accessibilityService :: " + accessibilityService + " " + service);
                    if (accessibilityService.equalsIgnoreCase(service)) {
                        Log.v(TAG, "We've found the correct setting - accessibility is switched on!");
                        return true;
                    }
                }
            }
        } else {
            Log.v(TAG, "***ACCESSIBILITY IS DISABLED***");
        }

        return false;
    }

  如果没有开启的话,我们就判断去开启这个服务:

   if(!SimulateKeyService.isAccessibilitySettingsOn(MainActivity.this)){
                    Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
                    startActivity(intent);
                }else{
                    startService(new Intent(MainActivity.this, SimulateKeyService.class));
                }

最后我们写一个SimulateKeyService服务继承AccessibilityService的onAccessibilityEvent方法:

 @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        Log.d("awqtj",event.toString()+" ===== "+event.getPackageName());
        if(event==null ||event.getPackageName()==null){
            return;
        }

        if(event.getPackageName().equals("com.ss.android.ugc.aweme.lite")){

            final AccessibilityNodeInfo nodeInfo = event.getSource();
            if (nodeInfo != null &&  "android.support.v4.view.ViewPager".equals(nodeInfo.getClassName())){
                if(!isFirst){
                    return;
                }
                if(isFirst){
                    isFirst = false;
                }
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            while(true){
                                Log.d("awqtj","================start "+nodeInfo.getClassName());

                                Random random = new Random();
                                int delay = random.nextInt(1000);
                                Thread.sleep(1000+delay);
                                {
                                    nodeInfo.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
                                }
                                Log.d("awqtj","================end ");
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }else {
                Log.d("awqtj","node info null");
            }

        }
    }

然后,首次进入抖音的时候,你滑动一下,就会检测到抖音里面的viewpager这个控件,然后就可以实现不断自动刷抖音得金币啦,而且设置自动刷的时间是随机的,应该可以避免被系统检测到自动刷的机制。

相关标签: 自动刷抖音