2016-07-14 3 views
1

Я хочу, чтобы создать уведомление о том, обрабатывать входящие вызовы, как этотСоздание пользовательских уведомлений с пользовательской точки зрения

enter image description here

Я попытался использовать RemoteViews, но не успех. Возможно, я не могу с этим взаимодействовать. Это мой макет:

<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> 

Это мое шоу функция уведомления:

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()); 
    } 

Может кто-нибудь сказать мне об этом?

ответ

4

Это не требует специального уведомления - это стандартное уведомление, использующее стандарт notification actions.

Поведение, которое вы видите, это heads up notification, который запускается только в том случае, если вы используете setFullScreenIntent() (который также является видимым в течение длительного периода времени) и/или имеет высокий приоритет и использует рингтоны или вибрации.

+0

Спасибо, но как мы можем работать с уведомлением Heads? Есть ли такой режим, как CALLING? –

+0

«Какой-то режим, как вызов» - вы имеете в виду, как 'setFullScreenIntent()« Я упоминаю в своем ответе? – ianhanniballake

Смежные вопросы