2016-11-20 9 views
0

私はカスタム通知にこのコードを使用しています。問題は、文字列内のテキスト全体が1行で表示されていることです。通知バーの操作ボタンが表示されません

 private void showNotification(String msg){ 
    //Creating a notification 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
    builder.setSmallIcon(R.drawable.ic_alert); 
    builder.setContentTitle("Alert"); 
    builder.setContentText(msg); 
    builder.setAutoCancel(false); 
    builder.setPriority(NotificationCompat.PRIORITY_HIGH); 
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com")); 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); 
    builder.setContentIntent(pendingIntent); 
    //builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)); 

    builder.addAction(R.drawable.ic_call, "Accept", pendingIntent).build(); 
    // builder.addAction(R.drawable.ic_alert, "Reject", pendingIntent).build(); 
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    notificationManager.notify(0, builder.build()); 


} 

答えて

0

テキストとアクションボタンのNotificationCompat.Actionの複数の行との通知にBigTextStyleを使用してください。

private void showNotification(String msg) { 
//Creating a notification 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(R.drawable.ic_alert); 
builder.setContentTitle("Alert"); 
builder.setContentText(msg); 
builder.setAutoCancel(false); 
builder.setPriority(NotificationCompat.PRIORITY_HIGH); 
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com")); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); 
builder.setContentIntent(pendingIntent); 
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)); 
builder.addAction(R.drawable.ic_call, "Accept", pendingIntent); 
// builder.addAction(R.drawable.ic_alert, "Reject", pendingIntent); 
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg)); 
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
notificationManager.notify(0, builder.build()); 
} 
+0

私は.........コードに次の行が、まだ同じ問題を追加したNotification.Builder =新しいNotification.Builder(この)釜; ........ buil.setStyle(new Notification.BigTextStyle() .bigText(msg)); .........新しいNotificationCompat.Action(R.drawable.ic_call、 "CALL"、pendingIntent); –

+0

あなたは[this](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#addAction(android.support.v4.app.NotificationCompat.Action))メソッドを呼び出しましたか?あなたの 'NotificationCompat.Builder'に? –

+0

setStyleはNotificationクラスによって呼び出されます。Notification.Builder buil = new Notification.Builder(this); –

関連する問題