背景:
现在用户未同意隐私政策前就获取了用户个人信息(mac地址,imei码),所以在启动页都得加个隐私政策询问弹框,同意后再初始化第三方SDK
作用:
符合要求
效果图:
思路:
用SP存储用户是否同意了隐私政策,在启动页如果SP存的值为true,就走正常流程,如果为false,就弹框询问,用户同意后再调Application里面的初始化第三方SDK,再走正常流程
关键代码:
SPUtils
public static void saveIsAgreeYSAndXY(){
putBoolean(SPKey.IS_AGREE_YS_AND_XY,true);
}
public static boolean getIsAgreeYSAndXY(){
return getBoolean(SPKey.IS_AGREE_YS_AND_XY,false);
}
MyApplication
public class MyApplication extends MultiDexApplication {
@Override
public void onCreate() {
super.onCreate();
// 友盟预初始化
UMConfigure.preInit(mInstance,BuildConfig.UMENG_APPKEY, BuildConfig.FLAVOR);
initSDK();
}
public void initSDK(){
if(SPNoCleanUtil.getIsAgreeYSAndXY()){
//友盟初始化,因为项目中的新版友盟,组件化SDK,没有用到Push功能,传null
UMConfigure.init(mInstance, BuildConfig.UMENG_APPKEY, BuildConfig.FLAVOR, UMConfigure.DEVICE_TYPE_PHONE, null);
// 选用AUTO页面采集模式
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
//初始化其他SDK
}
}
}
StartupActivity(启动页)
public class StartupActivity extends BaseActivity<StartupIView, StartupPresenter> implements StartupIView {
@BindView(R.id.iv_ad)
ImageView ivAd;
@BindView(R.id.tv_ad_countdown)
TextView tvAdCountdown;
@BindView(R.id.fl_ad)
FrameLayout flAd;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_startup);
ButterKnife.bind(this);
//开始倒计时,改成隐私弹框
startCountDown();
}
private void startCountDown() {
if(!SPNoCleanUtil.getIsAgreeYSAndXY()){
AppDialogUtils.guideYinsiDialog(mContext, new View.OnClickListener() {
@Override
public void onClick(View view) {
}
}, new View.OnClickListener() {
@Override
public void onClick(View view) {
}
}, new View.OnClickListener() {
@Override
public void onClick(View view) {
//点了同意按钮
toNext();
}
});
}else {
toNext();
}
}
private void toNext() {
if(!SPNoCleanUtil.getIsAgreeYSAndXY()){
SPNoCleanUtil.saveIsAgreeYSAndXY();
((MyApplication)getIView().getContext().getApplicationContext()).initSDK();
}
if (!SPUtils.getIsLogin()) {
IntentUtils.startGuideActivity(mContext);
} else {
IntentUtils.startMainActivity(mContext);
}
finish();
}
}
隐私政策弹框代码就不给出了,这里代码也简单,关键是思路要对