package com.ttstd.dialer.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

import com.tencent.mmkv.MMKV;
import com.ttstd.dialer.config.CommonConfig;

public class AppChangedReceiver extends BroadcastReceiver {
    private static final String TAG = "ApkInstallReceiver";

    private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);

    @Override
    public void onReceive(final Context context, Intent intent) {
        String action = intent.getAction();
        Log.e(TAG, "onReceive: " + "action = " + action);
        if (TextUtils.isEmpty(action)) {
            return;
        }
        String packageName = intent.getDataString().replace("package:", "");
        switch (action) {
            case Intent.ACTION_PACKAGE_ADDED:
                Log.e(TAG, "onReceive: added " + packageName);
                break;
            case Intent.ACTION_PACKAGE_REPLACED:
                Log.e(TAG, "onReceive: replaced " + packageName);
                break;
            case Intent.ACTION_PACKAGE_REMOVED:
                Log.e(TAG, "onReceive: removed " + packageName);
                break;
            default:
                break;
        }
    }

}
