Korsholm
Lurker
Hi.
I want to use notification manager on a device locked screen.
When a button is pushed in the notification i want to have a onclicklistener to trigger a counter.
But i can only get the notification manager to work with OnClickPendingIntent who is calling a intent and making the activity popup on the screen.
i cant figure out what to do so the activity not is called.
When i use onclicklistener the app crashes.
Regards Danni.
I want to use notification manager on a device locked screen.
When a button is pushed in the notification i want to have a onclicklistener to trigger a counter.
But i can only get the notification manager to work with OnClickPendingIntent who is calling a intent and making the activity popup on the screen.
i cant figure out what to do so the activity not is called.
When i use onclicklistener the app crashes.
Java:
NotificationPanel nPanel = new NotificationPanel(this);
public class NotificationPanel {
Context parent;
NotificationManager nManager;
NotificationCompat.Builder nBuilder;
RemoteViews remoteView;
NotificationPanel(Context parent) {
// TODO Auto-generated constructor stub
//this.parent = parent;
nBuilder = new NotificationCompat.Builder(parent)
.setContentTitle("Parking Meter")
.setSmallIcon(R.drawable.ic_toys)
.setOngoing(true);
remoteView = new RemoteViews(parent.getPackageName(), R.layout.notificationpanel);
//set the button listeners
setListeners(remoteView);
nBuilder.setContent(remoteView);
nManager = (NotificationManager) parent.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(2, nBuilder.build());
}
public void setListeners(RemoteViews view){
//listener 1
Intent volume = new Intent(parent,NotificationReturnSlot.class);
volume.putExtra("DO", "volume");
PendingIntent btn1 = PendingIntent.getActivity(parent, 0, volume, 0);
view.setOnClickPendingIntent(R.id.btn1, btn1);
//listener 2
Intent stop = new Intent(parent, NotificationReturnSlot.class);
stop.putExtra("DO", "stop");
PendingIntent btn2 = PendingIntent.getActivity(parent, 1, stop, 0);
view.setOnClickPendingIntent(R.id.btn2, btn2);
}
public void notificationCancel() {
nManager.cancel(2);
}
}
Java:
public class NotificationReturnSlot extends Hver_Del_Projekt {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
String action = (String) getIntent().getExtras().get("DO");
if (action.equals("volume")) {
Log.i("NotificationReturnSlot", "volume");
//Your code
} else if (action.equals("stopNotification")) {
//Your code
Log.i("NotificationReturnSlot", "stopNotification");
}
finish();
}
}
Regards Danni.