broadcastreceiver - App doesn't auto-start an app when booting the device in Android -
i have managed implement following method coding allows app perform auto-launch when device booted/started-up. however, when tested out implementation code, failed work, app has failed perform auto-launch when device booted. can please or advice me possibilities? thank you.
manifest.xml
<uses-permission android:name="android.permission.receive_boot_completed"> </uses-permission> <receiver android:enabled="true" android:exported="true" android:name="com.dapoaugury.apps.robotapp.autostartup" android:permission="android.permission.receive_boot_completed" android:installlocation="internalonly"> <intent-filter> <action android:name="android.intent.action.boot_completed" /> <action android:name="android.intent.action.quickboot_poweron" /> <category android:name="android.intent.category.default" /> </intent-filter> </receiver>
autostartup.java
package com.dapoaugury.apps.robotapp; /** * auto-start application on device start-up/ boot * created dev02 on 10/7/15. */ import android.content.broadcastreceiver; import android.content.context; import android.content.intent; public class autostartup extends broadcastreceiver{ @override public void onreceive(context context, intent intent) { if (intent.getaction().equalsignorecase(intent.action_boot_completed)){ //to start new intent when phone starts intent = new intent(context, mainactivity.class); // put activity on top of stack since activity launched context outside activity i.addflags(intent.flag_activity_new_task); // edited i.addflags(intent.flag_include_stopped_packages); context.startactivity(i); } //to start application on phone start-up - 10/7/2015(end of version) } }
mainactivity.java (mechanism suppose manually launch when app first installed)
public class mainactivity extends activity { public static long appelapsedtime; public static long appelapsetime_hr; public static long process_starttime = system.nanotime(); public static long currentproctime; private static context context; public final static int green = 0; public final static int blue = 1; private static int ctheme = green; webview webview; progressbar pb; @override public void oncreate(bundle savedinstancestate) { ........... }
from android 3.1, newly installed apps put "stopped" state , way move out of stopped state manually launch activity of app @ least once.
for problem,
1) need design mechanism user needs first open activity of app manually after installing app.
2) after that, bootreceiver work correctly , able launch activity of app automatically. implementation absolutely correct.
i faced same problem in 1 of apps, trying open activity every time device boots it didn't work newly installed app. once user opens app manually @ least once, the app moves out of "stopped" state , works normally.
edit
1) please ensure <uses-permission>
direct child of <manifest>
tag.
2) please ensure specify android:installlocation="internalonly"
otherwise not receive boot complete actions if app installed in sd card.
3) explained before also.
from android 3.1, apps put in stopped state same when user force closes app.
while in state, the application not run automatically reason, until , unless launched manually user launcher.
meaning not receive action_package_installed, boot_completed
etc. until user manually launches app. google has taken decision prevent malware apps auto-launching. user needs open app @ least once, perform actions automatically after that.
hope made clear time. thanks.
Comments
Post a Comment