Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2022, Leanplum, Inc. All rights reserved.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.leanplum;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.leanplum.LeanplumActivityHelper.NoTrampolinesLifecycleCallbacks;
import com.leanplum.callbacks.StartCallback;
import com.leanplum.callbacks.VariablesChangedCallback;
import com.leanplum.internal.ActionManager;
import com.leanplum.internal.Constants;
import com.leanplum.internal.Constants.Keys;
import com.leanplum.internal.Constants.Params;
import com.leanplum.internal.JsonConverter;
import com.leanplum.internal.LeanplumInternal;
import com.leanplum.internal.Log;
import com.leanplum.internal.PushActionPersistenceKt;
import com.leanplum.internal.Request.RequestType;
import com.leanplum.internal.RequestBuilder;
import com.leanplum.internal.Request;
import com.leanplum.internal.RequestSender;
import com.leanplum.internal.Util;
import com.leanplum.internal.VarCache;
import com.leanplum.utils.BuildUtil;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import androidx.core.app.NotificationCompat;
/**
* Leanplum push notification service class, handling initialization, opening, showing, integration
* verification and registration for push notifications.
*
* @author Andrew First, Anna Orlova
*/
public class LeanplumPushService {
/**
* Leanplum's built-in Google Cloud Messaging sender ID.
*/
public static final String LEANPLUM_SENDER_ID = "44059457771";
/**
* Intent action used when broadcast is received in custom BroadcastReceiver.
*/
public static final String LEANPLUM_NOTIFICATION = "LP_NOTIFICATION";
/**
* Action param key contained when Notification Bundle is parsed with {@link
* LeanplumPushService#parseNotificationBundle(Bundle)}.
*/
public static final String LEANPLUM_ACTION_PARAM = "lp_action_param";
/**
* Message title param key contained when Notification Bundle is parsed with {@link
* LeanplumPushService#parseNotificationBundle(Bundle)}.
*/
public static final String LEANPLUM_MESSAGE_PARAM = "lp_message_param";
/**
* Message id param key contained when Notification Bundle is parsed with {@link
* LeanplumPushService#parseNotificationBundle(Bundle)}.
*/
public static final String LEANPLUM_MESSAGE_ID = "lp_message_id";
private static final int NOTIFICATION_ID = 1;
private static final String OPEN_URL = "Open URL";
private static final String URL = "URL";
private static final String OPEN_ACTION = "Open";
private static Class extends Activity> callbackClass;
private static final PushProviders pushProviders = new PushProviders();
private static LeanplumPushNotificationCustomizer customizer;
private static boolean useNotificationBuilderCustomizer = false;
/**
* Get Cloud Messaging provider. By default - FCM.
*
* @return LeanplumCloudMessagingProvider - current provider
*/
@NonNull
static PushProviders getPushProviders() {
return pushProviders;
}
/**
* Changes the default activity to launch if the user opens a push notification.
*
* @param callbackClass The activity class.
*/
public static void setDefaultCallbackClass(Class extends Activity> callbackClass) {
LeanplumPushService.callbackClass = callbackClass;
}
/**
* Sets an object used to customize the appearance of notifications. Call this from your
* Application class's onCreate method so that the customizer is set when your application starts
* in the background.
*
* @param customizer LeanplumPushNotificationCustomizer push notification customizer.
*/
public static void setCustomizer(LeanplumPushNotificationCustomizer customizer) {
setCustomizer(customizer, false);
}
/**
* Sets an object used to customize the appearance of notifications. Call this from your
* Application class's onCreate method so that the customizer is set when your application starts
* in the background.
*
* @param customizer LeanplumPushNotificationCustomizer push notification customizer.
* @param useNotificationBuilderCustomizer True if if you want to support 2 lines of text on
* BigPicture style push notification.
*/
public static void setCustomizer(LeanplumPushNotificationCustomizer customizer,
boolean useNotificationBuilderCustomizer) {
LeanplumPushService.customizer = customizer;
LeanplumPushService.useNotificationBuilderCustomizer = useNotificationBuilderCustomizer;
}
private static Class extends Activity> getCallbackClass() {
return callbackClass;
}
private static boolean areActionsEmbedded(final Bundle message) {
return message.containsKey(Keys.PUSH_MESSAGE_ACTION);
}
private static void requireMessageContent(
final String messageId, final VariablesChangedCallback onComplete) {
Leanplum.addOnceVariablesChangedAndNoDownloadsPendingHandler(new VariablesChangedCallback() {
@Override
public void variablesChanged() {
try {
Map messages = VarCache.messages();
if (messageId == null || (messages != null && messages.containsKey(messageId))) {
onComplete.variablesChanged();
} else {
// Try downloading the messages again if it doesn't exist.
// Maybe the message was created while the app was running.
Request req = RequestBuilder
.withGetVarsAction()
.andParam(Params.INCLUDE_DEFAULTS, Boolean.toString(false))
.andParam(Params.INCLUDE_MESSAGE_ID, messageId)
.andType(RequestType.IMMEDIATE)
.create();
req.onResponse(new Request.ResponseCallback() {
@Override
public void response(JSONObject response) {
try {
if (response == null) {
Log.e("No response received from the server. Please contact us to " +
"investigate.");
} else {
Map values = JsonConverter.mapFromJson(
response.optJSONObject(Constants.Keys.VARS));
Map messages = JsonConverter.mapFromJson(
response.optJSONObject(Constants.Keys.MESSAGES));
Map regions = JsonConverter.mapFromJson(
response.optJSONObject(Constants.Keys.REGIONS));
List