应用程序关闭时,解析推送通知无法收到通知

时间:2014-06-19 07:13:39

标签: android push-notification broadcastreceiver parse-platform push

我尝试在我的Android中解析推送服务当应用程序运行时我的工作正常我可以收到通知但当我尝试在应用程序关闭时发送推送通知....我无法收到它并且它说不幸的是应用程序停止了 如何在应用关闭时收到通知

  public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);

   Parse.initialize(this, "xxxxx", "xxxxx");
   PushService.setDefaultPushCallback(this, OcSongs.class);
   PushService.startServiceIfRequired(this);
   ParseInstallation.getCurrentInstallation().saveInBackground();
   PushService.subscribe(this, "push", OcSongs.class);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_oc_songs);
        mWebView = (WebView) findViewById(R.id.webview);
        AdView ad = (AdView) findViewById(R.id.ad);
        ad.loadAd(new AdRequest());
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl(URL);
        loadingProgressBar=(ProgressBar)findViewById(R.id.progressbar_Horizontal); 
        mWebView.setWebChromeClient(new WebChromeClient()

        {

清单文件

     <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.freedownload.ocsongs"
android:versionCode="1"
android:versionName="1.0" ><uses-sdk
    android:minSdkVersion="4"
    android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <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.freedownload.ocsongs.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.freedownload.ocsongs.permission.C2D_MESSAGE" />                  <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >
    <activity         android:name="com.google.ads.AdActivity"android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
  /> 
   <activity
        android:label="@string/app_name"
        android:name=".splash" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <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.freedownload.ocsongs" />
</intent-filter>
                  </receiver>
     <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.RECEIVE_BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
                   </receiver>

    <activity
         android:configChanges="touchscreen|keyboardHidden|orientation"
        android:launchMode="singleTop"
        android:name="OcSongs" >
    </activity>

</application>

2 个答案:

答案 0 :(得分:0)

将此文件放入您的清单文件中。它会工作..

    <receiver android:name="com.parse.ParseBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
    <receiver android:name="your package name.YourCustomReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="your package name.UPDATE_STATUS" />
        </intent-filter>
    </receiver>

答案 1 :(得分:0)

这对我有用: https://stackoverflow.com/a/34830936/5588656

 Parse.enableLocalDatastore(this);

// Add your initialization code here
Parse.initialize(this, APP_ID, CL_ID);
ParseInstallation.getCurrentInstallation().saveInBackground();

ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
// defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);



// IF NEEADED
String topic ="YOUR_TOPIC";
System.out.println(topic);
ParsePush.subscribeInBackground(topic, new SaveCallback() {
    @Override
    public void done(ParseException e) {
        if (e == null) {
            Log.d("com.parse.push",
                    "successfully subscribed ");
        } else {
            Log.e("com.parse.push", "failed ", e);
        }
    }
});