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

Posted

技术标签:

【中文标题】Android解析推送通知不会在状态栏上显示消息【英文标题】:Android parse push notyfication wont show message on status bar 【发布时间】:2015-01-29 17:34:18 【问题描述】:

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

这是我的清单

 <?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 为空。我什么都不加,只是空白项目。 请帮我处理这个状态栏

日志

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

【问题讨论】:

【参考方案1】:

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

这里有更多信息 --> http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

【讨论】:

推送工作正常,但在状态栏上不显示任何内容。添加 sdk versjon 没有任何改变。 @user3818006 您是否正在通过解析网站发送推送?能否请您发布更新后的清单和日志文件。 现在什么都没有了,我愚弄了这个parse.com/tutorials/android-push-notifications 这不起作用,但唯一的问题是我在桌面屏幕的顶部栏上看不到通知 初始化解析后添加这个 PushService.setDefaultPushCallback(this, MainActivity.class); 接受的答案可能会有所帮助 --> ***.com/questions/18592617/…【参考方案2】:

您必须扩展 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。祝你好运!

【讨论】:

以上是关于Android解析推送通知不会在状态栏上显示消息的主要内容,如果未能解决你的问题,请参考以下文章

如何在 ios 的横幅栏上发送未覆盖的苹果推送通知

Android中使用Notification在状态栏上显示通知

[Parse][Android] 如何在应用程序运行时禁止显示推送通知?

如何使用phonegap在状态栏上创建通知

个推消息推送SDK通知栏铃声功能解析及使用攻略

如果设备收到来自 fcm 的推送通知,如何向处于终止状态的 android 应用程序显示/通信/广播消息