Reputation: 400
I have the header file for pendingIntent
Intent i=new Intent();
PendingIntent pi= new PendingIntent.getActivity(MainActivity.this,0,i,0);
This seems to not be working
Here is my whole code
package com.example.srinabh.notof;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=findViewById(R.id.notif);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i=new Intent();
PendingIntent pi= new PendingIntent.getActivity(MainActivity.this,0,i,0);
Notification n=new Notification.Builder(MainActivity.this)
.setTicker("Ticker Title")
.setContentTitle("Content Titlle")
.setContentText("Content Text")
.setContent(pi)
.getNotification();
n.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager nm= (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}
});
}
}
Upvotes: 0
Views: 389