GCM推送通知,如果应用程序在手机中关闭(Phonegap Android)
GCM Push notification if App is closed in mobile (Phonegap Android)
我正在将GCM与我的phonegap android应用程序一起使用。我面临的问题是,如果应用程序在手机中打开,它可以接收通知,但如果关闭,它就无法接收通知。我已经完成了java代码的编写,运行良好。但它无法与为接收消息而编写的javascript代码进行通信
public class GCMIntentService extends GCMBaseIntentService {
public static final String ME="GCMReceiver";
public GCMIntentService() {
super("GCMIntentService");
}
private static final String TAG = "GCMIntentService";
@Override
public void onRegistered(Context context, String regId) {
Log.v(ME + ":onRegistered", "Registration ID arrived!");
Log.v(ME + ":onRegistered", regId);
JSONObject json;
try
{
json = new JSONObject().put("event", "registered");
json.put("regid", regId);
Log.v(ME + ":onRegisterd", json.toString());
// In this case this is the registration ID
GCMPlugin.sendJavascript( json );
}
catch( JSONException e)
{
// No message to the user is sent, JSON failed
Log.e(ME + ":onRegisterd", "JSON exception");
}
}
@Override
public void onUnregistered(Context context, String regId) {
Log.d(TAG, "onUnregistered - regId: " + regId);
}
@Override
protected void onMessage(Context context, Intent intent) {
Log.d(TAG, "onMessage - context: " + context);
// Extract the payload from the message
Bundle extras = intent.getExtras();
if (extras != null) {
try
{
Log.v(ME + ":onMessage extras ", extras.getString("message"));
JSONObject json;
json = new JSONObject().put("event", "message");
json.put("message", extras.getString("message"));
json.put("msgcnt", extras.getString("msgcnt"));
Log.v(ME + ":onMessage ", json.toString());
GCMPlugin.sendJavascript( json );
// Send the MESSAGE to the Javascript application
}
catch( JSONException e)
{
Log.e(ME + ":onMessage", "JSON exception");
}
}
}
@Override
public void onError(Context context, String errorId) {
Log.e(TAG, "onError - errorId: " + errorId);
}
}
我认为您使用的是GCMPlugin插件。当应用程序进入后台或被销毁时,没有任何关于如何处理推送通知的内容。在我看来,最好删除这个插件并使用PushPlugin,否则你不仅要对GCMIntentservice.java,还要对GCMPlugin.java进行重大更改。
相关文章:
- onLoad function phonegap android
- GCM推送通知,如果应用程序在手机中关闭(Phonegap Android)
- Phonegap-Android 4.4-html5音频长度错误(javascript和媒体插件)
- phonegap Android中的pdf查看器
- 科尔多瓦 PhoneGap Android 回调与数据
- Phonegap (Android) - 数据库更改版本不起作用
- 访问设备'Phonegap Android中的本地日历
- 在phonegap android中上传多个文件时,使用jquery ui显示进度条
- 正在将数据URL(base64)保存到PhoneGap(android)上的文件中
- 如何在phonegap(android)中设置facebook好友生日提醒
- 如何隐藏PhoneGap Android SplashScreen
- 读取phonegap android应用程序中的本地文件
- 如何使我的phonegap android应用程序崩溃
- 阻止 YouTube API 在 PhoneGap Android 上全屏显示
- Phonegap Android Geolocation watch位置超时
- PhoneGap Android后退按钮需要按两次
- Phonegap android 向其他应用程序用户发送通知
- “在线”事件 Phonegap Android 未能在 StateChange 上开火
- Phonegap Android项目适用于模拟器,而不是实际的手机
- Phonegap Android 在输入焦点 Javascript 上显示键盘