gpt4 book ai didi

android - OneSignal - ANDROID - NotificationExtenderService

转载 作者:行者123 更新时间:2023-11-29 23:05:43 30 4
gpt4 key购买 nike

自一周前以来,我在使用 OneSignal 时遇到了问题,并且在我的应用程序被终止时点击通知时我正在做一些事情。经过研究,我发现我的问题是我没有使用 NotificationExtenderService

但是我不知道如何实现这个。我读到的是这是作为类实现的,但我不明白 - 我是否必须使用该名称创建一个单独的文件类,或者在我的 MainActivity 中创建类?我也不知道在那里做什么。

谢谢!

OneSignal
.startInit(MagHomeActivity.this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.setNotificationReceivedHandler(new OneSignal.NotificationReceivedHandler() {
@Override
public void notificationReceived(OSNotification notification) {
final String notificationID = notification.payload.notificationID;
JSONObject tags = new JSONObject();
try {
MagServices service = MagApplication.getRetrofitAuth(MagHomeActivity.this)
.create(MagServices.class);
Call<ResponseBody> magazines = service.registerNotification(notificationID);
magazines.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {

}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {

}
});

} catch (Exception e) {
e.printStackTrace();
}
}
})
.setNotificationOpenedHandler(new OneSignal.NotificationOpenedHandler() {
@Override
public void notificationOpened(OSNotificationOpenResult result) {
Intent intent = new Intent(MagHomeActivity.this,MagMyMessageActivity.class);
startActivity(intent);
}
})
.init();

最佳答案

您可以将它放在专门针对该类的单独文件中。例如……

NotificationExtenderExample.java

import android.support.v4.app.NotificationCompat;
import com.onesignal.OSNotificationPayload;
import com.onesignal.NotificationExtenderService;
import java.math.BigInteger;

public class NotificationExtenderExample extends NotificationExtenderService {
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
OverrideSettings overrideSettings = new OverrideSettings();
overrideSettings.extender = new NotificationCompat.Extender() {
@Override
public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
// Sets the background notification color to Green on Android 5.0+ devices.
return builder.setColor(new BigInteger("FF00FF00", 16).intValue());
}
};

OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);
Log.d("OneSignalExample", "Notification displayed with id: " + displayedResult.androidNotificationId);

return true;
}
}

然后,将以下内容添加到您的 AndroidManifest.xml

<service
android:name=".YOUR_CLASS_NAME"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender" />
</intent-filter>
</service>

来源: https://documentation.onesignal.com/docs/service-extensions#section-notification-extender-service-span-class-label-all-label-android-android-span-

关于android - OneSignal - ANDROID - NotificationExtenderService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56580587/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com