我正在使用方向传感器,除通知外,一切正常。通知来自我的代码中设置的传感器参数值
我的目标是控制通知,只要在检查定义的传感器参数之前加载应用程序。通知栏中有一条通知,清除后立即返回。
另一个目标是仅在满足传感器参数时才触发通知。传感器参数是正确的,我可以在日志文件和文本视图中看到它们。
最终目标是将通知限制在通知栏中,因为您可以想象移动传感器可以触发大量通知。
谢谢你的帮助,
还在学习路上。
以下是相关代码区:
私人 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
}
};