Android实现仿银行APP回退至后台,并在通知栏里显示
给应用实现仿银行APP回退至后台,在通知栏或状态栏里显示通知提示
使用广播接收形式,实现在通知栏里显示常驻通知:
public class LifeCircleReceiver extends BroadcastReceiver {
private NotificationManager notificationManager;
private Activity activity;
private static int notifyId;
private static final int NOTIFY_ID = 10001;
public LifeCircleReceiver(Activity activity) {
this.activity = activity;
}
@Override
public void onReceive(Context context, Intent intent) {
NLog.i(Constants.TAG, "LifeCircleReceiver.onReceive");
notificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
boolean background = intent.getBooleanExtra("background", false);
if (!background) {
if (notifyId > 0) {
notificationManager.cancel(notifyId); //清除ID号为常量notifyId的通知
notificationManager.cancelAll(); //清除全部通知
}
return;
}
String channel = AnalyticsConfig.getChannel(context);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channel);
//PendingIntent 跳转动作
PendingIntent pendingIntent = PendingIntent.getActivity(activity, 0, activity.getIntent(), 0);
mBuilder.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(context.getResources().getString(R.string.app_name))
.setContentText(context.getResources().getString(R.string.app_run_background))
.setContentIntent(pendingIntent);
Notification notification = mBuilder.build();
//notification.icon = R.drawable.logo;
//在通知栏上点击此通知后不会自动清除此通知
notification.flags = Notification.FLAG_ONGOING_EVENT;
//设置显示通知时的默认的发声、震动、Light效果
//notification.defaults = Notification.DEFAULT_VIBRATE;
notifyId = NOTIFY_ID;
notificationManager.notify(notifyId, notification);
}
}
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/18/android-implements-a-simulated-banking-app-to-rollback-to-the-backend-and-display-it-in-notification-bar/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
Android实现仿银行APP回退至后台,并在通知栏里显示
给应用实现仿银行APP回退至后台,在通知栏或状态栏里显示通知提示
使用广播接收形式,实现在通知栏里显示常驻通知:
public class LifeCircleReceiver extend……
文章目录
关闭
共有 0 条评论