Android解析推送通知不会在状态栏上显示消息

时间:2015-01-29 17:34:18

标签: java android parse-platform

我正在使用解析1.8.2进行pusch通知,我在状态栏上显示notyfication时遇到问题。 一切正常,但无法在状态栏上显示消息

这是我的清单

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sklep.parse5000" >

    <uses-sdk android:minSdkVersion="16"
              android:targetSdkVersion="16"
              android:maxSdkVersion="21" />

    <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" />

    <!--
      IMPORTANT: Change "com.parse.tutorials.pushnotifications.permission.C2D_MESSAGE" in the lines below
      to match your app's package name + ".permission.C2D_MESSAGE".
    -->
    <permission android:protectionLevel="signature"
        android:name="com.example.sklep.parse5000.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.example.sklep.parse5000.permission.C2D_MESSAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:name="com.example.sklep.parse5000.parseApplication">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>




        <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.USER_PRESENT" />
            </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" />

                <!--
                  IMPORTANT: Change "com.parse.tutorials.pushnotifications" to match your app's package name.
                -->
                <category android:name="com.example.sklep.parse5000" />
            </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>

        <!-- replace @drawable/push_icon with your push icon identifier -->
        <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/ic_launcher"/>

    </application>

</manifest>

这是我的应用程序类:

package com.example.sklep.parse5000;

import android.app.Application;
import android.util.Log;

import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParsePush;
import com.parse.SaveCallback;

public class parseApplication extends Application
{
    @Override
    public void onCreate()
    {
        super.onCreate();
        Parse.initialize(this, "OZjHkd8P7C5QH7Pvug750Jpk03VSvdqP8eiIhw4H", "JfiCdqs89jOe0A33ulnu2sEvJ67z9DtWTUZeApLQ");
        ParsePush.subscribeInBackground("", new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (e == null) {
                    Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
                } else {
                    Log.e("com.parse.push", "failed to subscribe for push", e);
                }
            }
        });
    }

MainActivity为空。我添加nothig,只是空白项目。 请帮我这个状态栏

日志

01-29 22:10:00.383  16797-16797/com.example.sklep.parse5000 W/IInputConnectionWrapper﹕ getExtractedText on inactive InputConnection
01-29 22:12:55.647  16797-16797/com.example.sklep.parse5000 E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
01-29 22:12:55.647  16797-16797/com.example.sklep.parse5000 E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
01-29 22:13:14.297  17783-17787/com.example.sklep.parse5000 D/dalvikvm﹕ GC_CONCURRENT freed 274K, 15% free 9539K/11143K, paused 19ms+2ms, total 44ms
01-29 22:13:14.387  17783-17783/com.example.sklep.parse5000 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
01-29 22:13:14.387  17783-17783/com.example.sklep.parse5000 W/dalvikvm﹕ VFY: unable to resolve virtual method 11516: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
01-29 22:13:14.387  17783-17783/com.example.sklep.parse5000 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-29 22:13:14.387  17783-17783/com.example.sklep.parse5000 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
01-29 22:13:14.387  17783-17783/com.example.sklep.parse5000 W/dalvikvm﹕ VFY: unable to resolve virtual method 11522: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
01-29 22:13:14.387  17783-17783/com.example.sklep.parse5000 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-29 22:13:14.387  17783-17783/com.example.sklep.parse5000 I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
01-29 22:13:14.387  17783-17783/com.example.sklep.parse5000 W/dalvikvm﹕ VFY: unable to resolve virtual method 9187: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
01-29 22:13:14.387  17783-17783/com.example.sklep.parse5000 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
01-29 22:13:14.422  17783-17783/com.example.sklep.parse5000 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
01-29 22:13:14.422  17783-17783/com.example.sklep.parse5000 W/dalvikvm﹕ VFY: unable to resolve virtual method 11519: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
01-29 22:13:14.422  17783-17783/com.example.sklep.parse5000 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0007
01-29 22:13:14.427  17783-17783/com.example.sklep.parse5000 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
01-29 22:13:14.427  17783-17783/com.example.sklep.parse5000 W/dalvikvm﹕ VFY: unable to resolve virtual method 417: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-29 22:13:14.427  17783-17783/com.example.sklep.parse5000 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-29 22:13:14.427  17783-17783/com.example.sklep.parse5000 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
01-29 22:13:14.432  17783-17783/com.example.sklep.parse5000 W/dalvikvm﹕ VFY: unable to resolve virtual method 439: Landroid/content/res/TypedArray;.getType (I)I
01-29 22:13:14.432  17783-17783/com.example.sklep.parse5000 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-29 22:13:14.612  17783-17783/com.example.sklep.parse5000 D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
01-29 22:13:14.617  17783-17783/com.example.sklep.parse5000 D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
01-29 22:13:14.622  17783-17783/com.example.sklep.parse5000 D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
01-29 22:13:14.627  17783-17783/com.example.sklep.parse5000 D/﹕ Device driver API match
    Device driver API version: 10
    User space API version: 10
01-29 22:13:14.627  17783-17783/com.example.sklep.parse5000 D/﹕ mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Thu Oct 25 08:43:05 KST 2012
01-29 22:13:14.652  17783-17783/com.example.sklep.parse5000 D/OpenGLRenderer﹕ Enabling debug mode 0
01-29 22:13:14.697  17783-17787/com.example.sklep.parse5000 D/dalvikvm﹕ GC_CONCURRENT freed 289K, 14% free 9755K/11335K, paused 13ms+2ms, total 35ms
01-29 22:13:15.142  17783-17783/com.example.sklep.parse5000 D/com.parse.push﹕ successfully subscribed to the broadcast channel.
01-29 22:13:18.382  17783-17787/com.example.sklep.parse5000 D/dalvikvm﹕ GC_CONCURRENT freed 385K, 15% free 9823K/11527K, paused 12ms+12ms, total 44ms
01-29 22:13:25.717  17783-17783/com.example.sklep.parse5000 W/IInputConnectionWrapper﹕ getSelectedText on inactive InputConnection
01-29 22:13:25.717  17783-17783/com.example.sklep.parse5000 W/IInputConnectionWrapper﹕ setComposingText on inactive InputConnection
01-29 22:13:25.722  17783-17783/com.example.sklep.parse5000 W/IInputConnectionWrapper﹕ getExtractedText on inactive InputConnection
01-29 22:13:33.982  17783-17783/com.example.sklep.parse5000 E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
01-29 22:13:33.982  17783-17783/com.example.sklep.parse5000 E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
01-29 22:14:21.462  17783-17783/com.example.sklep.parse5000 W/IInputConnectionWrapper﹕ getSelectedText on inactive InputConnection
01-29 22:14:21.462  17783-17783/com.example.sklep.parse5000 W/IInputConnectionWrapper﹕ setComposingText on inactive InputConnection
01-29 22:14:21.462  17783-17783/com.example.sklep.parse5000 W/IInputConnectionWrapper﹕ getExtractedText on inactive InputConnection
01-29 22:14:21.462  17783-17783/com.example.sklep.parse5000 W/IInputConnectionWrapper﹕ getSelectedText on inactive InputConnection
01-29 22:14:21.467  17783-17783/com.example.sklep.parse5000 W/IInputConnectionWrapper﹕ setComposingText on inactive InputConnection
01-29 22:14:21.467  17783-17783/com.example.sklep.parse5000 W/IInputConnectionWrapper﹕ getExtractedText on inactive InputConnection

2 个答案:

答案 0 :(得分:0)

在您的清单中

,我没有看到您的targetSdkVersion或minSdkVersion,在这种情况下,应用程序将使用sdk版本1作为默认值, 但是Parse Push需要Atleast sdk api 9(GingerBread),所以推送不起作用。

以下是更多信息 - &gt; http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

答案 1 :(得分:0)

你必须扩展ParsePushBroadcastReceiver,并覆盖onPushOpened()

以下示例

public class Receiver extends ParsePushBroadcastReceiver 
{
    @Override
    public void onPushOpen(Context context, Intent intent) 
    {     

        Intent mIntent = new Intent(context, Activity.class);
        mIntent.putExtras(intent.getExtras());
        mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);    

        //if overriding onPushOpen, we have to manually track opened intent events
        ParseAnalytics.trackAppOpenedInBackground(mIntent);

        //start activity
        context.startActivity(mIntent);
    }

    @Override
    protected int getSmallIconId(Context context, Intent intent) 
    {   
        return R.drawable.push_notification_icon; 
    }
}

不要忘记将此广播接收器添加到MANIFEST。祝你好运!