我正在使用解析sdk for android并在Android棒棒糖5.0中测试我的应用程序。我可以在应用程序运行或后台时收到推送通知,但是当我将其删除或关闭它时,我无法接受。这是我的manifest.xml代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ver.verapp" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<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.ver.verapp.permission.C2D_MESSAGE" />
<uses-permission android:name="com.ver.verapp.permission.C2D_MESSAGE" />
<application
android:name="com.ver.verapp.MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="io.fabric.ApiKey"
android:value="Z8Uof8cKL0FTs118iLUOOsjY4" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity android:name=".MainActivity" >
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".Login"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/verapp_push"/>
<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="com.ver.verapp" />
</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.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
</manifest>
这是我的自定义应用程序代码:
public class MainApplication extends Application {
private static String TAG_SESSIONTOKEN ="sessionToken";
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "XXXX", "XXXX");
ParseInstallation.getCurrentInstallation().saveInBackground();
String Token = (String) ParseInstallation.getCurrentInstallation().get("deviceToken");
SharedPreferences prefs = getSharedPreferences("verapp", 0);
if(Token!=null)
{
SharedPreferences.Editor editor = prefs.edit();
editor.putString("tokenParse", Token);
editor.commit();
}
else
{
Token="";
}
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
答案 0 :(得分:0)
我明白了,我的Asus Zenfone 2有一个名为Start Manger的预先安装的应用程序阻止我的应用程序单独唤醒,我必须启用它,现在它正在工作。
答案 1 :(得分:0)
有同样的问题。这里:
**创建一个名为Service的新类。在那里,把它放在oncreate:**
Parse.initialize(this, "XXXX", "XXXX");
ParseInstallation.getCurrentInstallation().saveInBackground();
然后,转到您的清单并添加:
<application
name:"pacakge.name.to.ServiceClass"
...
>
...