[英]Android Push Notifications - Parse.com API - Not working?
Here is the application code: 这是应用程序代码:
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();
}
}
Although subscribing to the channel wasn't mentioned in Docs, but when I tested, I did successfully subscribe. 尽管没有在文档中提及订阅该频道,但是当我进行测试时,我确实成功订阅了该频道。 If I put some random string in it wouldn't work so probably "testNotification" happens to be correct.
如果我在其中放入一些随机字符串将不起作用,那么“ testNotification”可能恰好是正确的。 Here is the manifest:
这是清单:
<?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>
I removed the application tags to make the code small. 我删除了应用程序标签以使代码更小。
Both <service>
and <receiver>
tags must be inside <application></application>
exactly like the <activity>
not outside so insert them inside <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>
and remove them from any other place outside 并将它们从外面的任何其他地方移走
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.