2012-05-09 27 views
5

sul mio cellulare HTC il RemoteView per le notifiche si presenta come l'immagine qui sotto ...Si tratta di un layout Android Notification (RemoteView) di serie?

enter image description here

vorrei utilizzare lo stesso layout (immagine, testo in grassetto e testo di piccole dimensioni) per una notifica nel mio app ma non riesco a capire se si tratta di un layout Android o meno. Ho creato il mio layout, ma non è proprio la stessa cosa e mi piacerebbe attenermi allo "standard", se possibile.

Utilizzo di eclipse Ho provato a digitare android.R.layout. per vedere quali erano i suggerimenti ma non riesco a vederli con un nome che suggerirebbe un layout di notifica.

È un layout Android di magazzino? In tal caso, come posso accedervi?

risposta

5

È un layout di notifica Android standard e non è necessario creare il proprio layout personalizzato. Basta usare l'API di notifica esistente per impostare drawable, titolo e testo. Di seguito è riportato un esempio, utilizzando NotificationCompat.Builder dalla libreria di compatibilità:

Intent notificationIntent = new Intent(this, ActivityHome.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setContentIntent(pendingIntent) 
     .setWhen(System.currentTimeMillis()) 
     .setTicker(getText(R.string.notification_ticker)) 
     .setSmallIcon(R.drawable.notification_icon) 
     .setContentTitle(getText(R.string.notification_title)) 
     .setContentText(getText(R.string.notification_text)); 

mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification()); 

E lo stesso utilizzando Notification classe:

Notification notification = new Notification(R.drawable.notification_icon, getText(R.string.notification_ticker), System.currentTimeMillis()); 

Intent notificationIntent = new Intent(this, ActivityHome.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

notification.setLatestEventInfo(this, getString(R.string.notification_title), getText(R.string.notification_text), pendingIntent); 

mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification()); 
Problemi correlati