autostart my app on phone power on ?

Beja

Expert
Licensed User
Longtime User
Hi friends!
is it possible to make b4a app autostarts everytime the phone is switched on?
and how? also I need to know if the app could run all the time in the background
even other apps are opened and running.
the app I am talking about will intercept any SMS message with a specific header
and append it to a text file.
Tanks in advance
 

Penko

Active Member
Licensed User
Longtime User
Upvote 0

Comalco

Member
Licensed User
Longtime User
Thanks NJDude, that's just what I was looking for.

I get an error from the manifest when I compile.....I suspect it's because I am only running SdkVersion 17?

Parsing code. 0.01
Compiling code. Error
Error parsing manifest script:
Line = 11, Word = (

'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: Manifest Editor

AddManifestText(<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="18"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)

SetManifestAttribute("android:installLocation", "auto")

SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

'End of default text.
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
Please download the file again. There was an illegal character in the manifest.

Hi NJDude,

Thanks for the sample project... The only "side effect" of this solution (Start Activity from Service) is that user will experience the screen pop up of my app right after he restarts the phone. It is not very nice. Somehow can we start the activity minimized?

Thanks again for your help.

Best
bsnqt
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
I don't understand what you mean by "pop up" the example I posted displays a MsgBox, you can start any activity on your app, and there's no such thing in Android as "minimized".

Hi NJ

Sorry for having been not clear enough.

What I meant is (not speaking about your message box example, I am speaking generally) the StartActivity(Main) will call the Activity and it will show up on the user screen right after phone starts up. What I want to achieve is Activity can still start but user will not see the Activity (hidden or going to background). I know that to do this we have several solutions (back key, go to home screen, CallSubDelayed....), but don't know how to do it in the best way. It is something similar to "Start minimized" in WP but I know that we dont have it in Android.

Thanks

bsnqt
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
In activity, in sample you write this code:

sub Service_Create
Dim i As Intent
i.Initialize("", "")
i.SetComponent("njdude.startatboot.sample/.main") '<-- Replace this with the name of your package
StartActivity(i)
StopService("")
End Sub



but, why not use this other code?



sub Service_Create
'only this code
StartActivity(main)
StopService("")
End Sub
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
If you don't start your activity (into service), the Service are running ( i think) , but, What do yo do in service?: get phone in, called by phone, input sms.... etc..
 
Upvote 0

almontgreen

Active Member
Licensed User
Longtime User
Thanks for posting here NJ Dude, a lot of us appreciate it - even enough to donate something! ha ha, go figure? I hope to understand more about the android start up for different devices and why some settings survive shutdown/startup and others don't. It sure would be nice to have greater control and the ability to monitor things like charge state and being able to set Tethering or network stuff. If tried a few things based upon reading here and have a lot to learn to even be able to ask a reasonable question.

As to the startatboot.zip it works like a charm! Saved me several more hours of experiments.
 
Upvote 0

Sgardy

Member
Licensed User
Longtime User
It doesn't works in my device under Android 6 ...
 
Upvote 0

Sgardy

Member
Licensed User
Longtime User
Just add a service and set the #StartAtBoot attribute to True.
1. Don't use the Starter service for it. It should be a different service.
2. Run your app in Release mode.
3. Don't kill your app with a swipe as it will not be started again.
Hi Erel, my app starts at boot since it's was born nearly 2 years ago, but now I'm testing it with Android 6 and it's doesn't do it anymore, I followed all your advices but at the moment there is nothing to do. No rest for the warriors :(. Ciao
 
Upvote 0

Sgardy

Member
Licensed User
Longtime User
How do you see that it is not started? Maybe it was started and then killed.
Actually the app show a toastmessage, vibrate and write a log when it starts... I don't see anything about them... really I'm not shure if this depends by the phone or OS... the phone is a Wiko Lenny3 that I bought just for testing in Android 6.

I tried also this in the manifest, where Launcher is the service that start at boot normally in android 4:

B4X:
AddPermission("android.permission.RECEIVE_BOOT_COMPLETED")
AddReceiverText(Launcher,
<intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>)

Any suggestion? There must be a way I think...
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I tried also this in the manifest, where Launcher is the service that start at boot normally in android 4:
You don't need to add it. It is added automatically.

The attached project restarts after boot. Tested with Android 7.

As I previously wrote, make sure to test it in Release mode and do not kill the app.
 

Attachments

  • 1.zip
    7.1 KB · Views: 401
Upvote 0
Top