在我自己的服务器上通过解析向Android设备发送推送通知时出现问题

时间:2019-05-20 10:33:22

标签: android firebase parse-platform push-notification

我正在使用this docker image的解析推送通知。

在配置服务器和仪表板发送带有curl的对象之后就可以了。 但是我很困惑如何使用此服务器向Android设备发送推送通知!在我的服务器上,我一直无法连接互联网,我的问题是fcm是否可以发送推送?还是从解析服务器接收来自android设备的推送的唯一方法?

使用以下代码运行我的应用程序后,将保存安装记录,我可以从分析仪表板中看到该记录。但是在发送推送时,Android设备不会收到推送。 需要将解析服务器连接到Firebase进行解析吗? (如果是,如何配置以将fcm与parse集成)(如果否,如何配置解析服务器或android应用以接收推送?)

这是我的实现:

(将google-services.json添加到应用目录中)

build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.test.project"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1" 
        multiDexEnabled true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }



dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.20.0"
    implementation "com.github.parse-community.Parse-SDK-Android:parse:1.20.0"
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'
}

应用程序类:

OkHttpClient.Builder builder = new OkHttpClient.Builder();
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.networkInterceptors().add(httpLoggingInterceptor);

Parse.initialize(new Parse.Configuration.Builder(this)
                .applicationId("APP_ID")
                .enableLocalDataStore()
                .server("http://ServerIp:1337/parse/")
                .clientBuilder(builder)
                .build()
        );
        Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG);
        ParsePush.subscribeInBackground("channel1", new SaveCallback() {
            @Override
            public void done(ParseException e) {
                Log.e(LOG_TAG, "Successfully subscribed to Parse!");
            }
        });

        ParseInstallation.getCurrentInstallation().saveInBackground();

清单服务和接收者:

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <permission
        android:name="ir.meedc.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="ir.meedc.permission.C2D_MESSAGE" />

    <application
        android:name=".App"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:supportsRtl="false"
        android:usesCleartextTraffic="true">

        <receiver
            android:name=".service.parsePush"
            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="info.androidhive.parsenotifications" />
            </intent-filter>
        </receiver>-->

        <service
            android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

        <service android:name="com.parse.fcm.ParseFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <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.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>

        <activity
            android:name=".ActivityMain"
            android:configChanges="orientation|screenSize"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:windowSoftInputMode="adjustNothing">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
</manifest>

安装记录已保存。

installation record on dashboard

从仪表板或api卷曲发送的某些推送。

sent pushes

(已解决) 最后,我弄清楚了配置可以传递给parse-server初始化命令。只需创建一个文件并将其传递给parse-server命令即可。

0 个答案:

没有答案