{"id":1302,"date":"2023-03-18T10:32:29","date_gmt":"2023-03-18T02:32:29","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1302"},"modified":"2023-04-29T09:17:04","modified_gmt":"2023-04-29T01:17:04","slug":"android-implements-a-simulated-banking-app-to-rollback-to-the-backend-and-display-it-in-notification-bar","status":"publish","type":"post","link":"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\/","title":{"rendered":"Android\u5b9e\u73b0\u4eff\u94f6\u884cAPP\u56de\u9000\u81f3\u540e\u53f0\uff0c\u5e76\u5728\u901a\u77e5\u680f\u91cc\u663e\u793a"},"content":{"rendered":"<p>\u7ed9\u5e94\u7528\u5b9e\u73b0\u4eff\u94f6\u884cAPP\u56de\u9000\u81f3\u540e\u53f0\uff0c\u5728\u901a\u77e5\u680f\u6216\u72b6\u6001\u680f\u91cc\u663e\u793a\u901a\u77e5\u63d0\u793a<\/p>\n<p>\u4f7f\u7528\u5e7f\u64ad\u63a5\u6536\u5f62\u5f0f\uff0c\u5b9e\u73b0\u5728\u901a\u77e5\u680f\u91cc\u663e\u793a\u5e38\u9a7b\u901a\u77e5\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">public class LifeCircleReceiver extends BroadcastReceiver {\n    private NotificationManager notificationManager;\n    private Activity activity;\n    private static int notifyId;\n    private static final int NOTIFY_ID = 10001;\n\n    public LifeCircleReceiver(Activity activity) {\n        this.activity = activity;\n    }\n\n    @Override\n    public void onReceive(Context context, Intent intent) {\n        NLog.i(Constants.TAG, &quot;LifeCircleReceiver.onReceive&quot;);\n        notificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);\n\n        boolean background = intent.getBooleanExtra(&quot;background&quot;, false);\n        if (!background) {\n            if (notifyId &gt; 0) {\n                notificationManager.cancel(notifyId);  \/\/\u6e05\u9664ID\u53f7\u4e3a\u5e38\u91cfnotifyId\u7684\u901a\u77e5\n                notificationManager.cancelAll();  \/\/\u6e05\u9664\u5168\u90e8\u901a\u77e5\n            }\n            return;\n        }\n\n        String channel = AnalyticsConfig.getChannel(context);\n        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channel);\n        \/\/PendingIntent \u8df3\u8f6c\u52a8\u4f5c\n        PendingIntent pendingIntent = PendingIntent.getActivity(activity, 0, activity.getIntent(), 0);\n        mBuilder.setSmallIcon(R.mipmap.ic_launcher)\n                .setContentTitle(context.getResources().getString(R.string.app_name))\n                .setContentText(context.getResources().getString(R.string.app_run_background))\n                .setContentIntent(pendingIntent);\n        Notification notification = mBuilder.build();\n        \/\/notification.icon = R.drawable.logo;\n        \/\/\u5728\u901a\u77e5\u680f\u4e0a\u70b9\u51fb\u6b64\u901a\u77e5\u540e\u4e0d\u4f1a\u81ea\u52a8\u6e05\u9664\u6b64\u901a\u77e5\n        notification.flags = Notification.FLAG_ONGOING_EVENT;\n        \/\/\u8bbe\u7f6e\u663e\u793a\u901a\u77e5\u65f6\u7684\u9ed8\u8ba4\u7684\u53d1\u58f0\u3001\u9707\u52a8\u3001Light\u6548\u679c\n        \/\/notification.defaults = Notification.DEFAULT_VIBRATE;\n        notifyId = NOTIFY_ID;\n        notificationManager.notify(notifyId, notification);\n    }\n\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5e94\u7528\u5b9e\u73b0\u4eff\u94f6\u884cAPP\u56de\u9000\u81f3\u540e\u53f0\uff0c\u5728\u901a\u77e5\u680f\u6216\u72b6\u6001\u680f\u91cc\u663e\u793a\u901a\u77e5\u63d0\u793a \u4f7f\u7528\u5e7f\u64ad\u63a5\u6536\u5f62\u5f0f\uff0c\u5b9e\u73b0\u5728\u901a\u77e5\u680f\u91cc\u663e\u793a\u5e38\u9a7b\u901a\u77e5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-1302","post","type-post","status-publish","format-standard","hentry","category-android-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1302"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1302\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}