我正在尝试按照the developer site的指导,在我现有的安卓应用程序上整合Firebase推送通知。
成功构建应用程序后,如何在不将应用程序发布到playstore的情况下测试Firebase通知是否工作?
相关文件如下所示:
services/FirebaseMessagingService.java
public class FirebaseNotificationService extends FirebaseMessagingService {
    private static final String TAG = "FirebaseMsgService";
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
        String messageBody = remoteMessage.getNotification().getBody();
        Intent intent = new Intent(this, NavActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle("FCM Message")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, notificationBuilder.build());
    }
}ApplicationManifest.xml
<service android:name="services.FirebaseNotificationService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>build.gradle
dependencies {
   compile 'com.google.firebase:firebase-messaging:9.2.1'
}发布于 2016-07-17 18:36:27
通过USB调试运行您的应用程序。为了测试它,它应该可以工作。或者,你也可以将你的应用程序发布到alpha/beta版本,然后在你自己的设备上下载并进行测试。两种方式都行得通
尽管第二种方法包括发布,但它并不是完全的发布,因为它只在封闭的alpha/beta中,对于一个实例,只有您才能访问。
发布于 2016-10-27 12:15:51
一种替代物理设备的方法是使用Genymotion emulator来测试它们,只需确保您遵循以下指南(非常简单)来安装Google Play:http://forum.xda-developers.com/showthread.php?t=2528952
https://stackoverflow.com/questions/38420299
复制相似问题