这是应用程序代码:
import android.app.Application;
import android.util.Log;
import com.ghostriley.sgt.ghostchat.UI.MainActivity;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseInstallation;
import com.parse.ParseObject;
import com.parse.ParseAnalytics;
import com.parse.ParsePush;
import com.parse.ParsePushBroadcastReceiver;
import com.parse.PushService;
import com.parse.SaveCallback;
public class GhostChatApplication extends Application {
@Override
public void onCreate(){
super.onCreate();
Parse.initialize(this, "P0zIagKQvEGdopuoLZuucgzC7H4oz64U7GZkGe1n", "mT15MV8OFEMTDNQaGU5XdLHTXMsNxnUxJdXVp4O3");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
虽然在Docs中没有提到订阅该频道,但是当我测试时,我确实成功订阅了。如果我在其中放入一些随机字符串将无法工作,所以可能“testNotification”恰好是正确的。这是清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ghostriley.sgt.ghostchat" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<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>
<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.ghostriley.sgt.ghostchat" />
</intent-filter>
</receiver>
<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.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="com.ghostriley.sgt.ghostchat.C2D_MESSAGE" />
<uses-permission android:name="com.ghostriley.sgt.ghostchat.permission.C2D_MESSAGE" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<application
android:name=".GhostChatApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.ghostriley.sgt.ghostchat.UI.MainActivity" />
</activity>
</application>
</manifest>
我删除了应用程序标签以使代码变小。
<service>
和<receiver>
标签都必须在<application></application>
内部,就像<activity>
不在外面所以插入里面
<application
android:name=".GhostChatApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.ghostriley.sgt.ghostchat.UI.MainActivity" />
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<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>
<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.ghostriley.sgt.ghostchat" />
</intent-filter>
</receiver>
</application>
并将它们从外面的任何其他地方移走