如何在开发过程中测试Firebase推送通知而不将应用程序发布到Playstore?

时间:2016-07-17 10:33:41

标签: android firebase firebase-notifications

我正在尝试按照the developer site的指南在我现有的Android应用上合并Firebase推送通知。

成功构建应用程序后,如果不将应用程序发布到Playstore,我如何测试Firebase Notifications是否正常工作?

相关文件如下所示:

服务/ 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'
}

2 个答案:

答案 0 :(得分:1)

通过USB调试运行您的应用。它应该工作,以测试它。或者,您可以将您的应用程序发布到alpha / beta并将其下载到您自己的设备上并进行测试。两种方式都可以工作

虽然第二种方式包括发布它不是完整的发布,因为它只是在封闭的alpha / beta中,只有实例才能访问。

答案 1 :(得分:0)

物理设备的替代方案是使用Genymotion emulator对其进行测试,只需确保您按照本指南(非常简单)安装Google Play:http://forum.xda-developers.com/showthread.php?t=2528952