Skip to content

dont recived notification when app in background or killed just on android 8 and later #941

Open

Description

@mehdidavarpanah66

push notification display in my app in android 8 and later when app is open but when app are in bakground or killed dont display
but in lower version i havent problems

-->

Activity

  1. google-oss-bot commented on Sep 2, 2019

    @google-oss-bot

    This issue does not seem to follow the issue template. Make sure you provide all the required information.

  2. mehdidavarpanah66 commented on Sep 2, 2019

    @mehdidavarpanah66
    Author

    this is mani fest

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    
    <application
        android:name=".Utils.FontDastnevis"
        android:allowBackup="true"
        android:icon="@mipmap/icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/icon"
        android:screenOrientation="portrait"
        android:supportsRtl="false"
        android:theme="@style/AppTheme"
        tools:replace="android:supportsRtl">
        <service
            android:name=".Utils.GetCitiesService"
            android:enabled="true"
            android:exported="true"></service>
    




                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/icon" />
        <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
             notification message. See README(https://goo.gl/6BKBk7) for more. -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/colorAccent" />
        <!-- [END fcm_default_icon] -->
        <!-- [START fcm_default_channel] -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="@string/default_notification_channel_id" />
        <activity android:name=".Main.MainActivity" >
    
        </activity>
        <activity android:name=".Categories.CategoryActivity" />
        <activity android:name=".Vip.VipActivity" />
        <activity android:name=".Question.QuestionActivity" />
        <activity android:name=".SearchActivity" />
        <activity android:name=".Categories.Group3Activity" />
        <activity android:name=".Views.Activities.AboutActivity" />
        <activity android:name=".Views.Activities.BasketActivity" />
        <activity android:name=".Views.Activities.DetailsActivity" />
        <activity android:name=".Views.Activities.FilterActivity" />
        <activity android:name=".Views.Activities.OrderHistoryActivity" />
        <activity android:name=".Views.Activities.ProductActivity" />
        <activity android:name=".Compare.CompareActivity" />
        <activity android:name=".Basket.Basket1Activity" />
        <activity android:name=".Basket.Basket2Activity" />
        <activity android:name=".Views.Activities.ProductCompareActivity" />
        <activity android:name=".Views.Activities.FavoriteActivity" />
        <activity
            android:name=".Login.RegisterActivity"
            android:windowSoftInputMode="adjustResize" />
        <activity
            android:name=".Login.Register2Activity"
            android:windowSoftInputMode="adjustPan" />
        <activity
            android:name=".Login.ActiveCodeActivity"
            android:windowSoftInputMode="adjustResize" />
        <activity
            android:name=".Login.LoginActivity"
            android:windowSoftInputMode="adjustResize" />
    
        <receiver
            android:name=".Utils.NetworkReciver"
            android:enabled="true">
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
                <action android:name="android.net.wifi.STATE_CHANGE" />
            </intent-filter>
        </receiver>
    
        <activity android:name=".Utils.DisconnectedActivity" />
    
        <service android:name=".Firebase.MyFirebaseMessagingService">
            <intent-filter>
    
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <service android:name=".Firebase.MyFirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
    
        <activity android:name=".Basket.Basket3Activity" />
        <activity android:name=".Basket.onlinePay" />
        <activity android:name=".Basket.finalBasketActivity"></activity>
    </application>
    
  3. mehdidavarpanah66 commented on Sep 2, 2019

    @mehdidavarpanah66
    Author

    package www.partopars.com.bigbag.Firebase;

    import android.app.Notification;
    import android.app.NotificationChannel;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.Context;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.media.RingtoneManager;
    import android.net.Uri;
    import android.os.Build;
    import android.support.v4.app.NotificationCompat;
    import android.support.v4.app.NotificationManagerCompat;
    import android.support.v4.content.LocalBroadcastManager;
    import android.util.Log;

    import com.google.firebase.messaging.FirebaseMessagingService;
    import com.google.firebase.messaging.RemoteMessage;

    import www.partopars.com.bigbag.Main.MainActivity;
    import www.partopars.com.bigbag.R;

    /**
    *
    */

    public class MyFirebaseMessagingService extends FirebaseMessagingService {
    public final String CHANEL_ID="088";
    public static final String TAG="firebasemessage";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "onMessageReceived: ");
        sendNotification(remoteMessage.getNotification().getBody());
    }
    
    //This method is only generating push notification
    //It is same as we did in earlier posts 
    private void sendNotification(String messageBody) {
       Log.d(TAG,messageBody);
      createNotification(messageBody);
    }
    
    
    private void createNotification(String messageBody) {
        // Create the NotificationChannel, but only on API 26+ because
        // the NotificationChannel class is new and not in the support library
    
    
        Log.d(TAG, "createNotification: ");
    
    
    
    
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);
    
        String channelId = getString(R.string.default_notification_channel_id);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                        .setSmallIcon(R.mipmap.icon)
                        .setContentTitle("bigbag")
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent);
    
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    
        // Since android Oreo notification channel is needed.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId,
                    "Channel human readable title",
                    NotificationManager.IMPORTANCE_DEFAULT);
            notificationManager.createNotificationChannel(channel);
        }
    
        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
    

    // Intent intent = new Intent(this, MainActivity.class);
    //
    //
    //
    // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
    // PendingIntent.FLAG_ONE_SHOT);
    //
    //
    // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    // Log.d(TAG, "createNotification: "+Build.VERSION.SDK_INT);
    // int importance = NotificationManager.IMPORTANCE_DEFAULT;
    // NotificationChannel channel = new NotificationChannel(CHANEL_ID, "088", importance);
    // channel.setDescription("bigbag");
    // // Register the channel with the system; you can't change the importance
    // // or other notification behaviors after this
    // NotificationManager notificationManager = getSystemService(NotificationManager.class);
    // notificationManager.createNotificationChannel(channel);
    // Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    //
    //
    // Notification.Builder builder=new Notification.Builder(getApplicationContext(),CHANEL_ID)
    // .setSmallIcon(R.mipmap.icon)
    // .setContentTitle("گروه تجاری بیگ بگ")
    // .setContentText(messageBody)
    // .setSound(defaultSoundUri)
    // .setContentIntent(pendingIntent)
    // .setAutoCancel(true)
    // .setPriority(Notification.PRIORITY_DEFAULT);
    //
    // NotificationManagerCompat notificationManagerCompat=NotificationManagerCompat.from(getApplicationContext());
    // notificationManager.notify(001,builder.build());
    // }else{
    // Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
    // .setSmallIcon(R.mipmap.icon)
    // .setContentTitle("گروه تجاری بیگ بگ")
    // .setContentText(messageBody)
    // .setSound(defaultSoundUri)
    // .setAutoCancel(true)
    // .setContentIntent(pendingIntent);
    //
    // Notification notification = notificationBuilder.build();
    // //notification.sound=Uri.parse("android.resource://www.partopars.com.musicplayer/" + R.raw.apple_ring);
    //
    // NotificationManager notificationManager =
    // (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    //
    // notificationManager.notify(0, notification);
    // }
    }
    }

  4. KORuL commented on Oct 8, 2019

    @KORuL
  5. ambr89 commented on Dec 18, 2019

    @ambr89

    Does anyone found the solution?

    I've Android device and I receive the push message only if ap is in the background but not killed.

    Android 8.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions