我正在尝试向Android应用添加FirebaseMessagingService
子类,以便可以接收设备令牌,但未创建服务。
这是服务:
package com.company.AppName;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
public class AppFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "AppFbMessagingService";
public AppFirebaseMessagingService() {
Log.d(TAG, "created");
}
@Override
public void onNewToken(String token) {
Log.d(TAG, "Refreshed token: " + token);
NativeApp.shared().setDeviceToken(token);
}
}
我的清单和服务声明:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.company.AppName" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="org.apache.cordova.camera.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/camera_provider_paths" />
</provider>
<service android:enabled="true" android:name="com.company.AppName.LocationListenerService" android:permission="android.permission.BIND_JOB_SERVICE" />
<service
android:name="com.company.AppName.AppFirebaseMessagingService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="26" />
</manifest>
这些是我启动应用程序时看到的唯一与Firebase相关的日志:
D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
I/FirebaseInitProvider: FirebaseApp initialization successful
AppFirebaseMessagingService
中的两个日志均未调用。我尝试用android:name="com.company.AppName.AppFirebaseMessagingService"
替换android:name="AppFirebaseMessagingService"
并删除android:exported="false"
。
答案 0 :(得分:0)
当我在真实设备而不是模拟器上运行时开始工作。考虑到是在仿真器中工作没有任何意义。