当前位置: 首页 > wzjs >正文

保定建网站公司网站怎么做可以合法让别人充钱

保定建网站公司,网站怎么做可以合法让别人充钱,站长工具5118,宁波海曙网站开发公司Android 监测顶层包名类名 本文主要介绍下通过辅助功能来实现android 中实时监测顶层包名类名. 1: 检测应用是否开启辅助功能 通过读取系统设置中的 ACCESSIBILITY_ENABLED 和 ENABLED_ACCESSIBILITY_SERVICES 来判断当前服务是否已启用. /*** 检查辅助功能是否已启用*/ pr…

Android 监测顶层包名+类名

本文主要介绍下通过辅助功能来实现android 中实时监测顶层包名类名.

1: 检测应用是否开启辅助功能

通过读取系统设置中的 ACCESSIBILITY_ENABLED 和 ENABLED_ACCESSIBILITY_SERVICES 来判断当前服务是否已启用.

/*** 检查辅助功能是否已启用*/
private boolean isAccessibilityServiceEnabled(Context context) {int accessibilityEnabled = 0;try {accessibilityEnabled = Settings.Secure.getInt(context.getContentResolver(),android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);} catch (Settings.SettingNotFoundException e) {Log.e(TAG, "Error finding accessibility setting: " + e.getMessage());}if (accessibilityEnabled == 1) {String services = Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);if (services != null) {Log.d(TAG, "Enabled services: " + services);return services.contains(context.getPackageName() + "/" + MyAccessibilityService.class.getName());}}return false;
}

2: 跳转到辅助功能设置页面

使用 Intent 跳转到系统辅助功能设置页面, 添加 FLAG_ACTIVITY_NEW_TASK 标志以确保可以从服务中启动 Activity.

注意权限声明:确保在 AndroidManifest.xml 中已声明 BIND_ACCESSIBILITY_SERVICE 权限

/*** 跳转到辅助功能设置页面*/
private void openAccessibilitySettings() {Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent);
}

3: 实现MyAccessibilityService类

package com.example.topclass;import android.accessibilityservice.AccessibilityService;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;import androidx.annotation.RequiresApi;/*** @Author: zh* @Time: 24-12-12.* @Describe: 辅助功能监测顶层包名*/
public class MyAccessibilityService extends AccessibilityService {private static final String TAG = "MyAccessibilityService";private static final String CHANNEL_ID = "AccessibilityServiceChannel";private Handler handler = new Handler(Looper.getMainLooper());private Runnable heartbeatRunnable;@Overridepublic void onAccessibilityEvent(AccessibilityEvent event) {// 检查事件类型是否为窗口状态变化if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {// 获取当前顶层页面的包名String packageName = event.getPackageName().toString();// 获取当前顶层页面的类名String className = event.getClassName().toString();// 打印包名和类名Log.d(TAG, "Top Activity: PackageName=" + packageName + ", ClassName=" + className);}}@Overridepublic void onInterrupt() {// 当服务被中断时调用Log.d(TAG, "Accessibility service interrupted");}@Overrideprotected void onServiceConnected() {super.onServiceConnected();// 提升服务优先级,绑定前台服务if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {startForegroundService();// 启动心跳机制,每1s发送一次通知heartbeatRunnable = new Runnable() {@Overridepublic void run() {// 增强日志记录,确保服务状态可见Log.d(TAG, "Heartbeat: Service is active. Thread ID: " + Thread.currentThread().getId());handler.postDelayed(this, 1000); // 每1s执行一次}};handler.post(heartbeatRunnable);}}@Overridepublic void onDestroy() {super.onDestroy();// 停止心跳机制if (heartbeatRunnable != null) {handler.removeCallbacks(heartbeatRunnable);}// 增加详细日志记录,确保资源释放过程被记录Log.d(TAG, "Service destroyed. Resources cleaned up. Thread ID: " + Thread.currentThread().getId());}/*** 绑定前台服务,提升优先级*/@RequiresApi(api = Build.VERSION_CODES.O)private void startForegroundService() {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {NotificationChannel channel = new NotificationChannel(CHANNEL_ID,"Accessibility Service",NotificationManager.IMPORTANCE_HIGH);NotificationManager manager = getSystemService(NotificationManager.class);manager.createNotificationChannel(channel);}Notification notification = new Notification.Builder(this, CHANNEL_ID).setContentTitle("Accessibility Service Running").setContentText("Listening for page changes...").setSmallIcon(R.drawable.ic_launcher_background).setPriority(Notification.PRIORITY_HIGH).build();startForeground(999, notification);}}
  1. 实现了 AccessibilityService,并在 onAccessibilityEvent 方法中监听 TYPE_WINDOW_STATE_CHANGED 事件。
    提取事件中的包名和类名,并通过 Log.d 打印到日志中
  2. 在 onServiceConnected 方法中调用 startForegroundService,将服务绑定为前台服务。使用 Notification 提示用户服务正在运行,避免被系统回收。
  3. 增加 android.permission.FOREGROUND_SERVICE权限, 避免启动前台服务时抛出 java.lang.SecurityException 异常.

4: 声明 AccessibilityService

AndroidManifest.xml文件中声明AccessibilityService.并配置了必要的权限和元数据.

<!-- 声明 AccessibilityService -->
<serviceandroid:name=".MyAccessibilityService"android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"android:exported="false"><intent-filter><action android:name="android.accessibilityservice.AccessibilityService" /></intent-filter><meta-dataandroid:name="android.accessibilityservice"android:resource="@xml/accessibility_service_config" />
</service>

5: 编写accessibility_service_config

编写accessibility_service_config, 配置服务的事件类型和反馈类型,确保能够监听窗口状态变化.

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"android:accessibilityEventTypes="typeWindowStateChanged"android:accessibilityFeedbackType="feedbackGeneric"android:canRetrieveWindowContent="true"android:description="@string/accessibility_service_description"android:notificationTimeout="100" />

6: 添加字符串资源

<string name="accessibility_service_description">This service listens to page changes and logs the top activity.</string>

7: 输出如下

2024-12-12 15:41:37.190 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2
2024-12-12 15:41:39.135 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2
2024-12-12 15:41:39.136 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.android.contacts, ClassName=android.widget.FrameLayout
2024-12-12 15:41:39.136 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.android.contacts, ClassName=com.android.dialer.BBKTwelveKeyDialer
2024-12-12 15:41:39.171 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.android.contacts, ClassName=com.android.dialer.BBKTwelveKeyDialer
2024-12-12 15:41:39.274 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.bbk.launcher2, ClassName=com.bbk.launcher2.Launcher
2024-12-12 15:41:40.153 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2
2024-12-12 15:41:40.247 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.bbk.launcher2, ClassName=com.bbk.launcher2.Launcher
2024-12-12 15:41:41.163 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2
2024-12-12 15:41:42.171 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2
2024-12-12 15:41:43.965 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2
2024-12-12 15:41:44.019 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.android.mms, ClassName=android.widget.FrameLayout
2024-12-12 15:41:44.019 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.android.mms, ClassName=com.android.mms.ui.ConversationList
2024-12-12 15:41:44.023 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.android.mms, ClassName=com.android.mms.ui.ConversationList
2024-12-12 15:41:44.125 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.bbk.launcher2, ClassName=com.bbk.launcher2.Launcher
2024-12-12 15:41:44.970 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2
2024-12-12 15:41:45.023 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.bbk.launcher2, ClassName=com.bbk.launcher2.Launcher
2024-12-12 15:41:46.562 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2
2024-12-12 15:41:46.596 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.tencent.mm, ClassName=com.tencent.mm.ui.LauncherUI
2024-12-12 15:41:46.596 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.tencent.mm, ClassName=com.tencent.mm.plugin.account.ui.LoginPasswordUI
2024-12-12 15:41:46.730 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.bbk.launcher2, ClassName=com.bbk.launcher2.Launcher
2024-12-12 15:41:47.569 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2
2024-12-12 15:41:47.806 7064-7064/com.example.topclass D/MyAccessibilityService: Top Activity: PackageName=com.bbk.launcher2, ClassName=com.bbk.launcher2.Launcher
2024-12-12 15:41:48.578 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2
2024-12-12 15:41:49.586 7064-7064/com.example.topclass D/MyAccessibilityService: Heartbeat: Service is active. Thread ID: 2

http://www.dtcms.com/wzjs/569499.html

相关文章:

  • 百度收录提交入口地址seo是啥职业
  • 深圳微商城网站设计制作wordpress 4.9 zh cn
  • 自己做的网站加载慢关于手机电子商务网站建设
  • 网站推广应该注意什么开封网站建设公司
  • wordpress 网站特效在线阅读网站开发
  • 网站建设视频做网站代理拉不到人
  • 软件开发和网站建设哪个好公司网址备案能用多少网站
  • 可信网站认证好处wordpress git 伪静态
  • 网站建设的重要指标怎么做私人彩票网站
  • 网站开发中都引用什么文献收费做网站
  • 重庆装修公司口碑排名seo项目
  • 北京网站ui设计公司苏州网站推广找苏州梦易行
  • 网站建设谈业务要知道什么保险网站程序源码
  • 效益型网站陇南建设网站
  • 企业网站建设 南通免费一级域名网站
  • 广西学校网站建设网站建设如何为企业电商化转型赋能
  • 广州网站优化服务常州网站备案
  • 北京网站建设手机号深圳网络营销推广培训
  • 可信网站权威性怎么样网站建设 三网
  • 视觉中国网站wordpress rss去掉
  • 北京各大网站推广平台哪家好网站建设安全问题
  • 连云港做网站优化为什么百度不收录wordpress
  • 合肥网站建设团队豌豆荚app下载 官网
  • 做网站制作步骤图片在线制作二维码
  • 网站建设运营费用wordpress模块咋编辑
  • 江苏省住房保障建设厅网站网站关键词排名如何做
  • 建设一个门户网站需要多少钱网站做很多关键词
  • 江苏优化网站公司哪家好哪里有专业网站建设公司
  • 站长wordpress 当前主题
  • 一般的网站建设玩具 东莞网站建设 技术支持