批量删除朋友圈

本文介绍了如何在安卓系统上批量删除朋友圈。通过创建继承自AccessibilityService的类,并实现在onAccessibilityEvent中处理主要功能。在安卓4.0系统中可能会遇到延迟问题,可以通过手动操作或增加代码延迟来解决。提供了源代码和apk下载链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近想清空朋友圈的内容,但发现即使把这些成年累月的记录从头到尾浏览一遍都是不可能完成的任务,更别说手动一个一个点击删除了,真是心生便是罪生时。虽然可以通过屏蔽好友查看,但感觉不删除终究很麻烦,之前有个账号竟然就因为几个月没登录就被封了,所以还是在能登录的时候删除最好,但是手动清空不现实,网上搜索也没有好的办法,听说以前可以通过停用清空,现在试过的确不行。后来发现安卓的辅助功能可以帮助点击,于是就想能不能通过这个功能编写个辅助删除朋友圈的功能呢?经过几天的摸索发现确实可以,大大减轻了删除的麻烦,基本上达到了想要的效果,所以下面就介绍一下怎么编写辅助删除朋友圈的功能。


一。先建立一个没有activity的as工程,因为辅助功能没有界面要求

二。建立一个继承自AccessibilityService的类,实现二个必须实现接口

public class plscpyq extends AccessibilityService {

@Override
    public void onAccessibilityEvent(AccessibilityEvent event) {


    }


    @Override
    public void onInterrupt() {


    }


主要功能都是在onAccessibilityEvent里完成的。


三。在androidmanifest.xml里的application增加




<service
            android:name="com.niepan.plscpyq.plscpyq"
            android:enabled="true"
            android:exported="true"
            android:label="@string/app_name"
            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/accessibility" />

        </service>


四,在res下新建目录xml,并新建文件accessibility.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="flagDefault"
    android:canRetrieveWindowContent="true"
    android:description="@string/desc"
    android:notificationTimeout="100"


    />


五。在/res/values/strings.xml的文件里添加
 <string name="desc">批量删除朋友圈</string>


至此辅助功能的框架就搭建好了,可以生成apk了,但是没有任何辅助的功能。


六。下面就是实现批量删除的核心代码


    boolean pyq=false;


    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {


        String packname=event.getPackageName().toString();
        if(packname.contentEquals("com.tencent.mm"))
        {
            if(event.getClassName().toString().contentEquals("com.tencent.mm.plugin.sns.ui.SnsUserUI"))
            {

                AccessibilityNodeInfo rootNode = getRootInActiveWindow();
                today=false;
                pyq=true;
                menunode(rootNode);
            }
            else if(event.getClassName().toString().contentEquals("com.tencent.mm.plugin.sns.ui.SnsGalleryUI"))
            {

                AccessibilityNodeInfo rootNode = getRootInActiveWindow();
                infonode(rootNode);
            }
            else if(event.getClassName().toString().contentEquals("com.tencent.mm.plugin.sns.ui.SnsCommentDetailUI"))
            {

                findAndPerformAction("android.widget.TextView","删除");
            }
            else if(event.getClassName().toString().contains("com.tencent.mm.ui.base"))
            {
                findAndPerformAction("android.widget.Button","确定");

            }
            else if(event.getClassName().toString().contentEquals("com.tencent.mm.plugin.sns.ui.SnsTimeLineUI"))
            {
                AccessibilityNodeInfo rootNode = getRootInActiveWindow();
                pyq=false;
                finddesnode(rootNode, "我的头像");
            }
            else if(event.getEventType()==AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
            {
                if(event.getText().toString().contains("不存在"))
                    performGlobalAction(GLOBAL_ACTION_BACK);
            }
            else if(event.getEventType()==AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED)
            {
                if(pyq)
                {
                    AccessibilityNodeInfo rootNode = getRootInActiveWindow();
                    today=false;
                    menunode(rootNode);
                }
            }
            else if(event.getEventType()==AccessibilityEvent.TYPE_VIEW_CLICKED)
            {
                if(pyq)
                {
                    AccessibilityNodeInfo rootNode = getRootInActiveWindow();
                    today=false;
                    menunode(rootNode);
                }
            }
        }
    }




    private void findAndPerformAction(String widget, String text) {
        // 取得当前激活窗体的根节点
        AccessibilityNodeInfo rootNode =getRootInActiveWindow();
        if (rootNode== null) {
            return;
        }

        // 通过文本找到当前的节点
        List<AccessibilityNodeInfo> nodes = rootNode.findAccessibilityNodeInfosByText(text);
        if(nodes != null) {
            for (AccessibilityNodeInfo node : nodes) {
                if (node.getClassName().equals(widget) && node.isEnabled()) {

                    node.performAction(AccessibilityNodeInfo.ACTION_CLICK); // 执行点击
                    break;
                }
            }
        }
    }





    boolean today=false;

    void infonode(AccessibilityNodeInfo nodes){
        if (nodes != null) {
            int count = nodes.getChildCount();
            for (int i=0;i<count;i++){
                AccessibilityNodeInfo node = nodes.getChild(i);
                if (node == null)
                    continue;

                CharSequence text = node.getText();

                if ( node.getClassName().toString().contentEquals("android.widget.TextView")) {

                    if (node.getContentDescription() == null && text == null)
                    {
                        node.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
                    }

                }

                infonode(node);

            }
        }
    }





    void finddesnode(AccessibilityNodeInfo rootNode,String str){
        if (rootNode != null) {
            int count = rootNode.getChildCount();
            for (int i=0;i<count;i++){
                AccessibilityNodeInfo node = rootNode.getChild(i);
                if (node == null)
                    continue;

                CharSequence des=node.getContentDescription();

                if (des!=null && des.toString().contains(str)){
                        node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
                }

                finddesnode(node,str);

            }
        }
    }






    void menunode(AccessibilityNodeInfo nodes){
        if (nodes != null) {
            int count = nodes.getChildCount();
            for (int i=0;i<count;i++){
                AccessibilityNodeInfo node = nodes.getChild(i);
                if (node == null)
                    continue;

                CharSequence text = node.getText();

                if ( node.getClassName().toString().contentEquals("android.widget.TextView")){

                    if (today   && text!=null)
                    {
                        node.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);

                    }

                    if(text!=null) {
                        if (text.toString().contentEquals("今天"))
                            today = true;
                    }
                }
                else if ( node.getClassName().toString().contentEquals("android.view.View")) {
                    node.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
                    //此处可以设置延迟时间以便朋友圈的正确刷新
                    try {
                        sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                    menunode(node);

            }
        }
    }


代码很简单就是根据不同的类名进行不同的遍历点击。


七。生成apk,安装,打开安卓设置,辅助功能,plscpyq功能打开。

如果你用的是安卓4,由于安卓4本身就比较卡容易造成的删除延迟出现带锁标志,此时可以手动点返回到朋友圈界面便会自动刷新恢复,当然也可以在代码里增加延迟的时间。

注意!如果你觉得朋友圈还有需要的资料请提前下到手机上,因为辅助打开之后,进入到朋友圈就会自动开始批量帮你点击删除,不会停止,除非你退出朋友圈到界面或者你回到设置里关闭。

源代码下载http://download.csdn.net/detail/niepan_/9785379

apk下载http://download.csdn.net/download/niepan_/9785359

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值