我试图做一个简单的闹钟管理器,虽然我加了5秒的延迟, 手机中的闹钟立即响起。
我知道在我的接收器中警报声响起, 但是我知道你把延迟设置为你希望它在未决意图中消失的时间。
我做错了什么?
这是我的警报意图:
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent (AlarmClockScreen.this, AlarmNotificationReciever.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
manager.set(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime()+5000,pendingIntent);
这是我的接收器
public class AlarmNotificationReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(android.R.mipmap.sym_def_app_icon)
.setContentTitle("Alarm TITLE")
.setContentText("I will finish, What you started")
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
.setContentInfo("Info");
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1,builder.build());
}
}
答案 0 :(得分:0)
通过添加
修复它async Task task()
{
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);
var speed = position.Speed * 3.6;
speedKmh = speed.ToString() + "km/h";
}