2017-06-12 51 views
0

我具有低於下面的方法:如何在通知Android中創建天文臺?

public NotificationCompat.Builder createNotification(Context context) { 
    Intent intent = new Intent(this, MapsActivity.class); 
    PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0); 

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    boolean running = true; 
    builder = new NotificationCompat.Builder(context) 
      .setContentText("conteúdo") 
      .setContentTitle("titulo") 
      .setSmallIcon(R.drawable.ic_today_black_24dp) 
      .setAutoCancel(false) 
      .setOnlyAlertOnce(true) 
      .setOngoing(running) 
      .setContentIntent(
        PendingIntent.getActivity(context, 10, 
          new Intent(context, MapsActivity.class) 
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), 
          0) 
      ) 
      .addAction(running ? R.drawable.ic_stop_black_24dp 
          : R.drawable.ic_play_arrow_black_24dp, 
        running ? "Pause" 
          : "play", 
        pIntent) 
      .addAction(R.drawable.ic_stop_black_24dp, "Stop", 
        pIntent); 

    notificationManager.notify(0, builder.build()); 

    return builder; 
} 

在其中在狀態欄發起的通知,如在第一通知顯示在下面:

enter image description here

要連結我這樣做的通知:

NotificationCompat.Builder notification = createNotification(this); 
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
mNotificationManager.notify(0, notification.build()); 

我想在通知中創建一個Chronometer,就像它出現的一樣在Strava通知(圖像的第二次通知)中,如上所示。

如何在通知中創建Chronometer

回答

1

因此,如果您知道如何使用Layouts,那麼創建App Widget佈局很簡單。但是,您必須知道,App Widget佈局基於RemoteViews,它不支持各種佈局或視圖窗口小部件。無論如何,如果你需要asistance與應用的Widget佈局這裏是一些guaidance: https://developer.android.com/guide/practices/ui_guidelines/widget_design.html

幸運的是RemoteViews支持Chronometer你可以從開發者網站看到:https://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

一想你可以進入您的Chronometer因爲通常你可以做這樣的事情取決於你是否希望它暫停,恢復,無論如何:

remoteView.setChronometer(R.id.myChronometere, SystemClock.elapsedRealtime(), 
         null, false); //pausing