Skip to content

Commit 94ee339

Browse files
committed
feat(notifications): adding intent action
1 parent ce38a4c commit 94ee339

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

AndroidSDK/src/com/leanplum/LeanplumPushReceiver.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
import android.content.BroadcastReceiver;
2525
import android.content.Context;
2626
import android.content.Intent;
27-
import android.content.pm.ApplicationInfo;
28-
import android.content.pm.PackageManager;
29-
import android.os.Bundle;
3027

28+
import com.leanplum.internal.Constants;
3129
import com.leanplum.internal.LeanplumManifestHelper;
3230
import com.leanplum.internal.Log;
3331
import com.leanplum.internal.Util;
@@ -57,6 +55,10 @@ public void onReceive(Context context, Intent intent) {
5755
Log.d("Custom broadcast receiver class found, using it to handle push notifications.");
5856
// Forward Intent to a client broadcast receiver.
5957
Intent forwardIntent = new Intent();
58+
// Add action to be able to differentiate between multiple intents.
59+
String action = Util.buildIntentAction(context,
60+
Constants.ClassUtil.LEANPLUM_NOTIFICATION);
61+
forwardIntent.setAction(action);
6062
forwardIntent.setClassName(context, receiver);
6163
forwardIntent.putExtras(intent.getExtras());
6264
context.sendBroadcast(forwardIntent);

AndroidSDK/src/com/leanplum/internal/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,6 @@ public static class Messaging {
259259

260260
public static class ClassUtil {
261261
public static final String UI_INTERFACE_EDITOR = "com.leanplum.uieditor.LeanplumUIEditor";
262-
public static final String LEANPLUM_NOTIFICATION_RECEIVER = "LP_NOTIFICATION_RECEIVER";
262+
public static final String LEANPLUM_NOTIFICATION = "LP_NOTIFICATION";
263263
}
264264
}

AndroidSDK/src/com/leanplum/internal/LeanplumManifestHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public static String parseNotificationMetadata() {
531531
ApplicationInfo app = context.getPackageManager().getApplicationInfo(context.getPackageName(),
532532
PackageManager.GET_META_DATA);
533533
Bundle bundle = app.metaData;
534-
return bundle.getString(Constants.ClassUtil.LEANPLUM_NOTIFICATION_RECEIVER);
534+
return bundle.getString(Constants.ClassUtil.LEANPLUM_NOTIFICATION);
535535
} catch (Throwable ignored) {
536536
}
537537
return null;

AndroidSDK/src/com/leanplum/internal/Util.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,4 +969,18 @@ public static int generateIdFromResourceName(String resourceName) {
969969
Log.w("Could not extract resource id from provided resource name: ", resourceName);
970970
return 0;
971971
}
972+
973+
/**
974+
* Builds intent action in format PackageName + Action.
975+
*
976+
* @param context Surrounding context.
977+
* @param action Intent action.
978+
* @return Action in format com.example.Action.
979+
*/
980+
public static String buildIntentAction(Context context, String action) {
981+
if (context == null) {
982+
return null;
983+
}
984+
return context.getPackageName() + "." + action;
985+
}
972986
}

0 commit comments

Comments
 (0)