FCM令牌在android nougat中返回null

时间:2017-04-04 08:33:52

标签: android firebase firebase-cloud-messaging android-7.0-nougat

安装我的应用程序FirebaseInstanceId.getInstance()。getToken()时,Android Nougat设备(Moto,索尼和华为)中未生成FCM令牌。返回null,但在模拟器(Nougat)和Nougat版本下生成FCM令牌。 / p>

1 个答案:

答案 0 :(得分:1)

您何时致电FirebaseInstanceId.getInstance().getToken()? 您需要等待FirebaseInstanceIdService onTokenRefresh回调的服务延长public class FcmTokenService extends FirebaseInstanceIdService { @Override public void onTokenRefresh() { try { String refreshedToken = FirebaseInstanceId.getInstance().getToken(); if (refreshedToken != null) { Log.i("FCM", String.format("Received new registration token from Firebase: token=\"%s\";", refreshedToken)); // ... forward the new token to some point in your app to store it } } catch (Exception e) { e.printStackTrace(); } } } 。这是您的令牌可用的时刻。

    <service android:name=".services.FcmTokenService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>

在清单中注册服务:

build.gradle

这应该是apply plugin: 'com.google.gms.google-services' 文件中的最后行:

public class checkFilePermission {

      private static String path = "C:\\Users\\abc_user\\Desktop\\VI\\test123.txt";

      public static void main(String[] args) {

            checkPermissions(path);


      }


      public static void checkPermissions(String path){
            File file = new File(path);
            System.out.println(file.getPath());
            if(file.canExecute()){
                  System.out.println("Executable file");
            }
            if(file.canRead()){
                  System.out.println("Readable file");
            }
            if(file.canWrite()){
                  System.out.println("Writeable file");
            }

            //We can set the permissions as well.

            file.setExecutable(false);
            file.setReadable(false);
            file.setWritable(false);
            //file.setReadOnly();

            System.out.println("Exe = "+file.canExecute());
            System.out.println("Read = "+file.canRead());
            System.out.println("Wrt = "+file.canWrite());

      }


}