So here are the three kind of layouts for a notification
i have been able to achieve all the three views,but i am facing weird problems I don't know which version supports what.
My app supports 4+ and i would like each and every version to support as many things as possible
Initially for api 16 and higher i was showing the layout 1(the top one in the picture below) .i.e there were buttons only in the big view but not in the normal view.I got complaints from people that they were unable to open to open the big view,hence they didn't see any buttons
So i added buttons in the normal view as well,you can see that in the picture(second layout)but now i am unable to open the big view....I even got a mail that the guy wasn't seeing any buttons now but he was able to see it earlier
Here is the code for notification
private void initNotification() {
if (android.os.Build.VERSION.SDK_INT < 16) {
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Just Another Music Player";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.flags = Notification.FLAG_ONGOING_EVENT;
Context context = getApplicationContext();
CharSequence contentTitle = (CharSequence) ma.NP_List
.get(ma.position).song;
CharSequence contentText = (CharSequence) ma.NP_List
.get(ma.position).Artist;
Intent notificationIntent = new Intent(this, Player.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
startForeground(NOTIFICATION_ID, notification);
}
if (android.os.Build.VERSION.SDK_INT >= 16) {
Intent intent = new Intent(this, Player.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
0);
Intent playIntent = new Intent(Player.BROADCAST_PLAYPAUSE);
PendingIntent playPendingIntent = PendingIntent.getBroadcast(
getApplicationContext(), 0, playIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Intent stopIntent = new Intent("stop");
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(
getApplicationContext(), 0, stopIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Intent previousIntent = new Intent(MyWidget.why);
PendingIntent previousPendingIntent = PendingIntent.getBroadcast(
getApplicationContext(), 0, previousIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Intent nextIntent = new Intent(MyWidget.BROADCAST_SWAP);
nextIntent.putExtra("nextprev", 1);
PendingIntent nextPendingIntent = PendingIntent.getBroadcast(
getApplicationContext(), 0, nextIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);
contentView.setImageViewResource(R.id.image, R.drawable.ic_launcher);
contentView.setTextViewText(R.id.title, ma.NP_List.get(ma.position).song);
contentView.setTextViewText(R.id.text, ma.NP_List.get(ma.position).Artist);
contentView.setOnClickPendingIntent(R.id.stop, stopPendingIntent);
RemoteViews customNotifView = new RemoteViews(getPackageName(), R.layout.notification_big);
customNotifView.setImageViewResource(R.id.image, R.drawable.ic_launcher);
customNotifView.setTextViewText(R.id.title, ma.NP_List.get(ma.position).song);
customNotifView.setTextViewText(R.id.text, ma.NP_List.get(ma.position).Artist);
customNotifView.setOnClickPendingIntent(R.id.bPrevious, previousPendingIntent);
customNotifView.setOnClickPendingIntent(R.id.bPlayPause, playPendingIntent);
customNotifView.setOnClickPendingIntent(R.id.bNext, nextPendingIntent);
customNotifView.setOnClickPendingIntent(R.id.stop, stopPendingIntent);
customNotifView.setImageViewResource(R.id.bPlayPause, ma.boolMusicPlaying1 == true ?
R.drawable.notification_pause
: R.drawable.notification_play);
Notification n = new Notification.Builder(this)
.setContent(contentView)
.setContentTitle(ma.NP_List.get(ma.position).song)
// .setContentText(ma.NP_List.get(ma.position).Artist)
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
// .setAutoCancel(true)
// .addAction(R.drawable.notification_prev, "",
// previousPendingIntent)
// .addAction(
// ma.boolMusicPlaying1 == true ? R.drawable.notification_pause
// : R.drawable.notification_play, "",
// playPendingIntent)
// .addAction(R.drawable.notification_next, "", nextPendingIntent)
.build();
n.bigContentView = customNotifView;
n.contentView=contentView;
startForeground(NOTIFICATION_ID, n);
}
}
Please guide me so that i can show buttons on as many device as possible:
0 comments:
Post a Comment