2017-06-12 5 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()); 

私はクロノメーターを正確に表示するように通知します上記のように、Strava通知(画像の2番目の通知)で

通知にChronometerを作成するにはどうすればよいですか?

答えて

1

したがって、Layoutsの使い方を知っていればApp Widgetのレイアウトを作成するのは簡単です。しかし、App WidgetのレイアウトはRemoteViewsに基づいており、あらゆる種類のレイアウトや表示ウィジェットをサポートしていないことに注意してください。あなたが開発者のwebisteから見ることができるようにあなたのために幸運なことに https://developer.android.com/guide/practices/ui_guidelines/widget_design.html

RemoteViewsサポートChronometerhttps://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

Aはあなたに通常あなたのChronometerをアクセスも可能だと思うし、あなたとにかくあなたがここのApp Widgetのレイアウトでasistanceが必要な場合は、いくつかのguaidanceですこのような何かをすることができますあなたはそれを一時停止、再開、何でもしたいかによって異なります:

remoteView.setChronometer(R.id.myChronometere, SystemClock.elapsedRealtime(), 
         null, false); //pausing 
関連する問題