0
有人能向我解釋GCM接收器在下面的例子中是如何工作的。通過設置在GcmBroadcastReceiver - GcmListenerService
和類別我的包裹我能達到什麼目的?這是否意味着從GCM接收器接收到GCM消息(無需編寫任何代碼)並將其發送到我的應用,我的GCM偵聽器在那裏接收它們?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gcm.play.android.samples.com.gcmquickstart" >
<uses-permission android:name="android.permission.INTERNET" />
<!-- [START gcm_permission] -->
<permission android:name="gcm.play.android.samples.com.gcmquickstart.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="gcm.play.android.samples.com.gcmquickstart.permission.C2D_MESSAGE" />
<!-- [END gcm_permission] -->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- [START gcm_receiver] -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="gcm.play.android.samples.com.gcmquickstart" />
</intent-filter>
</receiver>
<!-- [END gcm_receiver] -->
<!-- [START gcm_listener] -->
<service
android:name="gcm.play.android.samples.com.gcmquickstart.MyGcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- [END gcm_listener] -->
<!-- [START instanceId_listener] -->
<service
android:name="gcm.play.android.samples.com.gcmquickstart.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<!-- [END instanceId_listener] -->
<service
android:name=".RegistrationIntentService"
android:exported="false">
</service>
</application>
</manifest>
感謝您的回答!我之前檢查過這些文件,並再次檢查。根據我的理解,通過將GCMReceiver添加到我的清單中,並將意向過濾器中的類別設置爲我的包,真正發生的是,我告訴系統我可以接受來自GCMReceiver的消息,僅當它們以我的應用程序(intent-filter) 。我對嗎?我沒有得到的是,可以在聲明中聲明一個接收者,而不實現它。 –