【发布时间】:2014-11-21 08:40:34
【问题描述】:
我一直在尝试制作一个在 Android 上接收 Parse Push 通知的简单 Phonegap 应用。 我已经阅读了许多教程并在这里和其他地方阅读了相关问题,但我似乎无法让它在不崩溃的情况下工作。
我有最新的 Java JDK、Cordova + Node JS + plugman、Android API 19(cordova 似乎需要)、Apache ant 等...
底线:我可以启动应用程序。我可以很好地收到通知。但是当我点击通知返回应用程序时,它总是崩溃。
问题?谁能解释为什么会这样?或者如果你有一个可以工作的示例项目会更好?任何帮助将不胜感激。
参考资料:
https://parse.com/tutorials/android-push-notifications
http://www.raymondcamden.com/2012/10/10/PhoneGap-Parsecom-and-Push-Notifications -- 有点过时了
How do I get Parse.com Push Notifications working in a Cordova/Phonegap Android app?
apache cordova app crashes after receiving parse.com push notification
来源:
AndroidManifest.xml
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.company.challenger" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.company.challenger.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.company.challenger.permission.C2D_MESSAGE" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:name="com.company.challenger.ChallengerApplication">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:launchMode="singleTop" android:name="ChallengerApplication" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver" 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.company.challenger" />
</intent-filter>
</receiver>
<receiver android:exported="false" android:name="com.parse.ParsePushBroadcastReceiver">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
</manifest>
CordovaApp.java
package com.company.challenger;
import com.parse.ParseAnalytics;
import android.os.Bundle;
import org.apache.cordova.*;
public class CordovaApp extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
ParseAnalytics.trackAppOpened(getIntent());
}
}
ChallengerApplication.java
package com.company.challenger;
import android.app.Application;
import android.content.Context;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.PushService;
import com.company.challenger.CordovaApp;
public class ChallengerApplication extends Application
{
private static ChallengerApplication instance = new ChallengerApplication();
public ChallengerApplication() {
instance = this;
}
public static Context getContext() {
return instance;
}
@Override
public void onCreate() {
super.onCreate();
// register device for parse
Parse.initialize(this, "app key", "client key");
PushService.setDefaultPushCallback(this, CordovaApp.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
【问题讨论】:
-
如果您使用的是phonegap,那么为什么要解析Android api 而不是JS api?
-
据我了解,您仍然需要使用 parse 注册 android 安装以接收推送通知。只有推送安装与 Andoird 一起使用。剩下的就是 JS
-
这有什么更新吗?有类似的问题。
-
请在此处查看我的答案。 stackoverflow.com/questions/24685462/…
-
我最终通过混合和匹配来自不同来源的代码,拼凑出一些可行的东西。从解析推送指南开始,然后添加一个 Cordova 解析推送插件是一个好的开始。其中一些真的很旧或略有损坏,因此需要进行一些调整。
标签: android cordova parse-platform push-notification