2016-07-08 14 views
6

मैंने अपने एंड्रॉइड ऐप में पुश अधिसूचना के लिए फायरबेस को लागू किया। मैंने टोकन को पंजीकृत करने के लिए दो सेवाओं को लागू किया और पता चला जब अधिसूचना बनाने के लिए। जब मेरा ऐप लॉन्च होता है तो यह काम कर रहा है लेकिन जब मेरा ऐप बंद हो जाता है तो यह काम नहीं कर रहा है।फायरबेस पुश अधिसूचना

public class FirebaseinstanceIdService extends FirebaseInstanceIdService { 

    @Override 
    public void onTokenRefresh() { 
     String refreshedToken = FirebaseInstanceId.getInstance().getToken(); 
     Log.e("Firebase", refreshedToken); 
     MainActivity.setFirebaseToken(refreshedToken); 
    } 

} 

public class MyFirebaseMessageService extends FirebaseMessagingService { 

    private static final String TAG = "MyFirebaseMsgService"; 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     //Displaying data in log 
     //It is optional 
     Log.e(TAG, "From: " + remoteMessage.getFrom()); 
     Log.e(TAG, "Notification Message Body: " + remoteMessage.getData().get("title")); 

     //Calling method to generate notification 
     sendNotification(remoteMessage.getData()); 
    } 

    //This method is only generating push notification 
    //It is same as we did in earlier posts 
    private void sendNotification(Map<String, String> notification) { 
     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); 

     Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setContentTitle(notification.get("title")) 
      .setContentText(notification.get("body")) 
      .setAutoCancel(true) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 

     NotificationManager notificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     notificationManager.notify(0, notificationBuilder.build()); 
    } 
} 

और मेरे प्रकट:

<service 
     android:name=".FirebaseinstanceIdService"> 
     <intent-filter> 
      <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 
     </intent-filter> 
    </service> 
    <service 
     android:name=".MyFirebaseMessageService"> 
     <intent-filter> 
      <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
     </intent-filter> 
    </service> 

और मेरे अनुरोध:

{ 
    "to": "ex1CtVz5bbE:APA91bHiM_BCun62A9iCobF1yV26Dwn-hYCDhkYPoWEG5ZdqH0P28UsE5q1v7QibwAX7AJ290-9en9L6f548_2b7WEbJ8RPEWlIotLczjjCP7xEOWqeJk6Iz44vilWYvdu4chPwfsvXD", 
    "data": { 
     "title": "Notification", 
     "body": "Message", 
    } 
} 

मैं पहले से ही StackOverflow में कुछ समाधान पाया लेकिन यह मेरे मामले में काम नहीं करता। मेरे पास एक एपीआई रेस्ट है जो एपीआई अनुरोध पोस्ट को कॉल करता है: https://fcm.googleapis.com/fcm/send

तो, मेरा सवाल है: क्या ऐप बंद होने पर फायरबेस ही पुश अधिसूचना संभालता है और कैसे?

अपने जवाब

+0

क्या आप * स्टैक ओवरफ्लो * समाधान भी निर्दिष्ट कर सकते हैं जिन्हें आपने कोशिश की है और काम नहीं किया है? यह इस कारण को कम करने में मदद करेगा। –

+0

एपीआई कॉल में पैरामीटर अधिसूचना ऑब्जेक्ट या डेटा ऑब्जेक्ट हो सकता है, मैंने दोनों के साथ प्रयास किया और यह काम नहीं करता है। – yozzy

+0

अपना manifest.xml – Saini

उत्तर

5

जब एप्लिकेशन बंद हो FCM समर्थन सूचनाएं करता है के लिए धन्यवाद। आपका कोड ठीक प्रतीत होता है, इसलिए मुझे लगता है कि बैटरी अर्थशास्त्री (या पावर सेवर) आपकी सूचनाओं को मार सकते हैं। मुझे अपने एसस जेनफ़ोन पर ऐसी समस्याएं थीं, उन्हें हुवेई और शीओमी का उपयोग करने के मामलों में भी बताया गया था। अगर कोई है तो बस उन्हें अक्षम करें या अपवाद सूची में अपना ऐप जोड़ें। एंड्रॉइड की हालिया रिलीज में भी एक नया पावर-सेविंग मोड है, इसे भी अक्षम करने का प्रयास करें।

+0

ठीक है मैं एक Huawei का उपयोग करें। आपके उत्तर – yozzy

+0

@yozzy के लिए धन्यवाद, क्या यह आपकी समस्या का समाधान करता है? – inthy

+0

धन्यवाद, मैं सिर्फ एक एचटीसी पर परीक्षण करता हूं और यह बहुत अच्छा काम करता है। क्या आप इस मुद्दे को फोन पर संगत नहीं करने का विचार करते हैं? – yozzy

संबंधित मुद्दे