Fivos
Fivos

Reputation: 568

Open other App from Notification

Is it possible to start another App from a Notification? e.g. the Native App for making calls. My code is the followng but cannot start the calling App.

NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_call_white_24dp)
                    .setContentTitle("My notification")
                    .setContentText("Hello World!");

    Intent myIntent = new Intent(Intent.ACTION_CALL);
    myIntent.setData(Uri.parse("694154257"));      

    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    this,
                    0,
                    myIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );

    mBuilder.setContentIntent(resultPendingIntent).addAction(R.drawable.ic_call_white_24dp, "Make phone call", resultPendingIntent);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.build());

Upvotes: 0

Views: 571

Answers (1)

Anggrayudi H
Anggrayudi H

Reputation: 15155

Why don't you use:

Intent myIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:694154257"));

Btw, avoid using notification's id that less than 1:

mNotificationManager.notify(12, mBuilder.build());

For more information:

Sending the User to Another App

Upvotes: 1

Related Questions