• 开启个推和关闭个推--SharePreferences使用


    https://docs.getui.com/getui/mobile/android/api/

    初始化

    类名 com.igexin.sdk.PushManager
    接口 public void initialize(Context context)
    PushManager.getInstance().initialize

    开启

    1. 开启推送
      类名 com.igexin.sdk.PushManager
      接口 public void turnOnPush(Context context)
      com.igexin.sdk.PushManager.getInstance().turnOnPush(mContext);

    关闭

    类名 com.igexin.sdk.PushManager
    接口 public void turnOffPush(Context context)

    SharePreferences使用

            rl_ifpush = findViewById(R.id.rl_ifpush);
            tv_ifpush = findViewById(R.id.tv_ifpush);
            sp = getSharedPreferences("ifpush", Context.MODE_PRIVATE);
            if (!sp.getBoolean("ifpush", true)) {
                tv_ifpush.setText("开启定向推送");
            }
    
            rl_ifpush.setOnClickListener(ifPushClickListener);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
        private View.OnClickListener ifPushClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sp = getSharedPreferences("ifpush", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                if (sp.getBoolean("ifpush", true)) {
                    com.igexin.sdk.PushManager.getInstance().turnOffPush(mContext.getApplicationContext());
                    editor.putBoolean("ifpush", false);
                    tv_ifpush.setText("开启定向推送");
    
                }else {
                    com.igexin.sdk.PushManager.getInstance().turnOnPush(SDKInit.mContext);
                    editor.putBoolean("ifpush", true);
                    tv_ifpush.setText("禁止定向推送");
    
                }
                editor.apply();
                editor.commit();
                ToastUtils.showLongToast("是否定向推送:"+sp.getBoolean("ifpush", true));
    
    
            }
        };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    https://blog.csdn.net/xipengbozai/article/details/114644264
    sp(SharedPreferences实例)获取方式:Context.getSharedPreferences(java.lang.String, int),这个方法有两个参数,第一个表示sp对应xml的文件名,第二个为这个文件的模式,私有,共有,可读,可写

    putBoolean(Context ctx, String key, boolean value)
    里面可以是存储节点,第二个是存储节点的值
    getBoolean实际上是先读取这个可以的值,如果不存在的话就使用默认值取代

    在这里插入图片描述

  • 相关阅读:
    状态保持-JWT
    干洗店洗鞋店小程序家政保洁带商城一体化系统开发
    java中的线程中断
    [RoarCTF 2019]Easy Calc
    OpenCV4 :并行计算cv::parallel_for_
    Spark在大数据集群下的部署
    springboot redisTemplate.opsForValue().setIfAbsent返回null原理
    单元测试,集成测试,系统测试的区别是什么?
    Windows10计算机能升级到Windows 11 22H2吗?
    TiDB | 来说说TiEM初体验吧
  • 原文地址:https://blog.csdn.net/weixin_46045444/article/details/125292174