首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在开发期间测试Firebase推送通知,而不将应用程序发布到playstore?

如何在开发期间测试Firebase推送通知,而不将应用程序发布到playstore?
EN

Stack Overflow用户
提问于 2016-07-17 18:33:41
回答 2查看 2.7K关注 0票数 1

我正在尝试按照the developer site的指导,在我现有的安卓应用程序上整合Firebase推送通知。

成功构建应用程序后,如何在不将应用程序发布到playstore的情况下测试Firebase通知是否工作?

相关文件如下所示:

services/FirebaseMessagingService.java

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
<service android:name="services.FirebaseNotificationService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

build.gradle

代码语言:javascript
运行
复制
dependencies {
   compile 'com.google.firebase:firebase-messaging:9.2.1'
}
EN

回答 2

Stack Overflow用户

发布于 2016-07-17 18:36:27

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

尽管第二种方法包括发布,但它并不是完全的发布,因为它只在封闭的alpha/beta中,对于一个实例,只有您才能访问。

票数 1
EN

Stack Overflow用户

发布于 2016-10-27 12:15:51

一种替代物理设备的方法是使用Genymotion emulator来测试它们,只需确保您遵循以下指南(非常简单)来安装Google Play:http://forum.xda-developers.com/showthread.php?t=2528952

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38420299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档