DropBoxReceiver

Posted adamli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DropBoxReceiver相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章