我尝试用这种方式在华为设备上实现推送通知:
目标
(2)当我的app未启动或在后台时,应显示标准弹出。点击弹出窗口打开我的应用程序,传递数据消息中的数据,这样我的应用程序就可以处理它。
实施
通过设置FOREGROUND_SHOW:false,我能够实现(1)。然而,对于(2),当我从服务器发送推送通知时,当我的应用程序不活动时,设备上什么也没有发生!
logcat的输出(详细):
2021-07-05 10:48:02 30209-1281/? W/AwareLog: AwareMem_Reclaim: getPssForPid error skip! procName=com.huawei.hwid.core
2021-07-05 10:48:02 923-953/? D/: HibSTrategy::HibStrategySwapCandidateProcessAdd packageName com.huawei.android.pushagent
2021-07-05 10:48:02 30898-6851/? I/PGServer: getTopFrontApp. calling pkg: android
2021-07-05 10:48:02 10315-10315/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:02 10315-10315/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:02 923-3399/? D/AwareLog: HiberManagerService::DoReclaim ok, pid=2351, reclaimMode=hiber_anon
2021-07-05 10:48:02 923-3399/? D/AwareLog: GetReclaimResult:reclaimKb=0, swapKb=0, swapUs=574
2021-07-05 10:48:02 923-3399/? D/: HibStrategy::HibStrategySwapCandidateProcessRemove packageName is com.huawei.android.pushagent
2021-07-05 10:48:02 923-3399/? D/AwareLog: HiberManagerService::SendMessageToHiberTask successful
2021-07-05 10:48:02 10313-10313/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:02 10313-10313/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:02 31536-32767/? I/PushLog110102300: [SocketRead_17:39:13-72]enter cancelAlarm(Action=com.huawei.android.push.intent.RESPONSE_FAIL
2021-07-05 10:48:02 31536-32767/? I/PushLog110102300: [SocketRead_17:39:13-72]process cmdid to receive from pushSrv:44, subCmdId:FF
2021-07-05 10:48:02 31536-32767/? I/PushLog110102300: [SocketRead_17:39:13-72]dispatchIntent over
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50]process push message cmdid from pushSrv:44, subCmdId:FF
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50]msgType: 2 [0:PassBy msg, 1:System notification, 2:normal notification, 3:HCM PassBy msg]
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50] closeTokenCheck: false
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50]custom channelId is empty
2021-07-05 10:48:02 31536-31992/? E/SecurityComp10105302: kj: content or algorithm is null.
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50]accountVerify profileId is empty.
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50]app declare HmsMessageService num is: 1
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50]no running process.
2021-07-05 10:48:02 31536-31992/? E/PushLog110102300: [ReceiverDispatcher-50]no permission to start activity, appPackageName:my.packageName, isUri:false
2021-07-05 10:48:02 31536-31992/? E/PushLog110102300: [ReceiverDispatcher-50]no permission to start activity:my.packageName,msgID:0E61558047A96124
2021-07-05 10:48:02 31536-31992/? E/PushLog110102300: [ReceiverDispatcher-50]NC message is invalid, can not display.
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50]process cmdid to send to pushSrv:45, subCmdId:FF
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50]send msg to remote srv success
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50]handleMessageResponse the response msg is :45,msgId:0E61558047A96124,displayPkgName:my.packageName,flag:94
2021-07-05 10:48:02 31536-31992/? I/PushLog110102300: [ReceiverDispatcher-50]enter AlarmTools:setInexactAlarm(intent:Intent { act=com.huawei.action.push.intent.CHECK_CHANNEL_CYCLE pkg=android } interval:1200000ms
2021-07-05 10:48:02 30209-3902/? I/AlarmManager: remove alarm:Alarm{f82f7b7 type 1 when 1625454447206 PendingIntent{b60bf97: PendingIntentRecord{d9d6467 android broadcastIntent}}android procName com.huawei.android.pushagent.PushService} according to operation:9c75eb6
2021-07-05 10:48:02 30209-30237/? I/AppEyeFwkBlock: do monitor
2021-07-05 10:48:02 10324-10324/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:02 10324-10324/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:02 10329-10329/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:02 10329-10329/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:02 711-711/? I/SurfaceFlinger: doPartialComposeImpl: reject partial compose request.
2021-07-05 10:48:02 711-711/? I/SurfaceFlinger: doPartialComposeImpl: reject partial compose request.
2021-07-05 10:48:03 10337-10337/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:03 10337-10337/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:03 10336-10336/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:03 10336-10336/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:03 30209-30542/? I/TrafficMonitor: expired arrive. level:-1
2021-07-05 10:48:03 30209-30542/? I/TrafficMonitor: during_ms:2001,period_ms:2000
2021-07-05 10:48:03 30209-30542/? I/TrafficMonitor: count:330,rx_sum:0,tx_sum:0,rxBytes:0,during_ms:2001,rx_speed:0.0,tx_speed:0.0,rto:0.0
2021-07-05 10:48:03 30209-30542/? I/HuaweiWifiWatchdogStateMachine: Get speed information rx_speed = 0 ,tx_speed = 0 ,isSpeedOk = false ,mBestSpeedInPeriod = 0
2021-07-05 10:48:03 30713-6875/? E/HwNaturalBase: [Binder:30713_8]: Failed to check permission, check database/table permission failed.
2021-07-05 10:48:03 30713-6875/? E/HwNaturalBase: [Binder:30713_8]: dsCollectEncrypt-0: Failed to registerListener, check database/table permission failed.
2021-07-05 10:48:03 27863-28586/? E/HwNaturalBaseClient: Failed to register observer for RawFgAPPEvent.
2021-07-05 10:48:03 27863-28586/? E/HwNaturalBaseClient: Failed to register remote observer.
2021-07-05 10:48:03 27863-28586/? E/OdmfHelper: CAWARENESS: subscribeManagedObject isSuccess = false
2021-07-05 10:48:03 10344-10344/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:03 10344-10344/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:03 10349-10349/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:03 10349-10349/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:03 10354-10354/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:03 10354-10354/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:03 923-953/? W/: Failed to SetQos, ret=-1, tid=10359, qos=1
2021-07-05 10:48:03 923-953/? E/AwareLog: iawared: GetFileContent open /proc/10354/task/10360/cpuset fail errno(2)!
2021-07-05 10:48:03 923-953/? W/: Failed to SetQos, ret=-1, tid=10360, qos=1
2021-07-05 10:48:03 10357-10357/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:03 10357-10357/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:03 10364-10364/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:03 10364-10364/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:03 10369-10369/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:03 10369-10369/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:04 711-711/? I/SurfaceFlinger: doPartialComposeImpl: reject partial compose request.
2021-07-05 10:48:04 711-711/? I/SurfaceFlinger: doPartialComposeImpl: reject partial compose request.
2021-07-05 10:48:04 10377-10377/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:04 10377-10377/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:04 10376-10376/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:04 10376-10376/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:04 10384-10384/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:04 10384-10384/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:04 10389-10389/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:04 10389-10389/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:04 705-705/? E/WifiHAL: enter wifi_get_link_stats
2021-07-05 10:48:04 30209-30543/? E/WificondControl: Noise: -94, Snr: 127, Chload: 55
2021-07-05 10:48:04 30209-30543/? V/HwWifiServiceFactory: get AllImpl object = com.android.server.wifi.HwWifiServiceFactoryImpl@212f9be
2021-07-05 10:48:04 10394-10394/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:04 10394-10394/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:04 10397-10397/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:04 10397-10397/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:04 711-711/? I/SurfaceFlinger: doPartialComposeImpl: reject partial compose request.
2021-07-05 10:48:04 10404-10404/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:04 10404-10404/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:04 30707-31174/? I/SpeedTestNotifier: is low speed scene
2021-07-05 10:48:04 10409-10409/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:04 10409-10409/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:05 10414-10414/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:05 10414-10414/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:05 10419-10419/? I/HiTraceC: entered LogRegisterGetIdFun
2021-07-05 10:48:05 10419-10419/? I/HiTraceC: entered HiTraceInit
2021-07-05 10:48:05 30713-6875/? E/HwNaturalBase: [Binder:30713_8]: Failed to check permission, check database/table permission failed.
2021-07-05 10:48:05 30713-6875/? E/HwNaturalBase: [Binder:30713_8]: dsCollectEncrypt-0: Failed to registerListener, check database/table permission failed.
2021-07-05 10:48:05 27863-28586/? E/HwNaturalBaseClient: Failed to register observer for RawFgAPPEvent.
2021-07-05 10:48:05 27863-28586/? E/HwNaturalBaseClient: Failed to register remote observer.
2021-07-05 10:48:05 27863-28586/? E/OdmfHelper: CAWARENESS: subscribeManagedObject isSuccess = false
2021-07-05 10:48:05 10424-10424/? I/HiTraceC: entered LogRegisterGetIdFun
我的代码
我通过REST调用发送到华为API的JSON对象的有效负载:
{
validate_only: false,
message: {
android: {
notification: {
foreground_show: false,
title: "My title",
body: "Message body",
click_action: {
// 1 = opens a custom app page. foreground_show: false requires this!
type: 1,
action: "com.huawei.codelabpush.intent.action.test",
}
}
},
token: [ 'myDeviceTokenHere' ],
}
}
根据我的研究,这可能与我的AndroidManifest.xml文件有关。特别是,我在活动标记下设置了exports:true:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="my.packageName">
<!-- Required to fetch data from the internet -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
<uses-permission android:name="com.android.vending.BILLING" />
<!-- For QR scanner -->
<uses-permission android:name="android.permission.CAMERA" />
<application
android:name="androidx.multidex.MultiDexApplication"
android:requestLegacyExternalStorage="true"
android:allowBackup="false"
android:fullBackupContent="false"
android:label="packageName"
android:icon="@mipmap/launcher_icon">
<!-- Firebase messaging -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_notification_icon" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/ic_stat_notification_icon" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/notification_channel_id" />
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
</activity>
<!-- Facebook Login configuration -->
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" />
<activity android:name="com.facebook.CustomTabActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
问题
如何解决当我的应用程序在后台时通知不显示的问题?
根据您提供的日志,建议您检查是否对要在通知栏单击事件中打开的活动设置了permission或export=false
。
我想为一个聊天应用程序实现FCM推送通知服务,我遵循Firebase文档中的步骤,当通知从Firebase控制台发送到我的设备时,我会得到通知。当我尝试使用http post to https://FCM.googleapis.com/FCM/send通过FCM将通知通过服务器端发送到设备时: 当应用程序处于活动状态并且我正在将此通知发送到我的设备时,Im在我的控制台日志中收到以下消息,所以我认为
index.js中的代码 bgmessaging.js中的代码负责应用程序在后台时的推送 为了在应用程序处于前台时带来图像,我使用了下面的代码:-
当应用程序在后台时,如何更新包含数据负载的Firebase推送通知?有没有办法在通知中指定通知id给Firebase API? 完整的项目在github https://github.com/akshatashan/FireBaseCloudMessagingDemo中
null 而当app在后台时,系统托盘总是显示一个到达一个重复的通知(如收到通知a,系统托盘显示2个通知a)。 怎么解决这个问题? 编辑:添加的代码 我扩展了 类,并在 方法中包含该类 这是项目中我使用NotificationManager的唯一部分。 另外,我尝试在这个方法上添加一个日志。当应用程序处于前台时调用onMessageReceived。当应用程序在后台时,它不会被调用
当应用程序处于前台时,我可以成功地接收带有图像的通知和数据消息。 当应用程序在后台/kill时,onMessageReceed(message)没有调用,所以我使用getIntent(),我得到了数据,但当应用程序在后台时,android os会使用系统托盘自动显示通知,但图像无法显示。 所以我的问题是用图像显示通知文本? 我使用django api发送通知和发送的数据如下所示 下面是我的onMe
我通过FCM实现了推送通知。当应用程序从我的服务器获得一个新的通知时,通知面板会被我在notificationcompat.builder中设置的图标所注意,但消息不会作为弹出预览。我尝试设置优先级,样式,类别,但通知仍然没有显示。当我滚动时,我可以看到通知。 我在两种不同的设备操作系统(6.0.1和5.0.1)上尝试了这个应用程序,也是我的后端C#解决方案--两种方法都不弹出通知消息和通知 Fi