2016-07-14 10 views
1

とカスタム通知を作成します。たぶん私はそれと対話することはできません。これは私のレイアウトです:私はRemoteViewsではなく、成功を使用しようとしたこの</p> <p><a href="https://i.stack.imgur.com/sBddb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sBddb.png" alt="enter image description here"></a></p> <p>のような着信コールを処理し、通知を作成するカスタムビュー

<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を使用する標準通知です。

あなたが見ている動作は、setFullScreenIntent()(それは長い時間の間、どのように表示されているか)、または優先度が高く、着信音や振動を使用する場合にのみトリガーされるheads up notificationです。

+0

ありがとうございますが、ヘッドアップ通知でどのように作業できますか? CALLINGのようなモードがありますか? –

+0

'呼び出しのようないくつかのモード' - 私の答えで言及している 'setFullScreenIntent()'のような意味ですか? – ianhanniballake

関連する問題

 関連する問題