diff --git a/app/build.gradle b/app/build.gradle index 984b3c1..67cbc6b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'com.android.application' android { compileSdkVersion 26 - buildToolsVersion "26.0.2" defaultConfig { applicationId "com.emarsys.mobileengage.sample" minSdkVersion 14 @@ -48,8 +47,8 @@ dependencies { // Getting a "Could not find firebase-core" error? Make sure you have // the latest Google Repository in the Android SDK manager - compile 'com.android.support:design:26.0.2' - compile 'com.android.support:appcompat-v7:26.0.2' + compile 'com.android.support:design:26.1.0' + compile 'com.android.support:appcompat-v7:26.1.0' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.squareup.picasso:picasso:2.5.2' diff --git a/app/src/main/java/com/emarsys/mobileengage/sample/MobileEngageFragment.java b/app/src/main/java/com/emarsys/mobileengage/sample/MobileEngageFragment.java index 58caf48..2891701 100644 --- a/app/src/main/java/com/emarsys/mobileengage/sample/MobileEngageFragment.java +++ b/app/src/main/java/com/emarsys/mobileengage/sample/MobileEngageFragment.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; @@ -20,7 +21,10 @@ import com.emarsys.mobileengage.MobileEngage; import com.emarsys.mobileengage.MobileEngageException; import com.emarsys.mobileengage.MobileEngageStatusListener; +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 org.json.JSONException; import org.json.JSONObject; @@ -153,22 +157,26 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { pushToken.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { - String pushToken = FirebaseInstanceId.getInstance().getToken(); - ClipboardManager clipboard = (ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE); - String toastMessage = pushToken; - if (clipboard != null) { - ClipData clip = ClipData.newPlainText("pushtoken", pushToken); - clipboard.setPrimaryClip(clip); - toastMessage = "Copied: " + toastMessage; - } - Toast.makeText( - v.getContext(), - toastMessage, - Toast.LENGTH_LONG).show(); + public void onClick(final View view) { + FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + ClipboardManager clipboard = (ClipboardManager) view.getContext().getSystemService(Context.CLIPBOARD_SERVICE); + String pushToken = task.getResult().getToken(); + String toastMessage = pushToken; + if (clipboard != null) { + ClipData clip = ClipData.newPlainText("pushtoken", pushToken); + clipboard.setPrimaryClip(clip); + toastMessage = "Copied: " + toastMessage; + } + Toast.makeText( + view.getContext(), + toastMessage, + Toast.LENGTH_LONG).show(); + } + }); } }); - return root; } diff --git a/build.gradle b/build.gradle index bc7a1cf..7e44536 100644 --- a/build.gradle +++ b/build.gradle @@ -2,10 +2,11 @@ buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.3.0' classpath 'com.google.gms:google-services:3.1.0' // NOTE: Do not place your application dependencies here; they belong @@ -15,10 +16,8 @@ buildscript { allprojects { repositories { + google() jcenter() - maven { - url "https://maven.google.com" - } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5c3e007..f3e830d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip