2016-07-14 25 views
1

Ich möchte eine Benachrichtigung erstellen, dieErstellen von benutzerdefinierten Benachrichtigung mit benutzerdefinierten Ansicht

enter image description here

Ich habe versucht, wie diese eingehenden Anruf behandeln RemoteViews zu verwenden, aber nicht den Erfolg. Vielleicht kann ich nicht damit umgehen. Das ist mein Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:padding="10dp"> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginRight="10dp" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/title" 
      style="Custom Notification Title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/image" 
      android:text="aasdasdasd" /> 

     <TextView 
      android:id="@+id/text" 
      style="Custom Notification Text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/title" 
      android:layout_toRightOf="@id/image" 
      android:text="aasdasdasd" /> 

    </LinearLayout> 


    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

Dies ist meine Show Benachrichtigungsfunktion:

private void customNotification() { 
     RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.layout_custom_notification); 


     Intent intent = new Intent(this, CallingActivity.class); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 

     remoteViews.setImageViewResource(R.id.image, R.drawable.bank); 
     remoteViews.setTextViewText(R.id.title, "Custom notification"); 
     remoteViews.setImageViewResource(R.id.icon, R.drawable.individual); 
     remoteViews.setTextColor(R.id.title, ResourceUtil.getColorId(R.color.black)); 
     remoteViews.setTextViewText(R.id.text, "This is a custom layout"); 
     remoteViews.setTextColor(R.id.text, ResourceUtil.getColorId(R.color.black)); 
     AppWidgetManager.getInstance(this).updateAppWidget(getComponentName(), remoteViews); 

     NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
       .setSound(defaultSoundUri) 
       .setOngoing(true) 
       .setContentTitle("Calling") 
       .setContentText("Message") 
       .setSmallIcon(R.drawable.login_logo) 
       .setContentIntent(pendingIntent) 
       .setAutoCancel(true) 
       .setContent(remoteViews); 


     NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 


     mNotificationManager.notify(1, builder.build()); 
    } 

Kann mir jemand sagen, über diese?

Antwort

4

Das erfordert keine benutzerdefinierte Benachrichtigung - das ist eine Standardbenachrichtigung unter Verwendung des Standards notification actions.

Das angezeigte Verhalten ist ein heads up notification, das nur ausgelöst wird, wenn Sie setFullScreenIntent() verwenden (was auch für eine lange Zeit sichtbar bleibt) und/oder hohe Priorität hat und Klingeltöne oder Vibrationen verwendet.

+0

Danke, aber wie können wir mit Heads-up-Benachrichtigung arbeiten? Hat es einen Modus wie CALLING? –

+0

'Einige Modus wie Anruf' - Sie meinen wie die 'setFullScreenIntent()' ich in meiner Antwort erwähnen? – ianhanniballake

Verwandte Themen