1. 初始化神策 SDK

可参考:https://manual.sensorsdata.cn/sa/latest/tech_sdk_client_android_basic-7541696.html

2. 获取归因信息并触发激活事件

private static final String PROVIDER_URI ="content://com.huawei.appmarket.commondata/item/5";
private static final int INDEX_ENTER_AG_TIME = 1;
private static final int INDEX_INSTALLED_FINISH_TIME = 2;
private static final int INDEX_START_DOWNLOAD_TIME= 3;
private static final int INDEX_TRACKID = 4;
private static final int INDEX_REFERRER_EX = 5;

/**
 * 获取华为归因信息并触发神策激活事件
 * @param pkgName 目标包名
 */
private String trackAppInstall(String pkgName) {
    String trackId = null;
    Cursor cursor = null;
    Uri uri = Uri.parse(PROVIDER_URI);
    ContentResolver contentResolver = getContentResolver();
    String packageName[] = new String[] { pkgName };
    JSONObject channelJSON = new JSONObject();
    try {
		// 查询归因信息
        cursor = contentResolver.query(uri, null, null, packageName, null);
        if (cursor != null) {
            cursor.moveToFirst();
            Log.i(TAG, "packageName= " + pkgName);
            if (cursor.getColumnCount() > INDEX_TRACKID) {
                // 10.5.0.300 及之后版本,之前版本无 trackId
                JSONObject attributionJSON = new JSONObject(); 
                attributionJSON.put("channel_name", "huawei_appstore_track"); 
                attributionJSON.put("enter_ag_time", cursor.getString(INDEX_ENTER_AG_TIME));
                attributionJSON.put("installed_finish_time", cursor.getString(INDEX_INSTALLED_FINISH_TIME));
                attributionJSON.put("download_time", cursor.getString(INDEX_START_DOWNLOAD_TIME)); 
                attributionJSON.put("trackId", new JSONObject(cursor.getString(INDEX_TRACKID)));
				attributionJSON.put("referrer_ex", cursor.getString(INDEX_REFERRER_EX));
                channelJSON.put("$sat_media_attribution_info", attributionJSON.toString());
            }
        }
    }catch(Exception e){
        //处理异常
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
	//触发神策激活事件
    SensorsDataAPI.sharedInstance().trackAppInstall(channelJSON);
}
CODE