{"id":1284,"date":"2023-03-18T10:11:02","date_gmt":"2023-03-18T02:11:02","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1284"},"modified":"2023-04-29T09:20:59","modified_gmt":"2023-04-29T01:20:59","slug":"android-8-and-above-integrate-with-umeng-push","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/android-8-and-above-integrate-with-umeng-push\/","title":{"rendered":"Android 8.0 \u53ca\u4ee5\u4e0a\u96c6\u6210\u53cb\u76df\u63a8\u9001\u91c7\u5751\u8bb0\u5f55"},"content":{"rendered":"<h2>setPushIntentServiceClass\u65e0\u6548<\/h2>\n<p>\u91c7\u7528<code>mPushAgent.setPushIntentServiceClass(PushService.class)<\/code>\u63a5\u6536\u5904\u7406\u6d88\u606f\u7684\u65b9\u5f0f\uff0c\u5728\u53cb\u76dfchannel\u8fdb\u7a0b\u53ef\u4ee5\u6210\u529f\u63a5\u6536\u5230\u6d88\u606f\uff0cLogcat\u6709\u6d88\u606f\u65e5\u5fd7\u6253\u5370\uff0c\u4f46\u5728\u4e3b\u8fdb\u7a0b\u63a5\u6536\u4e0d\u5230\u6d88\u606f<\/p>\n<p>\u7ecf\u6d4b\u8bd5\uff0cAndroid 8.0 \u53ca\u4ee5\u4e0a\u96c6\u6210\u53cb\u76df\u63a8\u9001\u63a5\u6536\u53ca\u5904\u7406\u6d88\u606f\u7edf\u8ba1\uff1a<\/p>\n<p><!-- more --><\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u5ba2\u6237\u7aef\u6d88\u606f\u5904\u7406\u65b9\u5f0f<\/th>\n<th style=\"text-align: center;\">\u670d\u52a1\u7aef\u53d1\u9001\u6d88\u606f\u7c7b\u578b<\/th>\n<th style=\"text-align: center;\">\u4e3b\u8fdb\u7a0b\u662f\u5426\u6210\u529f\u63a5\u6536\u6d88\u606f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">setMessageHandler<\/td>\n<td style=\"text-align: center;\">notification<\/td>\n<td style=\"text-align: center;\">\u662f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">setMessageHandler<\/td>\n<td style=\"text-align: center;\">message<\/td>\n<td style=\"text-align: center;\">\u5426<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">setPushIntentServiceClass<\/td>\n<td style=\"text-align: center;\">notification<\/td>\n<td style=\"text-align: center;\">\u5426<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">setPushIntentServiceClass<\/td>\n<td style=\"text-align: center;\">message<\/td>\n<td style=\"text-align: center;\">\u5426<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>android:permission<\/h2>\n<p>Android 8.0 \u53ca\u4ee5\u4e0a\u52a1\u5fc5\u6dfb\u52a0\u6743\u9650\uff1a<code>android:permission=&quot;android.permission.BIND_JOB_SERVICE&quot;<\/code><\/p>\n<pre><code class=\"language-xml\">&lt;service\n    android:name=&quot;.service.PushService&quot;\n    android:permission=&quot;android.permission.BIND_JOB_SERVICE&quot;\n    \/&gt;<\/code><\/pre>\n<p>\u89e3\u51b3\u601d\u8def\uff1a\u70b9\u51fb\u8fdb\u5165<code>mPushAgent.setPushIntentServiceClass(PushService.class)<\/code>\u65b9\u6cd5<\/p>\n<pre><code class=\"language-java\">public &lt;U extends UmengMessageService&gt; void setPushIntentServiceClass(Class&lt;U&gt; var1) {\n<\/code><\/pre>\n<p>\u53ef\u77e5\u53c2\u6570<code>PushService<\/code>\u5fc5\u987b\u7ee7\u627f\u81f3<code>UmengMessageService<\/code>\uff0c\u518d\u70b9\u51fb\u8fdb\u5165\u7c7b<code>UmengMessageService<\/code><\/p>\n<pre><code class=\"language-java\">public abstract class UmengMessageService extends UMJobIntentService {\n<\/code><\/pre>\n<pre><code class=\"language-java\">public class UMJobIntentService extends JobIntentService {\n<\/code><\/pre>\n<pre><code class=\"language-java\">public abstract class JobIntentService extends Service {\n<\/code><\/pre>\n<p>\u67e5\u770b<code>JobIntentService<\/code>\u7c7b\u6e90\u7801\u53d1\u73b0\u6709\u8bb8\u591a<code>if (VERSION.SDK_INT &gt;= 26)<\/code>\u7684\u5224\u65ad\uff0c\u5b9e\u9645\u4e0a\u5728<code>VERSION.SDK_INT &gt;= 26<\/code>\uff0c\u5373Android 8.0\u4ee5\u4e0a\u91c7\u7528<code>JobScheduler<\/code>\u673a\u5236\u5b9e\u73b0\u670d\u52a1\u8c03\u5ea6\uff0c\u56e0\u6b64\u58f0\u660eService\u5fc5\u987b\u6dfb\u52a0<code>android:permission=&quot;android.permission.BIND_JOB_SERVICE&quot;<\/code>\u6743\u9650<\/p>\n<h2>\u81ea\u5b9a\u4e49\u6d88\u606f<\/h2>\n<p>\u5982\u679c\u53ea\u9700\u63a5\u6536\u81ea\u5b9a\u4e49\u6d88\u606f\uff0c\u5e76\u5728\u5ba2\u6237\u7aef\u81ea\u884c\u5904\u7406\u6d88\u606f\u53ca\u6784\u5efa\u901a\u77e5\u680f\uff0c\u53ea\u9700<code>setPushIntentServiceClass<\/code>\uff0c\u4e0d\u80fd<code>setMessageHandler<\/code>\uff0c\u4e24\u8005\u4e0d\u80fd\u540c\u65f6\u8bbe\u7f6e\u751f\u6548<\/p>\n<pre><code class=\"language-java\">\/\/mPushAgent.setMessageHandler(MyUmengMessageHandler.getInstance(context));\n\/\/mPushAgent.setNotificationClickHandler(notificationClickHandler);\nmPushAgent.setPushIntentServiceClass(PushService.class);<\/code><\/pre>\n<h2>android:process<\/h2>\n<p>\u5207\u52ff\u8bbe\u7f6e<\/p>\n<pre><code>android:process=&quot;:push&quot;<\/code><\/pre>\n<p>\u5426\u5219\u72ec\u7acb\u8fdb\u7a0b\u83b7\u5f97\u5168\u5c40\u53d8\u91cf\u7684\u503c\u4e0e\u4e3b\u8fdb\u7a0b\u4ea7\u751f\u4e0d\u540c\u6b65\u73b0\u8c61<\/p>\n<h2>Time-out while trying to bind Service<\/h2>\n<p>\u5982\u679c\u53d1\u73b0\u62a5\u9519\uff1a<\/p>\n<pre><code>2019-10-26 16:00:23.633 336-336\/system_process W\/JobServiceContext: Time-out while trying to bind 713f514 #u0a73\/21000 com.lianlianpay.llterminal\/.service.PushService, dropping.\n2019-10-26 16:00:23.635 13259-13259\/? I\/yezhou: PushService.onDestroy<\/code><\/pre>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a\u6ce8\u91ca\u6216\u5220\u9664<code>onBind<\/code>\u65b9\u6cd5<\/p>\n<pre><code class=\"language-java\">\/\/@Nullable\n\/\/@Override\n\/\/public IBinder onBind(Intent intent) {\n\/\/    return null;\n\/\/}<\/code><\/pre>\n<h2>\u6784\u5efa\u901a\u77e5\u680f<\/h2>\n<p>\u4eceAndroid 8.0\u5f00\u59cb\uff0cNotificationManager\u9700\u8981\u521b\u5efaNotificationChannel\uff0c\u7136\u540e\u8c03\u7528createNotificationChannel\u628aNotificationChannel\u4f20\u9012\u8fdb\u53bb\uff0c\u5e76\u4e14\u901a\u8fc7setChannelId\u8bbe\u7f6e\u76f8\u5e94\u7684id<\/p>\n<pre><code class=\"language-java\">public void buildNotification() {\n    manager = (NotificationManager) mContext.getSystemService(mContext.NOTIFICATION_SERVICE);\n    Notification.Builder builder = new Notification.Builder(mContext);\n    \/\/\u89e3\u51b3Android8.0\u6536\u4e0d\u5230\u6d88\u606f\u95ee\u9898\n    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {\n        NotificationChannel mChannel = new NotificationChannel(PUSH_CHANNEL_ID, PUSH_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);\n        manager.createNotificationChannel(mChannel);\n        builder.setChannelId(PUSH_CHANNEL_ID);\n    }\n\n    Intent intent = new Intent(mContext, ReveiveEmailActivity.class);\n    Bundle bundle = new Bundle();\n    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);\n\n    builder.setContentTitle(&quot;appblog&quot;);\n    builder.setContentText(&quot;AppBlog.CN&quot;);\n    builder.setDefaults(Notification.DEFAULT_ALL);\n    builder.setContentIntent(pendingIntent);\n    builder.setSmallIcon(R.mipmap.ic_launcher);\n    builder.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher));\n    builder.setAutoCancel(true);\n\n    manager.notify(id++, builder.build());\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>setPushIntentServiceClass\u65e0\u6548 \u91c7\u7528mPushAgent.setPushIntentS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[311],"tags":[322],"class_list":["post-1284","post","type-post","status-publish","format-standard","hentry","category-android-advance","tag-322"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1284","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=1284"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1284\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}