String 传感器上的Android已更改,已创建通知,但无法控制通知
我正在使用方向传感器,除了通知,其他一切都正常。通知来自“我的代码”中设置的传感器参数值 我的目标是在检查定义的传感器参数之前加载应用程序后,立即控制通知。通知栏中有一个通知,清除后会立即返回 另一个目标是仅当传感器参数满足时才发出通知。传感器参数正确,我可以在日志文件和文本视图中看到它们 最后一个目标是将通知限制在通知栏中,因为您可以想象移动传感器会触发大量通知 谢谢你的帮助 仍然在学习的道路上 以下是相关代码区域: 私有SensorEventListener mySensorEventListener=新建SensorEventListener{String 传感器上的Android已更改,已创建通知,但无法控制通知,string,notifications,orientation,android-sensors,sensormanager,String,Notifications,Orientation,Android Sensors,Sensormanager,我正在使用方向传感器,除了通知,其他一切都正常。通知来自“我的代码”中设置的传感器参数值 我的目标是在检查定义的传感器参数之前加载应用程序后,立即控制通知。通知栏中有一个通知,清除后会立即返回 另一个目标是仅当传感器参数满足时才发出通知。传感器参数正确,我可以在日志文件和文本视图中看到它们 最后一个目标是将通知限制在通知栏中,因为您可以想象移动传感器会触发大量通知 谢谢你的帮助 仍然在学习的道路上 以下是相关代码区域: 私有SensorEventListener mySensorEventLis
@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
}
};
如果event.values[0]<-100 | | | event.values[1]<-95 | | event.values[2]<-100{}添加上述语句后,我自己用以下语句解决了这个问题。感谢所有感兴趣的人。