【发布时间】:2019-11-22 13:53:08
【问题描述】:
创建 Android 服务以在后台更新位置并将其与 Unity 集成。服务在启动时工作正常,但几个小时后服务停止并且它不会更新用户位置。
下面是OnStartCommand, OnCreate, Override方法的代码sn-p。
public int onStartCommand(Intent intent, int flags, int startId)
{
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
public void onCreate()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
"channel_01",
"My Channel",
NotificationManager.IMPORTANCE_DEFAULT
);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
Notification.Builder builder = new Notification.Builder(getApplicationContext(), "channel_01");
startForeground(12345678, builder.build());
}
initializeLocationManager();
stopForeground(true);
}
任何帮助将不胜感激。谢谢
【问题讨论】:
标签: android unity3d service location