2
我在后台运行应用程序时使用了地理栅栏。设备重启后无法使用。即使在cn1中重新启动设备后,我如何才能使其工作?我认为cn1推送通知使用RECEIVE_BOOT_COMPLETED权限来实现它。我们是否有一些内置函数可以用于其他用途,如我的情况?设备重启后在后台自动运行应用程序
代码:
Geofence gf = new Geofence("test", loc, 100, 100000);
LocationManager.getLocationManager().addGeoFencing(GeofenceListenerImpl.class, gf);
public class GeofenceListenerImpl implements GeofenceListener {
@Override
public void onExit(String id) {
}
@Override
public void onEntered(String id) {
if(Display.getInstance().isMinimized()) {
Display.getInstance().callSerially(() -> {
Dialog.show("Welcome", "Thanks for arriving", "OK", null);
});
} else {
LocalNotification ln = new LocalNotification();
ln.setId("LnMessage");
ln.setAlertTitle("Welcome");
ln.setAlertBody("Thanks for arriving!");
Display.getInstance().scheduleLocalNotification(ln, 10, LocalNotification.REPEAT_NONE);
}
}
}
更新:如何按照清单通过原生接口CN1集成?在引导
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:enabled="true"
android:exported="true"
android:name=".YourActivityRunOnStartup">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
好的我会使用本机代码。我有关于地理围栏方法的问题。大多数情况下,当应用程序在BG或删除,调用onEntered()方法。但onExit()也被频繁调用。 onExit方法的用途是什么? – beck
当您离开防护区时,它与onEnter相反 –
我已经在本机android中解决了在启动时自动重新注册应用程序的问题,该应用程序在清单中具有接收器。我不太清楚在cn1中如何做到这一点? (PS。在代码中动态注册接收器无法正常工作)查看上面问题中的更新。 – beck