问题
I'm developing a GCM Push notification on delphi xe6. I use the code in this post https://stackoverflow.com/questions/21466094/start-android-activity-before-passing-the-gcm-intent (using the standars components in the AndroidManifest.xml) for my own app and I manage to use the service to receive the notification even if the app is not running.
But I have a problem when I receive the notification and that is i cant capture the onclick event, so my apps open (great) but it doesn't do the desire action.
Here is my AndroidManifest.xml
<receiver android:name="com.embarcadero.gcm.notifications.GCMNotification" android:exported="true">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="%package%" />
</intent-filter>
</receiver>
<service android:name="com.embarcadero.gcm.notifications.GCMIntentService">
</service>
If I use the code in the post, i can detect when the user click on the notification, but I don't know how to do it with the standard components.
Regards
回答1:
The best and simplist way to implement GCM client without kinvy in XE6 / XE7 after I dug many source codes is:
Drop TKinvyProvider onto the form and fill ONLY GCMAppID property, leave others default.
Drop TPushEvent component onto the form and let AutoRegisterDevice to false.
Double click the OnPushReceive event in TPushEvent, and you can get message from there.
Double click the OnDeviceTokenReceived event in TPushEvent, and you can get the device token nesseary for push server. Here you should send these infomation to your own GCM Sever by Indy for example.
Goto Project option, in Entilement List, check support push notification.
In your project directory, there's a file named AndroidManifest.template.xml. Just manually add
<service android:name="com.embarcadero.gcm.notifications.GCMIntentService" />
right before</application>
No more customized java codes needed !
PushEvents.StartupNotification works great when your app is launched by click on push notification. You can also get what message is in that returned object. If you don't use this, you can't get push message from OnPushRecevied evnet (somehow seems a bug).
If you need GCM server for testing, just leave comments. I will send or upload files.
回答2:
AFAIK you cannot remove a specific notification from the notification list (PUSH). You have to remove it manually swiping it.
But you can know wich notification was pressed and clear all notifications (if you want) with:
procedure TFrmMain.ShowMenu;
var
LNotification: TPushData;
begin
LNotification := PushEvents.StartupNotification; //Notification that starts the app
try
if Assigned(LNotification) then
begin
//LNotification is your notification with all your sent data
//do something here
//Clear all notifications
NotificationCenter.CancelAll; //NotificationCenter: TNotificationCenter Component
end;
finally
LNotification.DisposeOf;
end;
end;
using the NotificationCenter component.
P.S.: I asked this to Sarina Dupont in her blog. Here the answer
来源:https://stackoverflow.com/questions/25205478/issue-with-gcm-push-notification-service-delphi-xe6