我正在Back4Apps上运行Parse,我已按照他们的指示向T介绍了如何为Android设置推送通知。
http://docs.back4app.com/docs/android/push-notification/send-push-dashboard/
我从Parse仪表板上发出通知,我的手机振动,有时甚至会显示1/2秒的通知然后立即消失,所以我知道我的手机正在接收它,我错过了什么?为什么不显示?
非常感谢。
主要应用:
public class MainApplication extends Application {
public MainApplication()
{
instance=this;
}
public static Context getContext()
{
return instance;
}
@Override
public void onCreate() {
super.onCreate();
// Enable Crash Reporting
ParseCrashReporting.enable(this);
Parse.enableLocalDatastore(this);
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("blah blah")
.clientKey("blah blah")
.server("https://parseapi.back4app.com/")
.enableLocalDataStore()
.build());
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("GCMSenderId", "123456789 etc");
installation.saveInBackground();
}
}
的build.gradle:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('src/main/java/libs/ParseCrashReporting-1.9.2.jar')
compile files('src/main/java/libs/picasso-2.5.2.jar')
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.parse:parsefacebookutils-v4-android:1.10.3@aar'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.parse:parse-android:1.13.1'
}
apply plugin: 'com.google.gms.google-services'
Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="adam.exercisedictionary">
<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="adam.exercisedictionary.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="adam.exercisedictionary.permission.C2D_MESSAGE" />
<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:name="adam.exercisedictionary.MainApplication"
android:theme="@style/AppTheme"
android:largeHeap="true">
<activity
android:name="adam.exercisedictionary.CategoryList"
android:label="Gym Exercises">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.default_searchable"
android:value=".SearchResultsActivity"/>
</activity>
<service android:name="com.parse.PushService" />
<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="adam.exercisedictionary" />
</intent-filter>
</receiver>
<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.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:123456789 etc" />
答案 0 :(得分:0)
您能否尝试创建一个扩展AppCompatActivity的Activity,而不是一个扩展Application的类?这可能是问题所在,因为您指向的教程使用的是该方法,而不是这个方法。
答案 1 :(得分:0)
上面的代码运行正常。我正在测试的设备有问题。我将APK发送给我朋友的几款Android设备试用,它运行正常,但它们收到了警报。我的设备上必须有一些东西抑制通知,我的应用程序允许在设备上通知,但它不会工作。
证明可以在多个设备上进行测试,以防万一它看起来应该工作且没有。