mirror of
https://github.com/Xtao-Labs/FirebaseCloudMessaging-Android.git
synced 2025-01-30 15:08:38 +00:00
Update dependencies
This commit is contained in:
parent
152ca2d962
commit
32a1af3c8f
@ -2,11 +2,11 @@ apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion compileAndTargetSdkVersion
|
||||
buildToolsVersion '29.0.0'
|
||||
buildToolsVersion '29.0.2'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.example.fcm"
|
||||
minSdkVersion compileAndTargetSdkVersion
|
||||
minSdkVersion 23
|
||||
targetSdkVersion compileAndTargetSdkVersion
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
@ -37,8 +37,8 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
implementation 'com.google.firebase:firebase-core:17.0.0'
|
||||
implementation 'com.google.firebase:firebase-messaging:19.0.1'
|
||||
implementation 'com.google.firebase:firebase-core:17.2.0'
|
||||
implementation 'com.google.firebase:firebase-messaging:20.0.0'
|
||||
}
|
||||
|
||||
apply plugin: 'com.google.gms.google-services'
|
@ -3,12 +3,17 @@ package com.example.fcm;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.iid.FirebaseInstanceId;
|
||||
import com.google.firebase.iid.InstanceIdResult;
|
||||
import com.google.firebase.messaging.FirebaseMessaging;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@ -25,8 +30,9 @@ import java.util.Scanner;
|
||||
import static com.example.fcm.R.id.txt;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private static final String AUTH_KEY = "key=YOUR_SERVER_KEY";
|
||||
private static final String AUTH_KEY = "key=YOUR-SERVER-KEY";
|
||||
private TextView mTextView;
|
||||
private String token;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -43,11 +49,23 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
mTextView.setText(tmp);
|
||||
}
|
||||
|
||||
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<InstanceIdResult> task) {
|
||||
if (!task.isSuccessful()) {
|
||||
token = task.getException().getMessage();
|
||||
Log.w("FCM TOKEN Failed", task.getException());
|
||||
} else {
|
||||
token = task.getResult().getToken();
|
||||
Log.i("FCM TOKEN", token);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void showToken(View view) {
|
||||
mTextView.setText(FirebaseInstanceId.getInstance().getToken());
|
||||
Log.i("token", FirebaseInstanceId.getInstance().getToken());
|
||||
mTextView.setText(token);
|
||||
}
|
||||
|
||||
public void subscribe(View view) {
|
||||
@ -93,13 +111,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
jNotification.put("click_action", "OPEN_ACTIVITY_1");
|
||||
jNotification.put("icon", "ic_notification");
|
||||
|
||||
jData.put("picture", "http://opsbug.com/static/google-io.jpg");
|
||||
jData.put("picture", "https://miro.medium.com/max/1400/1*QyVPcBbT_jENl8TGblk52w.png");
|
||||
|
||||
switch(type) {
|
||||
case "tokens":
|
||||
JSONArray ja = new JSONArray();
|
||||
ja.put("c5pBXXsuCN0:APA91bH8nLMt084KpzMrmSWRS2SnKZudyNjtFVxLRG7VFEFk_RgOm-Q5EQr_oOcLbVcCjFH6vIXIyWhST1jdhR8WMatujccY5uy1TE0hkppW_TSnSBiUsH_tRReutEgsmIMmq8fexTmL");
|
||||
ja.put(FirebaseInstanceId.getInstance().getToken());
|
||||
ja.put(token);
|
||||
jPayload.put("registration_ids", ja);
|
||||
break;
|
||||
case "topic":
|
||||
@ -109,7 +127,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
jPayload.put("condition", "'sport' in topics || 'news' in topics");
|
||||
break;
|
||||
default:
|
||||
jPayload.put("to", FirebaseInstanceId.getInstance().getToken());
|
||||
jPayload.put("to", token);
|
||||
}
|
||||
|
||||
jPayload.put("priority", "high");
|
||||
|
@ -4,8 +4,8 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.4.1'
|
||||
classpath 'com.google.gms:google-services:4.2.0'
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath 'com.google.gms:google-services:4.3.1'
|
||||
}
|
||||
}
|
||||
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
|
||||
|
Loading…
Reference in New Issue
Block a user