/ / androidの通知バーからアプリケーションを起動します-android

アンドロイドの通知バーからアプリケーションを起動する - android

アプリケーションがあります。アプリのアイコンを表示したいです。アプリケーションの実行中に通知バーに移動し、ユーザーが通知バーにあるアプリアイコンをクリックしたときにも表示したい 私のアプリが開きます。これを行う方法?助けてください!

回答:

回答№1は14

ステータスバー通知を作成するには、onCreateメソッドでこれを行います。

  1. NotificationManagerへの参照を取得します。

      String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    
  2. 通知をインスタンス化します。

      int icon = R.drawable.notification_icon;
    CharSequence tickerText = "Hello";
    long when = System.currentTimeMillis();
    
    Notification notification = new Notification(icon, tickerText, when);
    
  3. 通知の展開されたメッセージと意図を定義します。

      Context context = getApplicationContext();
    CharSequence contentTitle = "My notification";
    CharSequence contentText = "Hello World!";
    Intent notificationIntent = new Intent(this, MyClass.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    
  4. 通知をNotificationManagerに渡します。

      private static final int HELLO_ID = 1;
    
    mNotificationManager.notify(HELLO_ID, notification);
    

    これで、ユーザーに通知されました。


回答№2のための7

受け入れられた回答は非推奨です。これがグーグルからのダイアログを表示する方法です ドキュメンテーション.

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable
.logo_listy).setContentTitle("My notification").setContentText("Hello World!");

Intent resultIntent = new Intent(this, ResultActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ResultActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);

NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());

回答№3の場合は3

いくつかの提案:

  • 通知バーにアイコンが必要な場合は、通知を送信する必要があります。
  • をクリックしてアプリケーションを開始することはできません通知アイコン。通知をクリックすると開始できます。通知は、ユーザーが通知バーをプルダウンすると利用できるようになります。そのためには、PendingIntentを作成する必要があります。

回答№4の場合は0

アプリを起動するインテントを含む保留中のインテントで通知を投稿する必要があります。 見る http://developer.android.com/guide/topics/ui/notifiers/notifications.html 一般的にそれを行う方法と http://javablogs.com/Jump.action?id=628173 あなたが陥る可能性のある罠のために。