Search code examples
javaandroidandroid-intentnotificationmanager

android notification pendinintent issue wrong 3rd argument type


On my app I'm getting an error trying to add a intent to a notification. Here is my notification here is my code...

public void notification(Context context,Bitmap bpm,File imagen)
{


    Intent pendingintent = new Intent();
    pendingintent.setAction(Intent.ACTION_VIEW);
    pendingintent.setDataAndType(Uri.fromFile(imagen),"image/*");
            //new Intent(Intent.ACTION_VIEW, Uri.parse(imagen.getAbsolutePath()));
    //context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(imagen.getAbsolutePath()))); /** replace with your own uri */
    PendingIntent intentpending = PendingIntent.getActivities(this.context,0,pendingintent,0);

    NotificationManager notification = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);


    Notification noti = new Notification.Builder(context)
            .setContentTitle("Nueva Pandi foto!")
            .setContentText("Foto recibida, clic para ver")
            .setSmallIcon(R.drawable.pandacamara)
            .setContentIntent(intentpending)
            .setLargeIcon(bpm)
            .setSound(Uri.parse("android.resource://aircam.prueba"+R.raw.sonidopanda))
            .setLights(-256, 100, 100)
            .build();
    notification.notify(0,noti);

}

I am able to see the notification whithout the Pendingintent. The problem is when adding the intent. This is the error I am getting

Error:(232, 52) error: no suitable method found for getActivities(Context,int,Intent,int) method PendingIntent.getActivities(Context,int,Intent[],int,Bundle) is not applicable (actual and formal argument lists differ in length) method PendingIntent.getActivities(Context,int,Intent[],int) is not applicable (actual argument Intent cannot be converted to Intent[] by method invocation conversion)

Compiler mark an error avobe PendingIntent intentpending (Intent pendingintent)

Wrong 3rd argument type found android.content.intent expected android.content.intent[]

Any help will be very apretiated :D. Sorry for my english, I am not a native speaker.


Solution

  • You need to call PendingIntent.getActivity() instead of PendingIntent.getActivities()

    But even that will not work because you need to use an explicit Intent (where you set the Activity class name) instead of an implicit intent (Action only).