【问题标题】:Android - how to check google play service before start firebaseAndroid - 如何在启动 firebase 之前检查 google play 服务
【发布时间】:2018-09-01 13:39:17
【问题描述】:

我使用 firebase 进行推送通知

我有一个类“MyFirebaseMessagingService 扩展 FirebaseMessagingService”

在用户启动应用后自动启动

但我想检查 如果存在并启用 google play 服务,则 启动火力基地

其他

换一种方式……

清单:

<service
 android:name=".MyFirebaseMessagingService">
 <intent-filter>
           <action android:name="com.google.firebase.MESSAGING_EVENT"/>
 </intent-filter>

【问题讨论】:

    标签: android firebase google-play-services


    【解决方案1】:

    首先将其添加到您的 android 清单中

    <application>
    <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"     
     />
    

    然后检查是否存在 Google Playstore 使用这个。

    public boolean isGooglePlayServicesAvailable(Activity activity) {
        GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
        int status = googleApiAvailability.isGooglePlayServicesAvailable(activity);
        if(status != ConnectionResult.SUCCESS) {
            if(googleApiAvailability.isUserResolvableError(status)) {
                  googleApiAvailability.getErrorDialog(activity, status, 2404).show();
            }
            return false;
        }
        return true;
    }
    

    【讨论】:

    • 没有人,我想在清单级别检查它,因为在 api 19 中,如果设备上未安装 google play 服务,应用程序将强制停止!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    相关资源
    最近更新 更多