All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yy.httpproxy.subscribe.SharedPreferencePushIdGenerator Maven / Gradle / Ivy

There is a newer version: 1.0.45
Show newest version
package com.yy.httpproxy.subscribe;

import android.content.Context;
import android.content.SharedPreferences;

import java.math.BigInteger;
import java.security.SecureRandom;

/**
 * Created by xuduo on 10/20/15.
 */
public class SharedPreferencePushIdGenerator implements PushIdGenerator {

    private Context context;

    public SharedPreferencePushIdGenerator(Context context) {
        this.context = context;
    }

    public String nextSessionId() {
        return new BigInteger(130, new SecureRandom()).toString(32);
    }

    @Override
    public String generatePushId() {
        SharedPreferences preferences = context.getSharedPreferences("SharedPreferencePushGenerator", Context.MODE_PRIVATE);
        String id = preferences.getString("pushId", null);
        if (id == null) {
            id = nextSessionId();
            preferences.edit().putString("pushId", id).commit();
        }
        return id;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy