Кнопки действий OneSignal - PullRequest
0 голосов
/ 03 июля 2018

Я совершенно новичок в разработке приложений, Java и StackOverflow, и это мое первое приложение для Android.

Я реализовал OneSignal для доставки push-уведомлений. Я просто пытался добавить поддержку кнопок действий в уведомлениях.

Я хочу, чтобы моя SplashActivity запускалась, если пользователь нажимает на кнопку «Действие» с идентификатором: posts, и хочет запустить URL-адрес в веб-браузере, если пользователь нажимает на кнопку с идентификатором: app.

Итак, это мой ApplicationClass.java:

package com.ananya.brokenhearts;

import android.app.Application;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import com.onesignal.OSNotificationAction;
import com.onesignal.OSNotificationOpenResult;
import com.onesignal.OneSignal;
import org.json.JSONObject;

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

        OneSignal.startInit(this)
                .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
                .unsubscribeWhenNotificationsAreDisabled(true)
                .init();
    }

    private class NotificationOpenedHandler implements OneSignal.NotificationOpenedHandler
    {
        @Override
        public void notificationOpened(OSNotificationOpenResult result)
        {
            OSNotificationAction.ActionType actionType = result.action.type;
            JSONObject data = result.notification.payload.additionalData;
            String customKey;

            if (data != null)
            {
                customKey = data.optString("customKey", null);
                if (customKey != null)
                    Log.i("OneSignalExample", "customkey set with value: " + customKey);
            }

            if (actionType == OSNotificationAction.ActionType.ActionTaken)
                Log.i("OneSignalExample", "Button pressed with id: " + result.action.actionID);

            if (result.action.actionID.equals("posts"))
            {
                Intent intent = new Intent(ApplicationClass.this, SplashActivity.class);
                startActivity(intent);
            } else if (result.action.actionID.equals("app"))
            {
                String url = "http://app.brokenhearts.ml/";
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);
            }
        }
    }
}

Итак, проблема в том, что независимо от того, на какую кнопку «Действие» я нажимаю, она просто отклоняет уведомление.

Я не знаю, какие еще файлы нужны. Итак, вот мой AndroidManifest.xml, на всякий случай:

<?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.ananya.brokenhearts"
    android:installLocation="auto" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="22" />
    <uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="AllowBackup"
        android:fullBackupContent="@xml/backup_descriptor"
        android:name=".ApplicationClass">

        <meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE"/>

        <activity android:name=".SplashActivity"
            android:theme="@style/Splash">

            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/plain"/>
            </intent-filter>

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

            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data
                    android:scheme="http"
                    android:host="brokenhearts.ml"/>
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:scheme="https"
                    android:host="brokenhearts.ml"/>
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:scheme="http"
                    android:host="www.brokenhearts.ml"/>
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data
                    android:scheme="https"
                    android:host="www.brokenhearts.ml"/>
            </intent-filter>

        </activity>

        <activity android:name=".MainActivity">
        </activity>

    </application>

</manifest>

Может кто-нибудь, пожалуйста, покажите мне, где я иду не так. Это будет высоко оценено.

...