1

I'm new to Android & also to Java....

I'm trying to get the Example of Pushy.me, it was working fine before I downloaded yesterday the last 2 Android Updates(yes I did update too late)...

New thing from Update: One UI 4.1

Now it's just doing nothing

Maybe someone knows where I'm wrong....

Here is the Code "PushReceiver"

    import androidx.core.app.NotificationCompat;
import me.pushy.sdk.Pushy;
import android.content.Intent;
import android.graphics.Color;
import android.content.Context;
import android.app.PendingIntent;
import android.media.RingtoneManager;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;

public class PushReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        // Attempt to extract the "title" property from the data payload, or fallback to app shortcut label
        String notificationTitle = intent.getStringExtra("title") != null ? intent.getStringExtra("title") : context.getPackageManager().getApplicationLabel(context.getApplicationInfo()).toString();

        // Attempt to extract the "message" property from the data payload: {"message":"Hello World!"}
        String notificationText = intent.getStringExtra("message") != null ? intent.getStringExtra("message") : "Test notification";

        // Prepare a notification with vibration, sound and lights
        NotificationCompat.Builder builder =  new NotificationCompat.Builder(context, "chanel_ID")
                .setAutoCancel(true)
                .setSmallIcon(R.mipmap.ic_notify)
                .setContentTitle(notificationTitle)
                .setContentText(notificationText)
                .setLights(Color.RED, 1000, 1000)
                .setVibrate(new long[]{0, 400, 250, 400})
                .setColor(context.getResources().getColor(R.color.colorPrimary))
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, Main.class), PendingIntent.FLAG_UPDATE_CURRENT));

        // Automatically configure a Notification Channel for devices running Android O+
        Pushy.setNotificationChannel(builder, context);

        // Get an instance of the NotificationManager service
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);

        // Build the notification and display it
        notificationManager.notify(1, builder.build());
    }
}

Here is also the Run Log if i try to send Notification from WebPush:

**

D/Pushy: Received push for package im.diego.mrschprachdienst
    {message=Hello World!}

** E/Pushy: Invoking push receiver via reflection failed java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at me.pushy.sdk.model.PushyCachedBroadcastReceiver.execute(PushyCachedBroadcastReceiver.java:22) at me.pushy.sdk.util.PushyBroadcastManager.sendBroadcast(PushyBroadcastManager.java:121) at me.pushy.sdk.util.PushyBroadcastManager.publishNotification(PushyBroadcastManager.java:107) at me.pushy.sdk.util.PushyMqttConnection.messageArrived(PushyMqttConnection.java:261) at me.pushy.sdk.lib.paho.internal.CommsCallback.deliverMessage(CommsCallback.java:475) at me.pushy.sdk.lib.paho.internal.CommsCallback.handleMessage(CommsCallback.java:379) at me.pushy.sdk.lib.paho.internal.CommsCallback.run(CommsCallback.java:183) at java.lang.Thread.run(Thread.java:920) Caused by: java.lang.IllegalArgumentException: im.zego.mrschluesseldienst: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. at android.app.PendingIntent.checkFlags(PendingIntent.java:382) at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:465) at android.app.PendingIntent.getActivity(PendingIntent.java:451) at android.app.PendingIntent.getActivity(PendingIntent.java:415) at im.zego.mrschluesseldienst.PushReceiver.onReceive(PushReceiver.java:32) ... 9 more

2 Answers2

2

Add this code below notificationText

PendingIntent pendingIntent = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
    pendingIntent = PendingIntent.getActivity
           (this, 0, new Intent(context, Main.class), PendingIntent.FLAG_MUTABLE);
}
else
{
     pendingIntent = PendingIntent.getActivity
            (this, 0, new Intent(context, Main.class), PendingIntent. FLAG_UPDATE_CURRENT);
}

then update your content intent

.setContentIntent(pendingIntent)

Note: Is still exist the issue , then update your SDK

Gobu CSG
  • 653
  • 5
  • 7
0

Update to the latest version of the Pushy Android SDK (1.0.84), which sets FLAG_IMMUTABLE when creating PendingIntents to comply with targetSdkVersion 31, by updating your app/build.gradle file:

implementation 'me.pushy:sdk:1.0.84'

More info: https://pushy.me/docs/android/get-sdk

Elad Nava
  • 7,746
  • 2
  • 41
  • 61