電話のアイコンを画像のようにステータスバーに追加したいだけです。 これ以上のものは、ステータスバーにこの小さなアイコンが表示されます。ステータスバーに電話アイコンを追加する(ステータスバーを削除する場所)
どうすればよいですか? いくつかのメソッドを呼び出すと、このアイコンを表示できますか?このアイコンをどのツールで描画すべきですか?次にこのアイコンを追加するには?
編集:私は最終的にこのコードを使用して通知を表示 :
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_phone_white_36dp)
.setContentTitle("My notification")
.setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, SecondActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(SecondActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(2, mBuilder.build());
しかし、私は自分のアプリケーションに2つのアクティビティを使用しています。削除は今問題です。ユーザーがプログラムを終了したときにこの通知を削除して通知をキャンセルする場所を希望しますか?
mNotificationManager.cancel(2);
私はonDestroyで試しました:それは動作していない、ユーザーがプログラムを終了するときに削除されていません。
@Override
protected void onDestroy() {
super.onDestroy(); // Always call the superclass method first
mNotificationManager.cancel(2);
}
私はonStopで試しました:それは動作していますが、ユーザーが別のアプリケーションを渡すと、この通知は削除されます。私はこれが好きではない。
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
mNotificationManager.cancel(2);
}
最後にどこをキャンセルするのですか?
https://developer.android.com/guide/topics/ui/notifiers/notifications.htmlを確認してください。アイコンは通知アイコンです。 – rhari
プログラムを終了するとどういう意味ですか? – mallaudin
ユーザーが2番目のアクティビティで終了すると、ユーザーはホームボタンを押して左にスライドしてアプリケーションを終了します。 –