package com.ym.zxhcsdk;

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

public class AppInstallReceive extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent!=null){
            String action = intent.getAction();
            if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_ADDED)){
                String packageName = intent.getData().getSchemeSpecificPart();
                if (!TextUtils.isEmpty(packageName)) {
                    for (int i =0;i<ZXHCConstant.adList.size();i++){
                        if (packageName.equals(ZXHCConstant.adList.get(i).getPackage_name())){
                            InstallFinishReport(ZXHCConstant.adList.get(i));
                            ZXHCConstant.adList.remove(i);
                            break;
                        }
                    }
                }
            }
            if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_REMOVED)){
                String packageName = intent.getData().getSchemeSpecificPart();
                if (!TextUtils.isEmpty(packageName)) {
                }
            }
            if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_REPLACED)){
                String packageName = intent.getData().getSchemeSpecificPart();
                if (!TextUtils.isEmpty(packageName)) {
                }
            }
//            intent.getAction()
        }


    }

    private void InstallFinishReport(HcAdBean adBean) {
        if (adBean.getFinishInstallmonitorUrls() != null && adBean.getFinishInstallmonitorUrls().size() > 0) {
            for (int i = 0; i < adBean.getFinishInstallmonitorUrls().size(); i++) {
                HttpClientUtils.GetEvent(adBean.getFinishInstallmonitorUrls().get(i));
            }
        }

    }
}
