вибрировать на реальном устройстве более одного раза для уведомления (ближайший сигнал) в Android - PullRequest
1 голос
/ 09 февраля 2012

Я установил уведомление, когда пользователь входит в определенное место. что происходит, когда пользователь вводит радиус-телефон, показывает уведомление на панели уведомлений и вибрирует снова и снова. даже я очищаю телефон уведомлений держать вибрацию, пожалуйста, помогите мне! Вот код для уведомления:

import android.app.Dialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;


    public class ProximityIntentReceiver extends BroadcastReceiver {

    private static int NOTIFICATION_ID = 0;
    public static final String EVENT_ID_INTENT_EXTRA = "EventIDIntentExtraKey";
    public static final String PLACE_NAME = "PLACE";
    public static final String ITEM_NAME = "ITEM";
    String Place_Name = "",Item_Name = "";


    @Override
    public void onReceive(Context context, Intent intent) {
         Log.v("entered","" );
        String key = LocationManager.KEY_PROXIMITY_ENTERING;
        //Bundle extras = getIntent().getExtras(); 
        NOTIFICATION_ID = intent.getIntExtra(EVENT_ID_INTENT_EXTRA, -1);
        Place_Name = intent.getStringExtra(PLACE_NAME);
        Item_Name =  intent.getStringExtra(ITEM_NAME);
        Boolean entering = intent.getBooleanExtra(key, false);
         Log.v(Place_Name,Item_Name );

        if (entering) {
            Log.d(getClass().getSimpleName(), "entering");
        }
        else {
            Log.d(getClass().getSimpleName(), "exiting");
        }


        NotificationManager notificationManager = 
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, null, 0);       

        Notification notification = createNotification();
        notification.setLatestEventInfo(context, "Hello You are near to this", Place_Name + "  and your task is  " + Item_Name, pendingIntent);

        notificationManager.notify(NOTIFICATION_ID, notification);

    }

    private Notification createNotification() {
        Notification notification = new Notification();

        notification.icon = R.drawable.newnotification;
        notification.when = System.currentTimeMillis();

        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;

        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_LIGHTS;

        notification.ledARGB = Color.WHITE;
        notification.ledOnMS = 1500;
        notification.ledOffMS = 1500;

        return notification;
    }
}

что я делаю не так?

Ответы [ 2 ]

1 голос
/ 09 февраля 2012

Попробуйте это:

notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.FLAG_ONLY_ALERT_ONCE;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_VIBRATE;
0 голосов
/ 14 февраля 2012

уведомлений. Когда система сообщает системе, в какое время отправлять уведомления.

...