Can't send notifications from Parse Server - android

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);
});

Related

problems in application when changing its package name

I am new to application development, it turns out that I have shared the template of an android application.
but it gives me the following problem when I make the change of the packname, (I also make the change in the build.gradle:app , I check the manifest and everything is fine, I have cleaned and rebuilt the project and I have cleared the cache and restarted the android studio ) but it gives me the following problem, once I have compiled the application I pass it to my cell phone but when I open it the application closes and does not open, it does not work.
Note: but if I don't change the packname the application works very well
build.gradle:
`
plugins {
id 'com.android.application'
id 'com.onesignal.androidsdk.onesignal-gradle-plugin'
//this to copied
}
def API_KEY = '"' + ApiKey + '"' ?: '"Api Key Not Found"'
def LOGIN_KEY = '"' + LoginKey + '"' ?: '"Login Key Not Found"'
def REG_KEY = '"' + RegKey + '"' ?: '"SignUp Key Not Found"'
def U_PROFILE_KEY = '"' + UprofileKey + '"' ?: '"Profile Key Not Found"'
def FP_KEY = '"' + FpKey + '"' ?: '"Forget P Key Not Found"'
def U_POINTS_KEY = '"' + UpointsKey + '"' ?: '"Update Points Key Not Found"'
def RP_KEY = '"' + RpKey + '"' ?: '"Reset P Key Not Found"'
def UD_KEY = '"' + UdKey + '"' ?: '"Update Points Key Not Found"'
def ADMIN_SETTINGS_KEY = '"' + ASettingsKey + '"' ?: '"Admin Settings Key Not Found"'
def GAME_SETTINGS_KEY = '"' + GSettingsKey + '"' ?: '"Game Settings Key Not Found"'
def REDEEM_SETTINGS_KEY = '"' + RSettingsKey + '"' ?: '"Redeem Settings Key Not Found"'
def APPS_SETTINGS_KEY = '"' + AppsSettingKey + '"' ?: '"Apps Settings Key Not Found"'
def VIDEO_SETTINGS_KEY = '"' + VideoSettingKey + '"' ?: '"Apps Settings Key Not Found"'
def VISIT_SETTINGS_KEY = '"' + VisitSettingKey + '"' ?: '"Visit Settings Key Not Found"'
def STRING = 'String'
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 19
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
each {type ->
type.buildConfigField STRING, 'ApiKey', API_KEY
}
each {type ->
type.buildConfigField STRING, 'LoginKey', LOGIN_KEY
}
each {type ->
type.buildConfigField STRING, 'RegKey', REG_KEY
}
each {type ->
type.buildConfigField STRING, 'UprofileKey', U_PROFILE_KEY
}
each {type ->
type.buildConfigField STRING, 'FpKey', FP_KEY
}
each {type ->
type.buildConfigField STRING, 'UpointsKey', U_POINTS_KEY
}
each {type ->
type.buildConfigField STRING, 'RpKey', RP_KEY
}
each {type ->
type.buildConfigField STRING, 'UdKey', UD_KEY
}
each {type ->
type.buildConfigField STRING, 'ASettingsKey', ADMIN_SETTINGS_KEY
}
each {type ->
type.buildConfigField STRING, 'GSettingsKey', GAME_SETTINGS_KEY
}
each {type ->
type.buildConfigField STRING, 'RSettingsKey', REDEEM_SETTINGS_KEY
}
each {type ->
type.buildConfigField STRING, 'AppsSettingKey', APPS_SETTINGS_KEY
}
each {type ->
type.buildConfigField STRING, 'VideoSettingKey', VIDEO_SETTINGS_KEY
}
each {type ->
type.buildConfigField STRING, 'VisitSettingKey', VISIT_SETTINGS_KEY
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
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.appcompat:appcompat:1.4.1' //1.3.0
implementation 'androidx.constraintlayout:constraintlayout:2.1.3' //2.1.2
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation files('../libs/unity-ads.aar')
testImplementation 'junit:junit:4.13.2' //4.13
implementation 'com.google.android.material:material:1.5.0' //1.4.0
androidTestImplementation 'androidx.test.ext:junit:1.1.3' // 1.1.2
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' //3.3.0
implementation 'com.google.android.gms:play-services-location:19.0.1'
//sceen Size
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'
//rootbear
implementation 'com.scottyab:rootbeer-lib:0.1.0'
implementation 'com.google.firebase:firebase-messaging:23.0.0'
implementation 'com.onesignal:OneSignal:4.6.0'
//Spin
implementation 'com.github.mmoamenn:LuckyWheel_Android:0.3.0'
//scratch
implementation 'in.codeshuffle.scratchcardlayout:ScratchCardLayout:1.0.8'
//activityLifeCycle
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
//multidex
implementation 'com.android.support:multidex:1.0.3'
//volley
implementation 'com.android.volley:volley:1.2.1'//1.1.1
implementation 'com.google.code.gson:gson:2.8.6'
//:Lottie
implementation "com.airbnb.android:lottie:4.2.0" //3.4.0
//InApp Update
implementation 'com.google.android.play:core:1.10.2'
//Ads Network
implementation 'com.startapp:inapp-sdk:4.9.1'
implementation 'com.applovin:applovin-sdk:11.4.2'
implementation 'com.applovin.mediation:facebook-adapter:6.11.0.2'
implementation 'com.google.android.gms:play-services-ads-identifier'
//glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
//Chrome Tab:
implementation "androidx.browser:browser:1.4.0"
//SweetAlert
implementation 'com.github.f0ris.sweetalert:library:1.5.1'//1.5.1
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.github.ibrahimsn98:SmoothBottomBar:1.7.9'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'applovin-quality-service'
applovin {
apiKey "...."
}
`
Manifest
`
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.app"
tools:ignore="LockedOrientationActivity">
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission
android:name="android.permission.ACCESS_WIFI_STATE"
tools:node="remove" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.Ad_ID" />
<application
android:name="com.example.app.App"
android:hardwareAccelerated="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:networkSecurityConfig="#xml/network_security_config"
android:theme="#style/AppTheme"
tools:replace="android:icon"
tools:targetApi="n">
<meta-data android:name="applovin.sdk.key"
android:value="#string/APPLOVIN_SDK_KEY"/>
<activity
android:name="com.example.app.activity.VisitActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.VideoActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.InstallActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.AppsActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.GiftCardActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.WatchAndEarnActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.GameLoader"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.GameActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.QuizActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.CaptchaActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.PrivacyActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.SpinActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.ScratchActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.LoginActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.MainActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" />
<activity
android:name="com.example.app.activity.SplashActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
<service
android:name="com.example.app.services.PointsService"
android:enabled="true"
android:exported="false" />
<service
android:name="com.example.app.services.UpdateDateService"
android:enabled="true"
android:exported="false" />
<service
android:name="com.example.app.services.MyFirebaseMessagingService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_launcher_round" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorPrimaryDark" />
</application>
</manifest>
`
I change the build.gradle:app , I check the manifest and everything is fine, I have cleaned and rebuilt the project and I have cleared the cache and restarted the android studio. what I hope is that it works with another packname

XMLHttpRequest not firing/calling any [on] callback in react-native Android

react-native v0.63.4 android XMLHttpRequest not calling any [on] callback after sending the request but if I check after in the request data, I find that ready state is DONE and the response status is 200 OK and the data is there but none of the callbacks gets fired.
Here is the code I'm testing with.
var request = new XMLHttpRequest();
request.onabort = () => {
console.warn("ABORTED");
};
request.onerror = () => {
console.warn("ERROR");
};
request.onloadstart = () => {
console.warn("LOAD START");
};
request.onloadend = () => {
console.warn("LOAD END");
};
request.ontimeout = () => {
console.warn("TIMEOUT");
};
request.onload = () => {
console.warn("LOAD");
};
request.onreadystatechange = (e) => {
console.warn("STATE CHANGE", request.status);
if (request.readyState !== 4) {
return;
}
if (request.status === 200) {
console.warn("success", request.responseText);
} else {
console.warn("error");
}
};
request.open("GET", "https://api.github.com/", true);
request.send();
setTimeout(() => {
console.warn(JSON.stringify(request, null, 2)); // this successfully log all the response data.
}, 1000);
My android/app/build.gradle dependencies are.
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation platform('com.google.firebase:firebase-bom:26.4.0')
def multidex_version = "2.0.1"
implementation "androidx.multidex:multidex:$multidex_version"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
My android/build.gradle is
buildscript {
ext {
RNNKotlinVersion = "1.3.72"
buildToolsVersion = "29.0.2"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
playServicesVersion = "17.0.0" // or find latest version
androidMapsUtilsVersion = "2.2.0"
androidXCore = "1.0.2"
}
repositories {
google()
jcenter()
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
classpath('com.android.tools.build:gradle:4.1.2')
classpath 'com.google.gms:google-services:4.3.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
finally, my AndroidManifest.xml is:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.app">
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<application
android:usesCleartextTraffic="true"
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme">
<!-- You will only need to add this meta-data tag, but make sure it's a child of application -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="mygooglekey"/>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
<!-- You will also only need to add this uses-library tag -->
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
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" />
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
</application>
</manifest>
What I'm doing wrong?

I/CrashlyticsCore: Crashlytics report upload complete but not show in dashboard

I have problem with Fabric. its a test project for find problem and do everything step by step in fabric documents, but i don't know what is mistake. please help me.
My Gradle:
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' }
}
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycompany.testtt"
minSdkVersion 17
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:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
compile('com.crashlytics.sdk.android:crashlytics:2.9.4#aar') {
transitive = true;
}
}
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.testtt">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="9fd0b323bad2f5dae063288c94fd3a2317faa104"
/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Main Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
// TODO: Move this to where you establish a user session
logUser();
setContentView(R.layout.activity_main);
}
private void logUser() {
// TODO: Use the current user's information
// You can call any combination of these three methods
Crashlytics.setUserIdentifier("12345");
Crashlytics.setUserEmail("user#fabric.io");
Crashlytics.setUserName("Test User");
}
public void forceCrash(View view) {
throw new RuntimeException("This is a crash");
}
After all, and error and testing, but nothing is still displayed on the dashboard.
I do everything step by step from fabric documents.
I have this problem for a few days, and anyway I've tested it, but I still have not gotten a result and does not display anything in the fabric dashboard. ApiKey is correct and I'm sure of it.
(sorry for English)

FirebaseInstanceIdService getToken returning null

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>

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