How to open a URL directly from the notification

Asked

Viewed 573 times

3

I want to clear an application to open Urls that redirect to the Play Store and I want you to just load the direct URL in the notification without Bir any layout, and appear in the android intent filter, Ex: (Complete this action using: Chrome, Browser, Redirect Browser). But I don’t know how to do it. I started creating the code:

public class MainActivity  extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        public void alerta (View v) {

        Notification.Builder notification = new Notification.Builder(this);
        notification.setContentTitle("Carregando página da Web...");
        notification.setContentText("A Play Store se abrira ao concluir");
        notification.setSmallIcon((R.drawable.ic_launcherrb));
        notification.setSound(Uri.parse("/system/media/audio/notifications/Argon.ogg"));


        notification.build();

        NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        int NOTIFICATION_ID = 0;
        nm.notify(NOTIFICATION_ID, notification.build());

}}

Can someone help me??

1 answer

4

Should create a Pendingintent as follows:

Intent intent= new Intent(Intent.ACTION_VIEW,Uri.parse(A_Sua_URL));
PendingIntent pIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);

and add it to the notification thus:

notification.setContentIntent(pIntent);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.