FirebaseMessagingService使用one plus 3 android oreo 8.0无法在后台运行

时间:2018-03-13 09:55:40

标签: android firebase-cloud-messaging android-8.0-oreo android-8.1-oreo oneplusthree

当应用未运行并从最近的应用列表中删除时,永远不会调用Firebase onMessageReceived。 我正在使用Firebase并从我的服务器向我的应用程序发送数据有效负载通知,我已经尝试使用JobScheduler每1分钟启动MyFirebaseMessagingService,以防系统终止我的服务但这种方法对One Plus无效3。 我知道android增加后台服务的限制以优化电池使用,但这种限制是否会影响FCM服务?

这是我的消息字符串:

{
"notification": {
    "title": "Hello",
    "body": "Notification",
    "badge": 1,
    "icon": "app_icon",
    "color": "#ffffff",
    "sound": "default",
    "clickAction": "home",
    "tag": "parent_ccid_6"
},
"message": {
    "priority": "high",
    "type": "daily_tips",
    "data": {
        "parent_ccid": "parent_ccid_6",
        "id": "2",
        "sound": "default"
    }
},

}

这是我的服务清单

 <service
        android:name=".util.FCM.MyFirebaseMessagingService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>

4 个答案:

答案 0 :(得分:0)

您必须使用上述Nougat的通知频道

样品

        int notifyID = 1;
        String CHANNEL_ID = "my_channel_01";
         // The id of the channel.
        CharSequence name = "channel ram";
         // The user-visible name of the channel.
        String groupId = "Building654651";
        CharSequence groupName = "BuilgingHub123";
        int importance = 0;
            importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
 Notification notification = new Notification.Builder(this)
                .setContentTitle(getString(R.string.app_name))
                .setContentText(messageBody)
                .setSmallIcon(R.drawable.ic_notifi).setColor(Color.parseColor("#FFA23B"))
                .setChannelId(CHANNEL_ID)
                .build();
  NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.createNotificationChannelGroup(new NotificationChannelGroup(groupId, groupName));
        mNotificationManager.createNotificationChannel(mChannel);
            mNotificationManager.notify(notifyID, notification);

答案 1 :(得分:0)

当应用程序处于后台时onMessageReceived永远不会按照android文档调用。 链接: - https://firebase.google.com/docs/cloud-messaging/android/receive

当应用程序处于后台时,通知会传送到设备的系统托盘,并且将调用应用程序的默认意图(即启动器屏幕),您必须在此屏幕上处理该通知。

其他解决方案是您可以删除&#34;通知&#34;来自有效负载的关键字,您可以在应用程序处于后台时收到通知,并且将调用onMessageReceived。

答案 2 :(得分:0)

我没有找到任何通过代码解决此问题的解决方案。 恢复通知的唯一方法是转到设置并从电池优化设置中选择“不优化”,它在后台运行正常,否则将不会触发通知处理程序。 我在One plus 3上遇到了所有已安装应用程序的问题。

答案 3 :(得分:0)

尝试<form method="post" action="{{ route('profile.update') }}" autocomplete="off" enctype="multipart/form-data"> @csrf @method('put') <h6 class="heading-small text-muted mb-4">{{ __('User information') }}</h6> @include('alerts.success') @include('alerts.error_self_update', ['key' => 'not_allow_profile']) <div class="pl-lg-4"> <div class="form-group{{ $errors->has('name') ? ' has-danger' : '' }}"> <label class="form-control-label" for="input-name">{{ __('Name') }}</label> <input type="text" name="name" id="input-name" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" placeholder="{{ __('Name') }}" value="{{ old('name', auth()->user()->name) }}" required autofocus> @include('alerts.feedback', ['field' => 'name']) </div> <div class="form-group{{ $errors->has('email') ? ' has-danger' : '' }}"> <label class="form-control-label" for="input-email">{{ __('Email') }}</label> <input type="email" name="email" id="input-email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" placeholder="{{ __('Email') }}" value="{{ old('email', auth()->user()->email) }}" required> @include('alerts.feedback', ['field' => 'email']) </div> <div class="text-center"> <button type="submit" class="btn btn-success mt-4">{{ __('Save') }}</button> </div> </div> </form> true ”。在您的Android清单文件中。