小编M.V*_*eli的帖子

Android:创建新通知后,将替换旧通知

我想在不取消/删除我的应用程序的先前通知的情况下创建通知.这是我创建通知的代码:

private void notification(Context context, String title, String content) {
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle(title)
            .setContentText(content);

    Intent resultIntent = new Intent(context, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                0,
                PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    //Id allows you to update the notification later on.
    mNotificationManager.notify(100, …
Run Code Online (Sandbox Code Playgroud)

notifications android notify

13
推荐指数
2
解决办法
7184
查看次数

Android KeyPairGenerator始终生成相同的密钥对

我正在创建一个为用户生成密钥对的应用程序.但在每个设备中,密钥都是相同的.这是我的代码:

public KeyPair generateKeys() {
    KeyPair keyPair = null;
    try {
        // get instance of rsa cipher
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(1024);            // initialize key generator
        keyPair = keyGen.generateKeyPair(); // generate pair of keys
    } catch(GeneralSecurityException e) {
        System.out.println(e); 
    }
    return keyPair;
}
Run Code Online (Sandbox Code Playgroud)

并显示生成的密钥代码是:

KeyPair keyPair = rsa.generateKeys();

byte[] publicKey = keyPair.getPublic().getEncoded();
byte[] privateKey = keyPair.getPrivate().getEncoded();
privateText.setText( Base64.encodeToString(privateKey, Base64.NO_WRAP) );
publicText.setText( Base64.encodeToString(publicKey, Base64.NO_WRAP) );
Run Code Online (Sandbox Code Playgroud)

对于每个Android设备,密钥生成仅被调用一次,因此每个设备中的密钥应该是不同的.有人能告诉我我在这里缺少什么吗?

java android key-generator key-pair

7
推荐指数
1
解决办法
4776
查看次数

标签 统计

android ×2

java ×1

key-generator ×1

key-pair ×1

notifications ×1

notify ×1