2017-11-03 11 views
-1

Androidのカスタム通知を処理しています。 NotificationCompat.Builderには、通知が来たときにユーザーに表示するための 'setShowWhen(boolean)'というメソッドがあります。RemoteViewsの通知時間を表示するには?

しかし私は、カスタム通知ビューであるRemoteViewsで同じことをする方法を見つけることができません。 時間の表示方法を教えてもらえますか? ありがとうございます。

答えて

0

以下のコードを参照してください。

RemoteViews remoteViews = new RemoteViews(getPackageName(), 
      R.layout.customnotification); 

    // Set Notification Title 
    String strtitle = getString(R.string.customnotificationtitle); 
    // Set Notification Text 
    String strtext = getString(R.string.customnotificationtext); 

    // Open NotificationView Class on Notification Click 
    Intent intent = new Intent(this, NotificationView.class); 
    // Send data to NotificationView Class 
    intent.putExtra("title", strtitle); 
    intent.putExtra("text", strtext); 
    // Open NotificationView.java Activity 
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 
      PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
      // Set Icon 
      .setSmallIcon(R.drawable.logosmall) 
      // Set Ticker Message 
      .setTicker(getString(R.string.customnotificationticker)) 
      // Dismiss Notification 
      .setAutoCancel(true) 
      // Set PendingIntent into Notification 
      .setContentIntent(pIntent) 
      // Set RemoteViews into Notification 
      .setContent(remoteViews); 

    // Locate and set the Image into customnotificationtext.xml ImageViews 
    remoteViews.setImageViewResource(R.id.imagenotileft,R.drawable.ic_launcher); 
    remoteViews.setImageViewResource(R.id.imagenotiright,R.drawable.androidhappy); 

    // Locate and set the Text into customnotificationtext.xml TextViews 
    remoteViews.setTextViewText(R.id.title,getString(R.string.customnotificationtitle)); 
    remoteViews.setTextViewText(R.id.text,getString(R.string.customnotificationtext)); 

    // Create Notification Manager 
    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    // Build Notification with Notification Manager 
    notificationmanager.notify(0, builder.build()); 
+0

いいコードですが、「時間」を処理する部分はありません。 – eyeballs

+0

あなたはレイアウトに時間としてテキストビューを入れてから、date()から時間をとり、それを設定する必要があります。私のコードのカスタムレイアウトの – Vasant

+0

はcustomnotificationです。 – Vasant

関連する問題