2017-05-26 16 views
0

一部の携帯電話は大きな通知をサポートしていません。だから私はどのようにランタイムに私のnotif大きなまたは通常のサイズを作ることを知ることができますか?また、私はサポートコントロールボタンが必要です。ここ は大きなNOTIFの私のコードです:Androidの大小通知

RemoteViews remoteViews = new RemoteViews(getPackageName(), 
      settings.getAttributeId(settings.getThemeByString(), R.attr.theme_dependent_notification)); 

    remoteViews.setOnClickPendingIntent(R.id.prev, ppreviousIntent); 
    remoteViews.setOnClickPendingIntent(R.id.play, pplayIntent); 
    remoteViews.setOnClickPendingIntent(R.id.next, pnextIntent); 
    remoteViews.setOnClickPendingIntent(R.id.close, pcloseIntent); 

    remoteViews.setImageViewBitmap(R.id.cover, icon); 
    remoteViews.setTextViewText(R.id.name, title); 
    remoteViews.setTextViewText(R.id.artist, text); 
    remoteViews.setTextViewText(R.id.count, count); 

    if (isPlayerActive) remoteViews.setImageViewResource(R.id.play, R.drawable.pause); 
    else remoteViews.setImageViewResource(R.id.play, R.drawable.play); 

    notification = new NotificationCompat.Builder(this) 
      .setSmallIcon(R.drawable.equalizer_icon) 
      .setContentTitle(title) 
      .setContentText(text) 
      .setTicker(getString(R.string.app_name)) 
      .setContentIntent(pendingIntent) 
      .setPriority(Notification.PRIORITY_MAX) 
      .build(); 

    notification.bigContentView = remoteViews; 

答えて

0

は、このコードを試してみてください。

public static void showNotification(Context context) { 
    int notificationId = 99; 
    Intent cancelIntent = new Intent(YOUR_ACTION).putExtra(YOUR_EXTRA_NOTIFICATION_ID, notificationId); 
    PendingIntent buttonPendingIntent = PendingIntent.getBroadcast(context, 123, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(context) 
      .setAutoCancel(false) 
      .setOngoing(true) 
      .setPriority(NotificationCompat.PRIORITY_HIGH) 
      .setSmallIcon(android.R.drawable.stat_notify_sync) 
      .setTicker("Ticker title") 
      .setOnlyAlertOnce(true) 
      .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, YourActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)); 

    Notification not = notBuilder 
      .setContentTitle("Title") 
      .setContentText("Message") 
      .setProgress(100, 33, false) 
      .addAction(android.R.drawable.ic_menu_close_clear_cancel, "Cancel", buttonPendingIntent) 
      .setStyle(new NotificationCompat.BigTextStyle().bigText("Message")) 
      .build(); 

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(notificationId, not); 
} 

それはボタン一つで大きな通知を表示 - あなたは下端を引き下げてそれを拡大することができます。

+0

カスタムレイアウトはどうですか?私はnotifの変種にする必要があります:携帯電話のために大きくて、通常のサイズを表示することはできません。カスタムレイアウトのコントロールボタン付き通知 –

+0

https://stackoverflow.com/questions/21237495/create-custom-big-notificationsまたはhttps://stackoverflow.com/questions/18367631/change-notification-layoutを試しましたか? – isabsent

+0

あなたは私を理解していません。私はカスタムレイアウトを作る方法を知っています。私のコードを見ることができます。私は大きなが許されないときに通常のサイズnotifを表示する方法を知らない。 –