FirebaseInstanceIdService getToken returning null - android

Im trying to add FCM notifications to my app, but for some reason
FirebaseInstanceId.getInstance().getToken();
is returning null.
Since im not getting any stacktrace my best guess is that FirebaseInstanceIdService is not working
Google Play Services version: 9.6.1
Firebase-messaging version : 9.6.1
added json config file from FirebaseConsole (Tried single file with 2 clients inside it, one for debug and one for release build) and 2 files each for respective build
Iw applied google services plugin at the bottom of my modules gradle script
Included google services in projects root gradle script
Created 2 services from the officail docs:
public class MyFirebaseInsanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
#Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
PreferencesHelper.putSharedPreferencesString(Constants.User.PUSH_NOTIFICATIONS, refreshedToken);
Log.e("TOKEN", "Token: " + FirebaseInstanceId.getInstance().getToken());
}
}
And the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.fc.test">
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="fctest"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="${appName}${appNameSuffix}"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:node="replace">
<service
android:name="com.fc.test.MyFirebaseInsanceIDService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name="com.fc.test.MyFirebaseMessagingService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity
android:name="com.fc.test.view.splash.Splash"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.CenterAnimation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
root Gradle:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
//noinspection GradleDynamicVersion
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
maven { url "http://dl.bintray.com/drummer-aidan/maven" }
maven { url "https://maven.fabric.io/public" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://jitpack.io" }
}
}
ext {
buildToolsVersion = '24.0.1'
compileSdkVersion = 24
minSdkVersion = 15
targetSdkVersion = 24
supportLibraryVersion = '24.2.1'
}
and the main part of the modules Gradle
dependencies {
final PLAY_SERVICES_VERSION = '9.6.1'
final SUPPORT_LIBRARY_VERSION = '24.2.1'
final RETROFIT_VERSION = '2.1.0'
final DAGGER_VERSION = '2.5'
final DEXMAKER_VERSION = '1.4'
final HAMCREST_VERSION = '1.3'
final ESPRESSO_VERSION = '2.2.1'
final RUNNER_VERSION = '0.4'
final BUTTERKNIFE_VERSION = '8.1.0'
def daggerCompiler = "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
def jUnit = "junit:junit:4.12"
def mockito = "org.mockito:mockito-core:1.10.19"
// App Dependencies
compile "com.google.android.gms:play-services-gcm:$PLAY_SERVICES_VERSION"
compile "com.google.firebase:firebase-messaging:$PLAY_SERVICES_VERSION"
compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION"
compile "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
compile "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
compile "com.squareup.retrofit2:adapter-rxjava:$RETROFIT_VERSION"
compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
compile('com.crashlytics.sdk.android:crashlytics:2.6.5#aar') {
transitive = true;
}
}
apply plugin: 'com.google.gms.google-services
Note that im using tools:node="replace" in my root application tag.
Is it possible that FirebaseInstanceIdService is not added to the manifest since it has the same intent filter as mine FirebaseInstanceService and thus not being called?
So my question here would be is there something wrong it the official docs or in my implementation that should cause the Instance token to be null?

After digging up thru old implementations of FCM and generated manifests, I can now say that manifest merger is the problem.
Solution for this problem is adding these classes to the apps manifest manualy
<activity
android:name="com.google.android.gms.common.api.GoogleApiActivity"
android:exported="false"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<service
android:name="com.google.firebase.messaging.FirebaseMessagingService"
android:exported="true" >
<intent-filter android:priority="-500" >
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.fc.debug" />
</intent-filter>
</receiver>
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
android:exported="false" />
<!--
-->
<service
android:name="com.google.firebase.iid.FirebaseInstanceIdService"
android:exported="true" >
<intent-filter android:priority="-500" >
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<provider
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:authorities="com.fc.debug.firebaseinitprovider"
android:exported="false"
android:initOrder="100" />
<receiver
android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="com.google.android.gms.measurement.UPLOAD" />
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.measurement.AppMeasurementService"
android:enabled="true"
android:exported="false" />

While I was doing the migration I had a problem, it was that I didn't receive any Notification. To solve this and If you have your GCM working, don't forget to include your sender ID when you get the Firebase Token. To consult this ID you have to navigate to your Firebase project and click Project Name. Click the Setting icon and select "Project Setting" menu Select "Could Messaging" tab and use sender ID on the page.
And when says to code this:
token = FirebaseInstanceId.getInstance().getToken();
You have to use this:
token = FirebaseInstanceId.getInstance().getToken("YOUR_SENDER_ID", "FCM");
It works for me, I hope this helps you ;)

This worked for me:
String token = FirebaseInstanceId.getInstance().getInstanceId().getResult().getToken();

First genarate "google-services.json" and Add this file in your android studio Like this projectFolder/APP/google-services.json
Add classpath to top level build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Add following plugin and dependencies in app’s build.gradle
apply plugin: 'com.google.gms.google-services'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'
}
Add following Firebase services in your java files
FirebaseIDService.java
package com.galleonsoft.firebase.push;
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class FirebaseIDService extends FirebaseInstanceIdService {
private static final String TAG = "FirebaseIDService";
#Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
// Add custom implementation, as needed.
}
}
MyFirebaseMessagingService.java
package com.galleonsoft.firebase.push;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class MyFirebaseMEssagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
}
Add service in your AndroidMainifest.xml file
<service android:name=".MyFirebaseMEssagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name=".FirebaseIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>

Related

Can't send notifications from Parse Server

I am trying to send push notifications from Bitnami Parse Server (3.1.2) hosted on AWS.
I have the server key and the sender ID from firebase in server.js.
Notifications work from the firebase console but not from parse server (neither from the dashbord nor from REST API). It says it's saved but Pushes Sent appear 0 even though I have two installations.
Any ideas?
Puhes Sent 0
My manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
<application
android:name=".StarterApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DepListActivity" />
<activity android:name=".AngListActivity" />
<activity android:name=".ChangeThePin" />
<activity android:name=".PicActivity" />
<activity android:name=".AddDepActivity" />
<service
android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name="com.parse.fcm.ParseFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
Project Gradle:
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0' // google-services plugin
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
google()
maven { url "https://jitpack.io" }
}
}
ext {
compileSdkVersion = 24
buildToolsVersion = "24.0.1"
minSdkVersion = 17
targetSdkVersion = 24
}
Module gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.parse.starter"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'com.parse.bolts:bolts-tasks:1.3.0'
implementation 'com.github.parse-community.Parse-SDK-Android:fcm:1.19.0'
implementation 'com.github.parse-community.Parse-SDK-Android:parse:1.19.0'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.android.gms:play-services-auth:16.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
apply plugin: 'com.google.gms.google-services'
And server.js
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();
// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var api = new ParseServer({
databaseURI: "",
cloud: "./node_modules/parse-server/lib/cloud-code/Parse.Cloud.js",
appId: "",
masterKey: "",
push: {
android: {
senderId: "",
apiKey: ""
}
},
fileKey: "",
serverURL: ""
});
// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);
var port = 1337;
app.listen(port, function() {
console.log('parse-server running on port ' + port);
});
//Parse Dashboard
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({
apps: [
{
appName: "My Bitnami Parse API",
appId: "",
masterKey: "",
push: {
android: {
senderId: "",
apiKey: ""
}
},
fileKey: "",
production: true,
serverURL: "
}
],
users: [
{
user: "user",
pass: ""
}
], useEncryptedPasswords: true
});
var allowInsecureHTTP = true;
// Serve the Parse Dashboard on the /parsedashboard URL prefix
app.use('/', dashboard);
var portdash = 4040;
app.listen(portdash, function() {
console.log('parse-dashboard running on port ' + portdash);
});

class file for com.google.android.gms.internal.zzbgl not found at remoteMessage.getNotification()

My current emulator play service dependency version is 12.0.1.I added all my firebase dependency with 12.0.1.And it's work fine.But when i call remoteMessage.getNotification() then thrown an exception
class file for com.google.android.gms.internal.zzbgl not found at remoteMessage.getNotification()
Here is my all firebase dependency
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.google.firebase:firebase-database:12.0.1'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
Here is FirebaseMessaging Service Class code
public class FirebaseMessageing extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (remoteMessage.getNotification().getTitle().equals("New Request")){
showNotification(remoteMessage.getNotification().getBody());
}
}
}
i also defined my class into the manifest file
<service android:name=".Service.FirebaseMessageing">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".Service.FirebaseService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
How can i solve this problem.

Fire base onMessageReceived isn't working at all

I've looked over all the answers I could find, the particular function of code isn't working even in foreground. I tried changing the manifest, changing the code, all i get in the logger are these 2 of these things:
D/FA: Logging event (FE): notification_receive(_nr), ...
This is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/avatar"
android:label="#string/app_name"
android:roundIcon="#drawable/avatar"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".StartActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"/>
<service android:name=".GettingDeviceTokenService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".NotificationService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
And here is the notification service:
public class NotificationService extends FirebaseMessagingService {
public static int NOTIFICATION_ID = 1;
private static final String CHANNEL_ID = "1";
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d("+++", remoteMessage.toString());
if (remoteMessage.getData().size() > 0) {
Log.d("dataa", "Data Payload: " + remoteMessage.getData().toString());
}
}
This is the app gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.xghos.Wrenchy"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'net.hockeyapp.android:HockeySDK:5.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.0'
implementation 'com.ethanhua:skeleton:1.1.1'
implementation 'io.supercharge:shimmerlayout:2.1.0'
implementation "com.daimajia.swipelayout:library:1.2.0#aar"
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
}
}
}
apply plugin: 'com.google.gms.google-services'
and the GettingDeviceTokenService:
package com.example.xghos.Wrenchy;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class GettingDeviceTokenService extends FirebaseMessagingService {
#Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.d("DeviceToken ==> ", s);
}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
}
EDIT: the problem was solved by changing the intent filter of the GettingDeviceTokenService from
<action android:name="com.google.firebase.MESSAGING_EVENT" />
to
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
You should consider difference between data message and display message.
Display message has payload with key notification and are automatically displayed when app is in background and also call onMessageReceived() if app is already in foreground.
Data message has payload key data . They always invoke onMessageReceived()
You have registered NotificationService service in your manifest. Since latest update for firebase notifications, the same service will handle new token and received messages. In your case you should register in manifest only GettingDeviceTokenService because you override both methods and remove NotificationService.
Try this way. It worked for me Perfectly.
1. Create a Service
public class YourService extends FirebaseMessagingService {
public static int NOTIFICATION_ID = 1;
#Override
public void onNewToken(String s) {
super.onNewToken(s);
}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
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 mNotifyBuilder = new NotificationCompat.Builder(this, "2")
.setSmallIcon(R.drawable.your_icon)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (NOTIFICATION_ID > 1073741824) {
NOTIFICATION_ID = 0;
}
Objects.requireNonNull(notificationManager).notify(NOTIFICATION_ID++, mNotifyBuilder.build());
}
}
Now add this to Manifest
<service
android:name=".YourService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

evollu/react-native-fcm - ClassNotFoundException

My App runs well, but... when it recives a notification from Firebase it Crash.
I think it's happening because my configuration is bad since i had implemented the "react-native-fcm" example.
I getFCMToken() succesfull.
Do you look any error? Do you know why is happening it? Ideas? HelP!!
CONSOLE ERRORS
package.json
"dependencies": {
"firebase": "^4.8.2",
"lodash": "^4.17.4",
"moment": "^2.20.1",
"react": "16.0.0-alpha.12",
"react-firebase-storage-connector": "^1.1.0",
"react-native": "0.47",
"react-native-fbsdk": "^0.7.0",
"react-native-fcm": "^13.3.1",
"react-native-fetch-blob": "^0.10.8",
"react-native-image-picker": "^0.26.7",
"react-native-modal": "^5.0.0",
"react-native-responsive-image": "^2.2.0",
"react-native-side-menu": "^1.1.3",
"react-native-textinput-effects": "^0.4.2",
"react-native-vector-icons": "^4.5.0",
"react-navigation": "^1.0.0-beta.11",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0",
"slugify": "^1.2.9"
},
app/build.gradlew
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "com.reactnavigationdrawer"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:+"
compile "com.facebook.react:react-native:+" // From node_modules
compile(project(':react-native-fbsdk')) {
exclude(group: 'com.facebook.android', module: 'facebook-android-sdk')
}
compile('com.facebook.android:facebook-android-sdk:4.22.1')
compile ("com.google.android.gms:play-services-base:11.2.0") {
force = true;
}
compile ('com.google.firebase:firebase-core:11.2.0') {
force = true;
}
compile ('com.google.firebase:firebase-auth:11.2.0') {
force = true;
}
compile (project(':react-native-fcm')){
exclude group: "com.google.firebase"
}
compile ("com.google.android.gms:play-services-gcm:11.2.0") {
force = true;
}
compile project(':react-native-vector-icons')
compile project(':react-native-fetch-blob')
compile project(':react-native-image-picker')
}
apply plugin: 'com.google.gms.google-services'
build.gradlew
dependencies {
classpath 'com.android.tools.build:gradle:2.2.+' // <- USE 2.2.+ version
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
MainActivity.java
package com.reactnavigationdrawer;
import com.facebook.react.ReactActivity;
import android.content.Intent;
public class MainActivity extends ReactActivity {
#Override
public void onNewIntent (Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
#Override
protected String getMainComponentName() {
return "reactnavigationdrawer";
}
}
MainApplication.java
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VectorIconsPackage(),
new ImagePickerPackage(),
new RNFetchBlobPackage(),
new FIRMessagingPackage(),
new FBSDKPackage(mCallbackManager)
);
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactnavigationdrawer"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:theme="#style/AppTheme">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="#drawable/ic_launcher"/>
<service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name="com.evollu.react.fcm.InstanceIdService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<receiver android:name="com.evollu.react.fcm.FIRLocalMessagingPublisher"/>
<receiver android:enabled="true" android:exported="true" android:name="com.evollu.react.fcm.FIRSystemBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
if you need more information you'll tell me!
the error reads ...
unable to resolve superclass of com.evullu.react.fcm.MessagingService
this means either reference in the Mainfest.xml is wrongful and / or the referenced class com.evullu.react.fcm.MessagingService does not exist. it might probably be rather called com.reactnavigationdrawer.MessagingService (or alike) and there's no need to compile the obsoleted package play-services-gcm either.
better add a dependency for com.google.firebase:firebase-messaging:11.8.0 ...which should contain the superclass of com.evullu.react.fcm.MessagingService, which cannot be resolved. you can check with ./gradlew app:dependencies | grep firebase whether it is present.
that file build.gradlew should be called build.gradle and Android Studio might complain about outdated versions ...meanwhile it's com.android.tools.build:gradle:3.0.1 & com.google.gms:google-services:3.1.2. that force = true; also seems useless in that context, at least don't understand what it shall do there, see ResolutionStrategy.

GCM working for build.gradle 1.4.0 but not working for 1.3.0

GCM is generating token when the build grader is com.google.gms:google-services:1.4.0-beta3 but when I change it to com.google.gms:google-services:1.3.0-beta1 it stops generating the "token.
When I am using 1.4.0-beta3" I set "com.google.android.gms:play-services-gcm:8.1.0" in build.gradle(app)
I have refered google document.
Can someone help me figure out where I am going wrong?
Here is my source code:
1)Build.gradle(project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.3.0-beta1'
//classpath 'com.google.gms:google-services:1.4.0-beta3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2)Here is build.gradle(app):
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.yembrace.android.app"
minSdkVersion 21
targetSdkVersion 21
maxSdkVersion 22
versionCode 4
versionName "1.0.3"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.google.android.gms:play-services-plus:7.5.0'
compile "com.google.android.gms:play-services-gcm:7.5.0"
// compile 'com.google.android.gms:play-services-plus:8.1.0'
// compile "com.google.android.gms:play-services-gcm:8.1.0"
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.android.support:cardview-v7:23.1.0'
//beacons sdk
compile 'com.estimote:sdk:0.8.8#aar'
compile 'com.github.clans:fab:1.6.2'
//Cards
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.1.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
}
3)Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yembrace.android.app">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="com.yembrace.yembarce.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<permission
android:name="com.yembrace.android.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:name=".AppController"
android:allowBackup="true"
android:icon="#drawable/app_logo"
android:label="#string/app_name"
android:theme="#style/AppCompatTheme"
android:screenOrientation="portrait">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!-- - Receivers -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.yembrace.yembarce" />
</intent-filter>
</receiver>
<receiver android:name=".Receivers.BeaconReceiver">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
</intent-filter>
</receiver>
<receiver android:name=".Receivers.LocationReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<!-- Services -->
<service
android:name=".Services.MyGcmListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".Services.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name=".Services.RegistrationIntentService"
android:exported="false" />
<service android:name=".Services.BeaconService" />
<service
android:name="com.estimote.sdk.service.BeaconService"
android:exported="false" />
<action android:name="android.location.PROVIDERS_CHANGED" />
<service
android:name=".Services.LocationService"
android:exported="false" />
<!-- Activities -->
<!-- Launcher Activity -->
<activity
android:name=".Activities.Launcher"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Login Activity -->
<activity
android:name=".Activities.LoginActivity"
android:label="#string/titleActivityLogin"
android:theme="#style/ThemeOverlay.MyNoTitleActivity" />
<activity
android:name=".Activities.MainActivity"
android:label=""
/>
<activity
android:name=".Activities.ShopActivity"
android:label=""
/>
<activity
android:name=".Activities.ItemActivity"
android:label=""
/>
<activity
android:name=".Activities.ProfileActivity"
android:label="#string/titleActivityProfile"
/>
<activity
android:name=".Activities.AboutActivity"
android:label="#string/titleActivityAbout"
/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="9e91d69acd5e717118f65608d8b4bae54dd4ab43" />
<!--<activity
android:name=".Activities.CheckoutActivity"
android:label="#string/title_activity_checkout"
android:theme="#style/AppTheme"></activity>-->
</application>
</manifest>
4)RegistrationIntentService.java
public class RegistrationIntentService extends IntentService {
private static final String TAG = "RegIntentService";
private static final String[] TOPICS = {"global"};
private SharedPreferences sharedPreferences = AppController.getAppContext().getSharedPreferences("app_pref", MODE_PRIVATE);
public RegistrationIntentService() {
super(TAG);
}
#Override
protected void onHandleIntent(Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
// [START register_for_gcm]
// Initially this call goes out to the network to retrieve the token, subsequent calls
// are local.
// [START get_token]
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
// [END get_token]
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(token);
// Subscribe to topic channels
subscribeTopics(token);
// You should store a boolean that indicates whether the generated token has been
// sent to your server. If the boolean is false, send the token to your server,
// otherwise your server should have already received the token.
sharedPreferences.edit().putBoolean(Config.SENT_TOKEN_TO_SERVER, true).apply();
// [END register_for_gcm]
} catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
// If an exception happens while fetching the new token or updating our registration data
// on a third-party server, this ensures that we'll attempt the update at a later time.
sharedPreferences.edit().putBoolean(Config.SENT_TOKEN_TO_SERVER, false).apply();
}
// Notify UI that registration has completed, so the progress indicator can be hidden.
Intent registrationComplete = new Intent(Config.REGISTRATION_COMPLETE);
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
/**
* Persist registration to third-party servers.
*
* Modify this method to associate the user's GCM registration token with any server-side account
* maintained by your application.
*
* #param token The new token.
*/
private void sendRegistrationToServer(final String token) {
// Add custom implementation, as needed.
Log.d("TAG","GCM Token "+token);
StringRequest stringRequest = new StringRequest(Request.Method.POST,
Config.user_gcm_register,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d("TAG",response);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d("TAG",error.toString());
}
}){
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> params = new HashMap<>();
//params.put("Authorization", Config.authorization);
return params;
}
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
Log.d("TAG","user Id "+sharedPreferences.getString("userID","null")+",GCM:"+token);
params.put("PublicUserID",sharedPreferences.getString("userID","null"));
params.put("GCMRegistrationToken",token);
return params;
}
};
AppController.getInstance().addToRequestQueue(stringRequest);
}
/**
* Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
*
* #param token GCM token
* #throws IOException if unable to reach the GCM PubSub service
*/
// [START subscribe_topics]
private void subscribeTopics(String token) throws IOException {
GcmPubSub pubSub = GcmPubSub.getInstance(this);
for (String topic : TOPICS) {
pubSub.subscribe(token, "/topics/" + topic, null);
}
}
// [END subscribe_topics]
}
5) Here is where I call GCM:
private void GCMRegister() {
Log.d("TAG","In gcm rregister in login");
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean sentToken = sharedPreferences.getBoolean(Config.SENT_TOKEN_TO_SERVER, false);
if (sentToken) {
Log.d(TAG, "register");
} else {
Log.d(TAG, "token error");
}
}
};
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
I was able to solve this problem by adding following in my manifest file:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

Categories

Resources