2016-05-27 12 views
6

मैं फायरबेस क्लाउड मैसेजिंग का उपयोग करने की कोशिश कर रहा हूं। मुझे टोकन प्राप्त हो रहा है लेकिन इसे कंसोल से कोई सूचना नहीं मिल रही है। यहाँ मेरी प्रकट है:फायरबेस क्लाउड मैसेजिंग काम नहीं कर रहा

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="careerage.jobseeker.app" 
android:hardwareAccelerated="true" 
android:versionCode="1" 
android:versionName="0.0.1"> 

<uses-sdk 
    android:minSdkVersion="16" 
    android:targetSdkVersion="23" /> 

<supports-screens 
    android:anyDensity="true" 
    android:largeScreens="true" 
    android:normalScreens="true" 
    android:resizeable="true" 
    android:smallScreens="true" 
    android:xlargeScreens="true" /> 

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

<android:uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<android:uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

<application 
    android:hardwareAccelerated="true" 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:supportsRtl="true"> 
    <activity 
     android:name=".MainActivity" 
     android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" 
     android:label="@string/activity_name" 
     android:launchMode="singleTop" 
     android:theme="@android:style/Theme.DeviceDefault.NoActionBar" 
     android:windowSoftInputMode="adjustResize"> 
     <intent-filter android:label="@string/launcher_name"> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <service 
     android:name=".TokenService"> 
     <intent-filter> 
      <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 
     </intent-filter> 
    </service> 
    <service 
     android:name=".NotificationService"> 
     <intent-filter> 
      <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
     </intent-filter> 
    </service> 
</application> 

और मेरे कोड का नमूना से के रूप में लगभग एक ही है:

public class NotificationService extends FirebaseMessagingService { 

private void sendNotification(String messagebody) { 
    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.drawable.icon) 
      .setContentTitle("Notified") 
      .setContentText(messagebody) 
      .setAutoCancel(true) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 

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

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

private void sendSnackbar(String messagebody) 
{ 
    Toast.makeText(this,"Notified",Toast.LENGTH_LONG).show(); 
} 

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 
    Toast.makeText(this,"Message Received",Toast.LENGTH_LONG).show(); 

     Log.d("Notification Received",remoteMessage.getNotification().getBody()); 

     sendNotification(remoteMessage.getNotification().getBody()); 
    sendSnackbar(remoteMessage.getNotification().getBody()); 
} 

} 

मैं प्रश्न यहाँ Firebase cloud messaging notification not received by device जाँच की, लेकिन अभी भी यह काम नहीं कर रहा है।

+0

क्या आप कंसोल के माध्यम से पेलोड भेज रहे हैं? –

+0

@McAwesomville Yep और इसके नमूने –

+0

क्षमा करें। मैंने पहले नहीं देखा था, आपने पहले ही इसका उल्लेख किया है। वैसे भी, तो आपके 'ऑन मैसेज रिसीव()' में लॉग इन अधिसूचना भेजने के बाद दिखाई नहीं दे रहे थे? क्या अग्रभूमि या पृष्ठभूमि में ऐप था? –

उत्तर

1

सेवा एपीआई कॉल का उपयोग कर संदेश भेजने का प्रयास करें। यह आपको प्रतिक्रिया कोड और प्रतिक्रिया जेसन प्रदान करेगा जो आपको एफसीएम काम नहीं करने का कारण प्राप्त करने में मदद कर सकता है।

सेवा कॉल उपयोग यहाँ Firebase onMessageReceived not called when app in background

-1

आप नीचे दिए गए की तरह पूरे पैकेज नाम के साथ में सेवा बदलने की जरूरत है उत्तर दिया,

<service 
    android:name="your.package.name.TokenService"> 
    <intent-filter> 
     <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 
    </intent-filter> 
</service> 
<service 
    android:name="your.package.name.NotificationService"> 
    <intent-filter> 
     <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
    </intent-filter> 
</service> 

कृपया मुझे बताएं कि यह काम नहीं कर रहा है।

+1

यह गलत है। एंड्रॉइड जानता है कि कहां देखना है –

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