FCM Expert Пожалуйста, помогите мне, мне нужно интегрировать уведомление для Android с помощью FCM, я пытаюсь продемонстрировать демо-версию Firebase, я пробовал много логики, но он дал первый токен для некоторых устройств: Я использовал три устройства: Moto E (2-й генератор) (версия Android 5.1.1), Samsung GT-S7562 (AV 4.1.2) и Karbon Titanium (AV 4.2.2), я получаю токен только для Karbon Titanium, don Не знаю, почему я не получаю токен для Moto E (2 Gen) и Samsung GT-S7562, но получаю токен от устройства Titanium из карбона:
Вот код, который я пробовал:
Logcat Moto E2:
07-07 15:58:08.776 24152-24152/? I/art: Late-enabling -Xcheck:jni
07-07 15:58:08.802 24152-24162/? E/art: Failed sending reply to debugger: Broken pipe
07-07 15:58:08.802 24152-24162/? I/art: Debugger is no longer active
07-07 15:58:08.848 24152-24152/? D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
07-07 15:58:08.859 24152-24152/? D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
07-07 15:58:08.872 24152-24152/? I/FA: App measurement is starting up, version: 9256
07-07 15:58:08.872 24152-24152/? I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
07-07 15:58:09.027 24152-24152/? I/FirebaseInitProvider: FirebaseApp initialization successful
07-07 15:58:09.196 24152-24152/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-07 15:58:09.361 24152-24192/? D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
07-07 15:58:09.378 24152-24152/? D/Atlas: Validating map...
07-07 15:58:09.564 24152-24192/? I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: (Ibddc658e36)
OpenGL ES Shader Compiler Version: E031.25.03.04
Build Date: 08/10/15 Mon
Local Branch: workspace
Remote Branch:
Local Patches:
Reconstruct Branch:
07-07 15:58:09.567 24152-24192/? I/OpenGLRenderer: Initialized EGL, version 1.4
07-07 15:58:09.609 24152-24192/? D/OpenGLRenderer: Enabling debug mode 0
07-07 15:58:12.860 24152-24242/com.shubhank.fcm_tutorial W/InstanceID/Rpc: Found 10016
07-07 15:58:13.049 24152-24242/com.shubhank.fcm_tutorial D/FirebaseInstanceId: background sync failed: PHONE_REGISTRATION_ERROR, retry in 10s
07-07 15:58:19.256 24152-24178/com.shubhank.fcm_tutorial I/FA: Tag Manager is not found and thus will not be used
07-07 15:58:23.194 24152-24448/com.shubhank.fcm_tutorial D/FirebaseInstanceId: background sync failed: PHONE_REGISTRATION_ERROR, retry in 20s
Logcat of Karbon Mobile:
07-07 16:38:03.964 3939-3939/com.shubhank.fcm_tutorial I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
07-07 16:38:04.004 3939-3939/com.shubhank.fcm_tutorial I/FirebaseInitProvider: FirebaseApp initialization successful
07-07 16:38:04.017 3939-3939/com.shubhank.fcm_tutorial W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
07-07 16:38:04.017 3939-3939/com.shubhank.fcm_tutorial I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
07-07 16:38:04.017 3939-3939/com.shubhank.fcm_tutorial W/dalvikvm: VFY: unable to resolve interface method 19193: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
07-07 16:38:04.017 3939-3939/com.shubhank.fcm_tutorial I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
07-07 16:38:04.017 3939-3939/com.shubhank.fcm_tutorial W/dalvikvm: VFY: unable to resolve interface method 19197: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
07-07 16:38:04.049 3939-3939/com.shubhank.fcm_tutorial I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
07-07 16:38:04.049 3939-3939/com.shubhank.fcm_tutorial W/dalvikvm: VFY: unable to resolve virtual method 577: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
07-07 16:38:04.050 3939-3939/com.shubhank.fcm_tutorial I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
07-07 16:38:04.050 3939-3939/com.shubhank.fcm_tutorial W/dalvikvm: VFY: unable to resolve virtual method 599: Landroid/content/res/TypedArray;.getType (I)I
07-07 16:38:04.092 3939-3939/com.shubhank.fcm_tutorial I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
07-07 16:38:04.092 3939-3939/com.shubhank.fcm_tutorial W/dalvikvm: VFY: unable to resolve virtual method 540: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
07-07 16:38:04.092 3939-3939/com.shubhank.fcm_tutorial I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
07-07 16:38:04.092 3939-3939/com.shubhank.fcm_tutorial W/dalvikvm: VFY: unable to resolve virtual method 542: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
07-07 16:38:04.096 3939-3939/com.shubhank.fcm_tutorial W/notification: faQNkJ65F5c:APA91bFHH5rVOhIlX5k7Pxo-sbZPwZplWqBGLVOjlG8G4NwoMqaKZQRYWMMjliYXb0gokiuJPBYpWY0G7L-FEbgAv7LfKcuR0j7Sr6ATxb1j2UR7A
07-07 16:38:04.148 3939-3939/com.shubhank.fcm_tutorial I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
07-07 16:38:04.148 3939-3939/com.shubhank.fcm_tutorial I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
07-07 16:38:04.148 3939-3939/com.shubhank.fcm_tutorial I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
07-07 16:38:04.159 3939-3939/com.shubhank.fcm_tutorial I/[MALI][Gralloc]: dlopen libsec_mem.so fail
MainActivity:
public class MainActivity extends AppCompatActivity {
Tracker mTracker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String token = FirebaseInstanceId.getInstance().getToken();
if (token != null) {
Log.w("notification", token);
Toast.makeText(MainActivity.this,""+token,Toast.LENGTH_SHORT).show();
}
}
}
app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.shubhank.fcm_tutorial"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-analytics:9.2.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.firebase:firebase-core:9.0.1'
compile 'com.google.firebase:firebase-messaging:9.0.1'
compile 'com.android.support:design:23.3.0'
}
apply plugin: 'com.google.gms.google-services'
верхний уровень gradle:
buildscript {
repositories {
jcenter()
mavenLocal()
}
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
}
}
allprojects {
repositories {
jcenter()
mavenLocal()
}
}
TokenService:
public class TokenService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.w("notification", refreshedToken);
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
}
}
FCMMessageReceiverService:
public class FCMMessageReceiverService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.w("fcm", "received notification");
sendNotification(remoteMessage.getNotification().getTitle());
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(messageBody)
.setAutoCancel(false)
.setSound(defaultSoundUri);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notificationBuilder.build());
}
}
Файл манифеста:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shubhank.fcm_tutorial">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:launchMode="standard"
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>
<service android:name=".TokenService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".FCMMessageReceiverService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
</application>
</manifest>