Note that there are some explanatory texts on larger screens.

plurals
  1. POPlacing Buttons on a status notification
    text
    copied!<p>I would like to put two buttons on my notifications from the status bar. Of course they do not appear until the user touches to expand them. I have created the custom layout for my notification using RemoteViews but am unsure if it's possible to obtain a reference to them because of my current code structure. </p> <pre><code>@Override public void onMessage(Context context, Intent intent) { Log.w("C2DMReceiver", "Message Received, this is the message with no payload"); Bundle extras = intent.getExtras(); if (extras != null) { String[] payload = new String[3]; payload[0] = (String) extras.get("payload"); payload[1] = (String) extras.get("payload2"); SharedPreferences sharedP = Prefs.get(this); boolean inApp = sharedP.getBoolean("currentlyInApp", true); if (!inApp) { createNotification(context, payload); } } } public void createNotification(Context context, String[] payload) { SharedPreferences sharedP = Prefs.get(context); boolean needsToLogin = sharedP .getBoolean("loginFromNotification", true); Log.w("C2DMReceiver", "createNotification called"); NotificationManager notificationmanager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(this, WebViewActivity.class); Intent notificationIntent2 = new Intent(this, UniteActivity.class); PendingIntent pIntent; if (needsToLogin) { pIntent = PendingIntent.getActivity(this, 0, notificationIntent2, PendingIntent.FLAG_CANCEL_CURRENT); } else { pIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); } // Compatibility builder NotificationCompat.Builder notification = new NotificationCompat.Builder( context); RemoteViews remote = new RemoteViews(getPackageName(),R.layout.notification); //Button okButton = (Button) findViewById(R.layout.notification); notification.setAutoCancel(false); notification.setContent(remote); notification.setContentIntent(pIntent); notification.setWhen(System.currentTimeMillis()); notification.setTicker(payload[0]); notification.setSmallIcon(R.drawable.default1); notification.setContentTitle(payload[1]); notification.setContentText(payload[0]); long duration[] = { 100, 300, 100 }; notification.setVibrate(duration); notificationmanager.notify(0, notification.getNotification()); } </code></pre> <p>onMessage is a method pulled from the Google C2DM library where the notifications are generated by intents received from google. Without a view, how can I obtain a reference to my buttons using findViewById()? or some other means</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload