I've got Firebase building without any warnings using Eclipse (see related: Unable to find obfuscated Firebase class in Eclipse)
I try to send a test notification, however I'm not getting anything. I'm using a library project as well. This is my code:
AndroidManifest.xml
<application />
...
<!-- ==================================
FIREBASE
=================================== -->
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".MyFirebaseInstanceIdService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
....
</application>
These files are practically straight from the samples:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
public static final String PUSH_NOTIFICATION_TEXT = "pushnotificationtext";
private static final String TAG = "Firebase";
public static final int NOTIFICATION_ID = 1;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Handle data payload of FCM messages.
String messageId = remoteMessage.getMessageId();
RemoteMessage.Notification notification = remoteMessage.getNotification();
Map<String, String> data = remoteMessage.getData();
Log.d(TAG, "FCM Message Id: " + messageId);
Log.d(TAG, "FCM Notification Message: " + notification);
Log.d(TAG, "FCM Data Message: " + data);
sendNotification(this, notification.toString());
}
// Put the GCM message into a notification and post it.
private void sendNotification(Context context, String message) {
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
final Intent intent = new Intent(context, Splash.class);
//intent.putExtras(bundle);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//Save push notification message to show when app starts
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
sp.edit().putString(PUSH_NOTIFICATION_TEXT, message).commit();
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setAutoCancel(true)
.setVibrate(new long[] { 0, 500, 200, 500, 200, 500 })
.setContentIntent(contentIntent)
.setContentTitle(context.getString(R.string.app_name))
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setContentText(message)
.setWhen(System.currentTimeMillis()).setOngoing(false);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
}
Other class:
public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {
private static final String TAG = "Firebase";
private static final String FRIENDLY_ENGAGE_TOPIC = "friendly_engage";
/**
* The Application's current Instance ID token is no longer valid
* and thus a new one must be requested.
*/
@Override
public void onTokenRefresh() {
// If you need to handle the generation of a token, initially or
// after a refresh this is where you should do that.
String token = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "FCM Token: " + token);
// Once a token is generated, we subscribe to topic.
FirebaseMessaging.getInstance().subscribeToTopic(FRIENDLY_ENGAGE_TOPIC);
}
}
I send a message via the Firebase console targeting the package name with no luck. I'm uncertain what I should do to get this to work. Do I need to use the google-services.json
file in some way?
Thanks