Android on Sensor Changed , Notification Created , but can't control notification

262 Views Asked by At

I am working with orientation sensors,everything works except for notification. Notification is coming from sensor parameter values set in my code

My goal is controlling the notifications,as soon as the application loads before the defined sensor parameters are checked. There is a notification in the notification bar and when cleared comes right back.

The other goal is getting the notification to fire only when the sensor parameters are meet. The sensor parameters are correct I can see them in a log file and in a text view.

The final goal is to limit the notifications to the notification bar, as you can imagine moving the senor about can fire a lot of notifications.

Thanks for any help,

Still on the learning path.

Below is the relevant code area:

private SensorEventListener mySensorEventListener = new SensorEventListener() {

    @Override
    public void onSensorChanged(SensorEvent event) {
        // TODO Auto-generated method stub


        String.valueOf(event.values[0]) ;
        String.valueOf(event.values[1]);
        String.valueOf(event.values[2]);

        if (event.values[1]<-100)mVibrator.vibrate(new long[] { 0, 200, 0 }, 0);
        else if

         (event.values[1]>-75)mVibrator.vibrate(new long[] { 0, 200, 0 }, 0); 

         else mVibrator.cancel();

        //We get a reference to the NotificationManager
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        String MyText = "Reminder";
        Notification mNotification = new Notification(R.drawable.ic_launcherone, MyText, System.currentTimeMillis() );
        //The three parameters are: 1. an icon, 2. a title, 3. time when the notification appears

        String MyNotificationTitle = "blah blah";
        String MyNotificationText  = "blah blah";

        Intent MyIntent = new Intent(Intent.ACTION_VIEW);
        PendingIntent StartIntent = PendingIntent.getActivity(getApplicationContext(),0,MyIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        //A PendingIntent will be fired when the notification is clicked. The FLAG_CANCEL_CURRENT flag cancels the pendingintent

        mNotification.setLatestEventInfo(getApplicationContext(), MyNotificationTitle, MyNotificationText, StartIntent);

        int NOTIFICATION_ID = 1;
        notificationManager.notify(NOTIFICATION_ID , mNotification);  
        //We are passing the notification to the NotificationManager with a unique id.
      }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        // TODO Auto-generated method stub

    }
  };
0

There are 0 best solutions below