gpt4 book ai didi

开/关切换按钮时的Android开/关推送通知

转载 作者:行者123 更新时间:2023-11-30 01:43:39 27 4
gpt4 key购买 nike

如何使用 ToggleButton 启用/禁用推送通知

示例:

ToggleButton 禁用 (OFF) >>> 推送通知应该停止

ToggleButton 启用 (ON) >>> 推送通知 Shouid strat

// turn on/off push notification
if (isChecked){
prefNotification.edit().putBoolean(Constant.PREF_KEY, true).commit();
PushService.setDefaultPushCallback(getApplicationContext(),YOUR_CLASS.class);
Toast.makeText(CatalogActivity.this, "turn on", Toast.LENGTH_SHORT).show();
} else{
prefNotification.edit().putBoolean(Constant.PREF_KEY_TOGGLE_NOTIFICATION, false).commit();
PushService.setDefaultPushCallback(getApplicationContext(), null);
Toast.makeText(CatalogActivity.this, "turn off", Toast.LENGTH_SHORT).show();
}
}

最佳答案

use this code inside your toggle button listener
if(isChecked)
{
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);

Editor editor = settings.edit();
editor.putString("push", "true");
editor.commit();
}
else
{
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);

Editor editor = settings.edit();
editor.putString("push", "false");
editor.commit();
}

and receiver class
show push notification according to shared Preference Flag

关于开/关切换按钮时的Android开/关推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34063863/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com