I am putted my logic in android background service,which will be start on onClick action of my sticky notification.Everything working fine but problems are:-
Below code is used for generate a sticky notification.
private void Notify() {
Context objContext = this.cordova.getActivity();
Intent objIntent = new Intent(objContext, ApiCallServeice.class);
PendingIntent pi = PendingIntent.getService(objContext, intNotificationId, objIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder builder = new Notification.Builder(objContext);
builder.setContentTitle("Click to get help.");
builder.setAutoCancel(false);
builder.setSmallIcon(objContext.getApplicationInfo().icon);
builder.setOngoing(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
}
builder.setContentIntent(pi);
builder.build();
myNotication = builder.getNotification();
manager.notify(intNotificationId, myNotication);
}
Please suggest me the solution or need to set any flag in my code.
For getting click on notification UI everwhere.We need to use the Remote View in which you can put the button overlay on whole layout and write click listener on that button
Below is the update code I am used:-
private void Notify() {
Context objContext=this.cordova.getActivity();
Intent objIntent = new Intent(objContext, ApiCallServeice.class);
PendingIntent pi = PendingIntent.getService(objContext, intNotificationId, objIntent, PendingIntent.FLAG_CANCEL_CURRENT);
RemoteViews objRemoteViews = new RemoteViews(objContext.getApplicationContext().getPackageName(), R.layout.your_notification_layout);
objRemoteViews.setOnClickPendingIntent(R.id.your_notification_clickable_button, pi);
Notification.Builder builder = new Notification.Builder(objContext);
builder.setAutoCancel(false);
builder.setSmallIcon(objContext.getApplicationInfo().icon);
objRemoteViews.setImageViewResource(R.id.img_icon, objContext.getApplicationInfo().icon);
builder.setOngoing(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
}
builder.setContent(objRemoteViews);
builder.build();
myNotication = builder.getNotification();
manager.notify(intNotificationId, myNotication);
}