天天看点

android首次启动,Android APP首次/首次今日启动判断

拿走不谢!

1.APP首次启动判断

2.APP今日启动判断

上菜:

public static boolean isFirstStart(Context context) {

SharedPreferences preferences = context.getSharedPreferences(

"NB_FIRST_START", 0);

Boolean isFirst = preferences.getBoolean("FIRST_START", true);

if (isFirst) {// 第一次

preferences.edit().putBoolean("FIRST_START", false).commit();

return true;

} else {

return false;

}

}

public static boolean isTodayFirstStartApp(Context context) {

try {

SharedPreferences preferences = context.getSharedPreferences("NB_TODAY_FIRST_START_APP", context.MODE_PRIVATE);

String svaeTime = preferences.getString("startAppTime", "2020-01-08");

String todayTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());

if (!TextUtils.isEmpty(todayTime) && !TextUtils.isEmpty(svaeTime)) {

if(!svaeTime.equals(todayTime)) {

preferences.edit().putString("startAppTime", todayTime).commit();

return true;

}

}

}catch (Exception e){

log(TAG, "是否为今日首次启动APP,获取异常:"+e.toString());

return true;

}

return false;

}