2016-11-19 10 views
0

電話のアイコンを画像のようにステータスバーに追加したいだけです。 これ以上のものは、ステータスバーにこの小さなアイコンが表示されます。ステータスバーに電話アイコンを追加する(ステータスバーを削除する場所)

どうすればよいですか? いくつかのメソッドを呼び出すと、このアイコンを表示できますか?このアイコンをどのツールで描画すべきですか?次にこのアイコンを追加するには?

enter image description here

編集:私は最終的にこのコードを使用して通知を表示

 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); 
    } 

最後にどこをキャンセルするのですか?

+1

https://developer.android.com/guide/topics/ui/notifiers/notifications.htmlを確認してください。アイコンは通知アイコンです。 – rhari

+0

プログラムを終了するとどういう意味ですか? – mallaudin

+0

ユーザーが2番目のアクティビティで終了すると、ユーザーはホームボタンを押して左にスライドしてアプリケーションを終了します。 –

答えて

0

を作成する必要があなたのアプリケーションでそれを追加する次にここhttps://material.io/icons/#ic_phone

からアイコンをダウンロードすることができます。通知の作成時に通知が添付されています。通知の送信中に任意のタイプのアイコンを追加できます。あなたのステータスバーには、通知が添付されたphoneアイコンが表示されています。通知の詳細については、hereをご覧ください。

+0

私は自分の質問を編集しました。もう一度読むことができますか? –

関連する問題