简体   繁体   English

Android推送通知未接收/未发送

[英]Android push notifications not receiving/not sending

I know that this question has been asked a lot, but many also went unanswered. 我知道这个问题已经问了很多,但很多人都没有回答。

However, I use Parse.com to send push-notifications to devices. 但是,我使用Parse.com将推送通知发送到设备。 On iOS it works fine. 在iOS上运行正常。 But it's not receives on Android devices. 但这不是在Android设备上收到的。

When I looking at Push tab on service page I see that no one push wasn't sent. 当我查看服务页面上的“推送”选项卡时,我看到没有发送任何推送。 Value in 'Pushes Sent' column is 0 (zero). “发送的推送”列中的值为0(零)。

Then I sent push through GCM (gcm-http.googleapis.com) and my device received the message. 然后,我通过GCM(gcm-http.googleapis.com)发送了推送,并且我的设备收到了该消息。

Perhaps the problem may be in settings of Parse.com? 也许问题出在Parse.com的设置中?

I was added Sender ID (Project number) & API Key from Google. Google为我添加了发件人ID(项目编号)和API密钥。

My AndroidManifest.xml immediately before the opening </application> tag: 我的AndroidManifest.xml紧接在</application>标记之前:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission android:name="my.app.name.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="my.app.name.permission.C2D_MESSAGE" />

My AndroidManifest.xml immediately before the closing </application> tag: 我的AndroidManifest.xml紧靠</application>标记之前:

    <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/ic_stat_bt"/>

    <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.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>
    <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="my.app.name" />
        </intent-filter>
</receiver>

My ApplicationClass 我的应用程式类别

package my.app.name;

import android.util.Log;
import android.os.Bundle;

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

public class MyApplication extends android.app.Application {
    @Override
    public void onCreate() {
        super.onCreate();

        // Parse
        Parse.initialize(this, "", "");
        ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
            public void done(ParseException e) {
                if (e == null) {
                    Log.d("com.parse.push", "successfully installed.");
                    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);
                        }
                    }
                });
            } else {
                Log.e("com.parse.push", "failed to install", e);
            }
        }
    });
}
...

On the advice of Clayton Oliveira I noticed, when I install my app and initialize it first time I get my token and pushes works fine. 在Clayton Oliveira的建议下,我注意到,当我安装应用程序并首次对其进行初始化时,我得到了我的令牌,并且推送工作正常。 But when I open my app again I get another token and pushes are not working until I delete all data from Parse, uninstall my app & install it again. 但是,当我再次打开应用程序时,我又得到了另一个令牌,直到我从Parse中删除所有数据后,推送才起作用,请卸载我的应用程序并重新安装。

Any ideas? 有任何想法吗?

I was facing the same problem just now ! 我现在正面临着同样的问题! Here's what did the trick: 诀窍如下:

I uninstalled my app and deleted all the data previously stored on Parse (Installation, Session and User). 我卸载了我的应用程序,并删除了先前存储在Parse中的所有数据(安装,会话和用户)。

After that, just install your app again and if you did everything right from the Parse tutorial: https://www.parse.com/tutorials/android-push-notifications 之后,只需再次安装您的应用,如果您正确执行了Parse教程中的所有操作,则: https : //www.parse.com/tutorials/android-push-notifications

Try send another Test Push ;) 尝试发送另一个测试推送;)

If you do not add the permission of the message then add it in to your manifest file. 如果您不添加消息的权限,则将其添加到清单文件中。

<uses-permission android:name="your.package.name.permission.C2D_MESSAGE"/>

and add this firebase lib in app's build.gradle file: 并在应用程序的build.gradle文件中添加此firebase lib:

compile 'com.google.firebase:firebase-messaging:11.0.4'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM