Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
7
Erster Beitrag:
vor 3 Jahren, 5 Monaten
Letzter Beitrag:
vor 3 Jahren, 5 Monaten
Beteiligte Autoren:
RAUL2, Pim Janssen, Danny Lauwers

[WM 17] Start WM app at Android device boot??

Startbeitrag von RAUL2 am 02.06.2014 13:13

Hi everybody.

I've found nothing in the forum about this. How do you start your Android WM app in an Android device?

Best regards.

Antworten:

I have no WM so i don''t know if there is a option. I know however how to do it native. I could digg up the code.

But the easiest solution would be to install a external app and configure it to start your app at boot. There are several apps in the market that can do this.

von Pim Janssen - am 02.06.2014 14:38
Thanks Pim for your reply. Do you have some Java code to do this? If true, can you post it here? Nevertheless, I'll search de play store for those apps you have mentioned.

Regards.

von RAUL2 - am 02.06.2014 15:04

package packagepath;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class AutoStartReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))
{
/* Only perform this code if the BroadcastReceiver received the ACTION_BOOT_COMPLETED action.*/
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
boolean autostart = prefs.getBoolean("autostart", false);
if (autostart) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}

}

Menifest.xml

&gk;receiver android:enabled="true" android:name=".AutoStartReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">







von Pim Janssen - am 02.06.2014 15:15
This is a quick example i extracted from my code. I have it somewhere documented but i could not find it quickly.

Class

package packagepath;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class AutoStartReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))
{
/* Only perform this code if the BroadcastReceiver received the ACTION_BOOT_COMPLETED action.*/
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
boolean autostart = prefs.getBoolean("autostart", false);
if (autostart) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}

}

Menifest.xml

<receiver android:enabled="true" android:name=".AutoStartReceiver"
android: permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>


von Pim Janssen - am 02.06.2014 15:27
Hi,

I don't know if this option is in WM17, but in WM18/19 you can set a flag during Android application generation:

Application Flags in the second screen of the wizard, it is called: Application Options, Automatically start the application when the device is started.
[attachment 926 img.png]

Danny

von Danny Lauwers - am 02.06.2014 15:51
Thank you Pim for your code. I'll try that!

Danny, I didn't see that option in WM17 but I'll check it out again. Thanks.

von RAUL2 - am 02.06.2014 16:33
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.