码迷,mamicode.com
首页 > 其他好文 > 详细

DropBoxReceiver

时间:2020-06-16 14:46:47      阅读:53      评论:0      收藏:0      [点我收藏+]

标签:public   debug   context   static   receive   list   mon   art   sync   

package com.android.demo.lileidemo.listener;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.DropBoxManager;
import android.os.Handler;

import com.android.demo.lileidemo.MyApplication;
import com.android.demo.lileidemo.constant.AppConstants;
/**
* date: 04/08/2020.
* author: lilei.
* Android8.0 should dynamic registration monitoring.
*/
public class DropBoxReceiver extends BroadcastReceiver {
public static String TAG = AppConstants.APP_TAG + "DropBoxReceiver ";
private Handler mWorker;
private static volatile DropBoxReceiver mInstance;
private static final boolean DEBUG = true;

public DropBoxReceiver() {
mWorker = new Handler();
}

/**
* get Instance.
*
* @return instance.
*/
public static DropBoxReceiver getInstance() {
if (mInstance == null) {
synchronized (DropBoxReceiver.class) {
if (mInstance == null) {
mInstance = new DropBoxReceiver();
}
}
}
return mInstance;
}

/**
* Register Ivi State Change Listener and start DropBox monitor.
*
*/
public void registerIviStateChangeListener() {
//LogUtil.d(TAG + "registerIviStateChangeListener()");
registerReceiver();
}

/**
* registerReceiver.
*/
private void registerReceiver() {
//LogUtil.d(TAG + "registerReceiver private");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.DROPBOX_ENTRY_ADDED");
MyApplication.getAppContext().registerReceiver(DropBoxReceiver.getInstance(),
intentFilter);
}

/**
* unregisterReceiver.
*/
public void unregisterReceiver() {
MyApplication.getAppContext().unregisterReceiver(DropBoxReceiver.getInstance());
}

@Override
public void onReceive(Context context, Intent intent) {
String tag = (String) intent.getExtras().get(DropBoxManager.EXTRA_TAG);
long time = (Long) intent.getExtras().get(DropBoxManager.EXTRA_TIME);
if (DEBUG) {
//LogUtil.d(TAG + "dropbox tag =" + tag + ",time = " + time);
}
parseDropBox(tag, time);
}

/**
* parseDropBox.
*
* @param tag tag.
* @param time time.
*/
public void parseDropBox(String tag, long time) {
/**
if ("system_app_crash".equals(tag) || "data_app_crash".equals(tag)) {
String packageName = DropBoxUtil.getDropBoxPackageName(tag, time - 1);
LogUtil.d(TAG + "parseDropBox 11 tag:" + tag + " time:" + time
+ " packageName:" + packageName);
} else if ("system_app_anr".equals(tag) || "data_app_anr".equals(tag)) {
String packageName = DropBoxUtil.getDropBoxPackageName(tag, time - 1);
LogUtil.d(TAG + "parseDropBox 22 tag:" + tag + " time:" + time
+ " packageName:" + packageName);
}
**/
}
}

DropBoxReceiver

标签:public   debug   context   static   receive   list   mon   art   sync   

原文地址:https://www.cnblogs.com/adamli/p/13140610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!