如何添加通知计时器(如whatsapp呼叫通知)?

propsLis

我有一个通知生成器。我想添加通知计时器,如whatsapp呼叫通知。因此,如果我调用updateNotifTime函数,则无法正常工作。

NotificationCompat.Builder builder = new NotificationCompat.Builder(context, callChannelId)
                .setSmallIcon(R.drawable.call_icon)
                .setContentIntent(pendingIntent)
                .setOngoing(true)
                .setShowWhen(true)
                .setWhen(System.currentTimeMillis())
                .setPriority(NotificationCompat.PRIORITY_HIGH);

public void updateNotifTime() {
    this.callingElapsedRunnable = new Runnable() {
                @Override
                public void run() {

                    elapsedTime += 1000;

                    String timer = DateUtils.calculateTime(elapsedTime);

                    builder.setWhen(elapsedTime);

                    callingElapsedHandler.postDelayed(this, 1000);
                }
            };

callingElapsedHandler.postDelayed(callingElapsedRunnable, 1000);
    }

whatsapp通知计时器 我的应用通知

propsLis

我为<5.0 SDK版本添加了自定义布局:

<5.0

public void startChronometer(String elapsedTime) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && builder != null) {
            RemoteViews mContentView = new RemoteViews(context.getPackageName(), R.layout.call_notification);
            //timerTxt
            TextView timerTxt = new TextView(context);
            timerTxt.setId(R.id.timerTxt);

            //callTypeTxt
            TextView callTypeTxt = new TextView(context);
            callTypeTxt.setId(R.id.callType);

            //calleeNameTxt
            TextView calleeNameTxt = new TextView(context);
            calleeNameTxt.setId(R.id.calleeName);

            mContentView.setTextViewText(timerTxt.getId(), elapsedTime);
            mContentView.setTextViewText(callTypeTxt.getId(), context.getString(R.string.call_in_progress));

            builder.setCustomBigContentView(mContentView);
            notificationManager.notify(CALL_NOTIFICATION_ID, builder.build());
        }
    }

其他版本

builder.setUsesChronometer(true);

HoreKishore Jethava问题:

Intent intent = new Intent(mContext, YourActivity.class);
intent.putExtra("tappedTime", System.currentTimeMillis());

PendingIntent pendingIntent = PendingIntent.getActivity(mContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章