简体   繁体   English

未收到解析Android通知

[英]Parse Android Notification not received

I followed thus tutorial for parse notification on android https://parse.com/apps/quickstart#parse_push/android/native/existing 我因此遵循了在Android https://parse.com/apps/quickstart#parse_push/android/native/existing上解析通知的教程

But I still can't receive the notifications in my App, this is my Manifest 但是我仍然无法在我的应用中收到通知,这是我的清单

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

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<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" />
<permission android:protectionLevel="signature"
    android:name="com.walid.app_247_parse.C2D_MESSAGE" />
<uses-permission android:name="com.walid.app_247_parse.C2D_MESSAGE" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">
    <activity android:name=".Splash">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".UserPhoneNumber" />
    <activity android:name=".MainPage" />
    <activity android:name=".ChatView" />
    <activity android:name=".Connect_Main" />

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyAZmjxQ_QZRG-0m-oMNcl0zC0H_eOEB8Jw" />

    <service android:name="com.parse.PushService" />
    <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="com.walid.app_247_parse" />
        </intent-filter>
    </receiver>
</application>

Also in my Launcher Activity I added these lines 同样在启动器活动中,我添加了以下几行

 Parse.initialize(this, getResources().getString(R.string.ParseAppID), getResources().getString(R.string.ParseClientID));

    ParseInstallation.getCurrentInstallation().saveInBackground();

    ParsePush.subscribeInBackground("247APP", new SaveCallback() {
        @Override
        public void done(com.parse.ParseException e) {
            Log.e("PARSE", "Successfully subscribed to Parse!");
        }


    });

And I can see the log of Successfully subscribed , and still whenever I send notification from parse.com nothing shown in my device. 而且,我可以看到“已成功订阅”的日志,并且无论何时我从parse.com发送通知时,设备上都没有显示任何内容。 Please note that I am testing the App on Asus Zenfone 2 running android 5. 请注意,我正在运行Android 5的Asus Zenfone 2上测试该应用程序。

Change 更改

Log.e("PARSE", "Successfully subscribed to Parse!");

to

if (e==null){
  Log.e("Parse", "Success");
} else {
  Log.e("PARSE", e.toString());
}

see what the error is or if it is actually successful for that portion. 查看错误是什么,或者该部分实际上是否成功。

Call Parse.initialize from the onCreate method of your Application class (instead of your Launcher Activity) 从Application类的onCreate方法(而不是Launcher Activity)调用Parse.initialize

AndroidManifest.xml AndroidManifest.xml中

<application
    android:name=".MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">

MyApplication.java MyApplication.java

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

        // Enable Local Datastore.
        Parse.enableLocalDatastore(this);

        // Add your initialization code here
        Parse.initialize(this, getResources().getString(R.string.ParseAppID), getResources().getString(R.string.ParseClientID));

        // Subscribe to a channel
        ParsePush.subscribeInBackground("twofourseven", new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (e == null) {
                    Log.d("PARSE", "Successfully subscribed to Parse channel");
                } else {
                    Log.d("PARSE", "Failed to subscribe to Parse channel");
                }
            }
        });

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

edit: 编辑:

package name + ".permission.C2D_MESSAGE" (missing .permission) 包名称+“ .permission.C2D_MESSAGE”(缺少.permission)

<permission android:protectionLevel="signature" android:name="com.walid.app_247_parse.permission.C2D_MESSAGE" />
<uses-permission android:name="com.walid.app_247_parse.permission.C2D_MESSAGE" />

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

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