delphi - 德尔福西雅图的 GCM,无 BAAS

标签 delphi google-cloud-messaging delphi-10-seattle

我正在尝试在 GCM 中实现没有 BAAS 的 GCM。我已经查看了之前使用桥接器的示例,根据我的研究,以下内容应该可以在不依赖旧的 TGCMReceiver 组件的情况下工作。

但是以下行始终返回 nil,我在单击按钮启动应用程序后运行此行:

APushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.GCM);

APushService 始终为零。

我的 AndroidManifest 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.embarcadero.Project1"
        android:versionCode="1"
        android:versionName="1.0.0"
        android:installLocation="auto">

    <!-- This is the platform API where NativeActivity was introduced. -->
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <permission android:name="com.embarcadero.Project1.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="com.embarcadero.Project1.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-feature android:glEsVersion="0x00020000" android:required="True"/>
    <application android:persistent="False" 
        android:restoreAnyVersion="False" 
        android:label="Project1" 
        android:debuggable="True" 
        android:largeHeap="False"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme"
        android:hardwareAccelerated="true">

        <meta-data android:name="com.google.android.gms.version" android:value="4323000" />


        <!-- Our activity is a subclass of the built-in NativeActivity framework class.
             This will take care of integrating with our NDK code. -->
        <activity android:name="com.embarcadero.firemonkey.FMXNativeActivity"
                android:label="Project1"
                android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
                android:launchMode="singleTask">
            <!-- Tell NativeActivity the name of our .so -->
            <meta-data android:name="android.app.lib_name"
                android:value="Project1" />
            <intent-filter>  
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter> 
        </activity>
        <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

<receiver
      android:name="com.embarcadero.gcm.notifications.GCMNotification" android:exported="true"
      android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
          <action android:name="com.google.android.c2dm.intent.RECEIVE" />
          <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
          <category android:name="com.embarcadero.Project1" />
        </intent-filter>
</receiver>

        <receiver android:name="com.embarcadero.rtl.notifications.NotificationAlarm" />
<receiver android:exported="true" android:name="com.embarcadero.gcm.notifications.GCMNotification" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.embarcadero.Project1" />
</intent-filter>
</receiver>

<service android:name="com.embarcadero.gcm.notifications.GCMIntentService" />
    </application>
</manifest>
<!-- END_INCLUDE(manifest) -->

我尝试使用 CodeRage9 中使用 XE8 的通用 TGCMReceiver 应用程序,它在 XE10/西雅图中不起作用,而且 XE10 似乎在这方面进行了更新,但我无法使用简单的 Google Cloud 进行任何操作消息传递并正在寻找一些指导。

最佳答案

答案如下所示:Issue with GCM Push notification service DELPHI XE6

除非使用 .Active := True 而非 AutoActivate := True,如答案所示。

TL;DR 版本。将 TKinvyProvider 放在仅填充 GCMAppID 的表单上,将 TPushEvent 放在表单上并将 AutoRegister 和 AutoActivate 设置为 false。在权利列表中设置“支持推送通知:true”。将以下内容添加到您的 AndroidManifest.template.xml:

<service android:name="com.embarcadero.gcm.notifications.GCMIntentService" /> 

就在</application>之前.

关于delphi - 德尔福西雅图的 GCM,无 BAAS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35590533/

相关文章:

c - 在 Ansi-C 中导入 Delphi Dll

delphi - Delphi中如何获取结构项

delphi - 如何使用系统路径之外的dll

android - 推送通知未从 Android 的通知栏中删除

delphi - 点击事件被 ListView 父项捕获

delphi - 有没有办法为整个项目全局设置 {$SCOPEDENUMS ON} ?

node.js - Firebase 上游云消息

android - 图书馆可以注册应用程序以获得通知吗?

delphi - 对于静态数组,使用 RTTI 获取记录字段类型失败

delphi - 如何定义 TFormatSettings 常量 (Delphi 10)