当前位置: 首页 > 知识库问答 >
问题:

某些Android设备中的FCM令牌问题

景安翔
2023-03-14

FCM专家请帮助我,我必须使用FCM为android集成通知,我正在尝试Firebase提供的演示,我尝试了许多逻辑,但它为一些设备提供了第一个令牌:我使用了三个设备,Moto E(第二代)(android版本5.1.1),Samsung GT-S7562(A.V 4.1.2)和Karbon Titanium (A.V 4.2.2),我只收到了Karbon Titanium的令牌,不知道为什么我没有收到Moto E(第二代)和的令牌

这是我尝试的代码:

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

Karbon Mobile的Logcat:

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

主要活动:

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

    }


}

应用程序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'

顶级等级 :

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

代币服务:

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

F CM消息接收器服务:

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>

共有1个答案

昌博易
2023-03-14

做出这样的改变

在gradle文件中

   compile 'com.google.firebase:firebase-messaging:9.0.0'

public class FirebaseMessagingServices extends FirebaseMessagingService {

private static final String TAG = "FirebaseMessaging";
private NotificationManager mNotificationManager;
public static final int NOTIFICATION_ID = 1;


@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // Not getting messages here
    Log.v(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.v(TAG, "Message data payload: 1" + remoteMessage.getData());
      //  sendNotification(remoteMessage.getData()+"");
        Log.v(TAG, "Message data payload: 2" + remoteMessage.getData().get(Config.MESSAGE_KEY).toString());    
                    sendNotification(remoteMessage.getData().get(Config.MESSAGE_KEY) + "");
         }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.v(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());

        SharedPreferences preferences =getSharedPreferences(Utils.SIGNUP_PREF, MODE_PRIVATE);
        boolean notification = preferences.getBoolean(Utils.notification,true);

            sendNotification(remoteMessage.getNotification().getBody()); 
    }
}
    private void sendNotification(String msg) {
    MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.notification1);
    mp.start();

    mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, MainActivity.class), 0);

    NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(
            this).setSmallIcon(R.drawable.penless_small)
            .setContentTitle("Penless")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setContentText(msg);
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());}}
 类似资料:
  • 问题内容: 我正在尝试通过Node.js服务器在Android应用中实现Firebase云消息传递,但遇到了用例。 我看到了Firebase教程,该教程使用注册令牌创建设备组以向登录同一用户的所有设备发送消息/通知,我不明白的是当使用onTokenRefresh()方法刷新一个注册令牌时会发生什么。 我将如何区分要更改的令牌,因为所有令牌都属于同一用户? 更新: 好的,所以现在我被困在另一个阻塞的

  • 最近,我们在Android应用程序中增加了对Chromecast的支持,但在对各种移动设备(手机和平板电脑)的扩展测试中,发现在许多移动设备上,Flipps应用程序都没有发现Chromecast。在相同的设备上,我们使用了最新版本的官方Chromecast SDK演示应用程序进行测试,该应用程序从https://github.com/googlecast/castvideo-Android下载(主

  • 我们用FCM创建了一个带有通知的聊天应用程序,我的代码是正确的,我的设备也得到了推送通知数据,但一些中国制造的设备,如vivo、oppo、一加、小米,不允许通知显示,除非我在各自厂商的受保护的应用程序列表中添加应用程序。他们有没有办法解决这个问题。 https://hackernoon.com/notifications-in-android-are-horribly-broken-b8dbec6

  • 这是我送的东西。

  • 在新的Firebase中,在Notification下,他们提到开发者可以向特定设备发送通知。为此,它在控制台中请求FCM令牌。它到底是什么?我怎样才能得到那个令牌?

  • 我正在学习一个教程,即http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/ 但我无法获取令牌,我的服务类也无法工作。请帮忙