Запускать действие при нажатии значка уведомления в строке состояния? - PullRequest
0 голосов
/ 27 февраля 2012

Я использую диспетчер тревог для установки будильника. Когда он выключается, получатель запускает эту услугу. Из этой службы уведомление делается с использованием следующего кода. Я хочу запустить действие при нажатии на уведомление, но когда я щелкаю значок уведомления, ничего не происходит.

Это просто показывает, что этот круг движется, как будто что-то загружается, и все.

package com.rythmal.alarmtest;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;

public class AlarmProcess extends Service {

    private static final int MY_NOTIFICATION_ID = 1;
    private NotificationManager mNotificationManager;
    private Notification myNotification;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // TODO Auto-generated method stub
        String ns = Context.NOTIFICATION_SERVICE;
        mNotificationManager = (NotificationManager) getSystemService(ns);

        int icon = R.drawable.ht_icon;
        CharSequence tickerText = "Rythmal";
        long when = System.currentTimeMillis();

        myNotification = new Notification(icon, tickerText, when);

        Context context = getApplicationContext();
        CharSequence notificationTitle = "My notification";
        CharSequence notificationText = "Hello World!";
        Intent notificationIntent = new Intent(this,com.rythmal.alarmtest.ResultRun.class);


        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, notificationIntent, 0);

        myNotification.defaults |= Notification.DEFAULT_SOUND;
        myNotification.flags |= Notification.FLAG_AUTO_CANCEL;

        myNotification.setLatestEventInfo(context, notificationTitle,notificationText, pendingIntent);
        mNotificationManager.notify(MY_NOTIFICATION_ID, myNotification);

        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
    }

}

Ответы [ 2 ]

1 голос
/ 12 марта 2012

Эй, это сработало внезапно после того, как я очистил проект ..

0 голосов
/ 27 февраля 2012

Я просмотрел ваш код уведомления. Все выглядит правильно.

Что вы подразумеваете под "но когда я нажимаю на значок уведомления, ничего не происходит. Это просто показывает, что этот круг движется, как будто что-то загружается, и это так". Я спрашиваю, потому что «это просто показывает этот круг» определенно подразумевает, что он что-то делает.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...