重新启动设备后,在后台自动运行应用程序

时间:2017-08-26 15:53:32

标签: codenameone

我正在使用地理围栏在后台运行应用程序。重启设备后它无法正常工作。即使在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>

1 个答案:

答案 0 :(得分:0)

有人讨论过为这些功能提供一个选项,以便在启动时自动重新注册,但这需要额外的权限,这可能是所有人都不需要的。

据我所知,没有任何一个RFE,因为最后一个要求使用Android库中的本机代码的人调用了这个,但我不认为他分享了他的代码。

相关问题