Android tablet - modify OS so app launches on boot - android

I have written an Android application for a large store for the purposes of production inspection. I have a few Android tablets with the app installed on each that will be provided to the store.
As the only purpose of this tablet is to run a single app, is there a way to force this app to load upon switching on the tablet, and only allow this app to be used? The app does require an active 4G connection so it still needs to use a few of the core functions of Android as well as actually running the app.
I don't know much about this so apologies for naivety in advance, but could someone please shed some light on this for me?

First, you need the permission in your AndroidManifest.xml:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Also, in yourAndroidManifest.xml, define your service and listen for the BOOT_COMPLETED action:
<service android:name=".MyService" android:label="My Service">
<intent-filter>
<action android:name="com.myapp.MyService" />
</intent-filter>
</service>
<receiver
android:name=".receiver.StartMyServiceAtBootReceiver"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Then you need to define the receiver that will get the BOOT_COMPLETED action and start your service.
public class StartMyActivityeAtBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, MyActivity.class);
context.startService(serviceIntent);
}
}
}

Related

run an application when reboot in Android

I want to run an application automatically when the phone reboot. I have added these lines to my code:
public class BootComplete extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
Intent serviceIntent = new Intent(context, MyActivity.class);
context.startService(serviceIntent);
}
}
And I have added these lines to my Manifest :
<receiver
android:name=".BootComplete"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
and it's permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" >
</uses-permission>
It works properly when MyActivity class contains just some background tasks. For example when I want to turn on a LED. But when I want to play a media (ex. a video) it doesn't work. Just says service has started and doesn't play anything.
How can I fix it? Is there anything that I must add to the code?
The problem is not with your code! It's about android device.
When the device boot up, you receive the broadcast. But pay attention, when you receive that broadcast, the SD CARD is still populating and you can't access it. If that media is on SD card you cant play it.
Also, you should pay attention to something else: if the user install your app in his/her SD card, that broadcast receiver would never trigger.
So, if you want to prevent problem in some devices, in your manifest, choose internal for your install location too.
Do this change in BroadcastReceiver:
public class BootComplete extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
Intent serviceIntent = new Intent(context, MyActivity.class);
// Change is here...
serviceInten.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(serviceIntent);
}
}
In the manifest:
<receiver
android:name=".BootComplete"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter android:priority="500">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
And leave permission as it is.

Google Glass - Autostart Application on Boot

I just received a new google-glass from a company which wants it to support their employees while picking and packing goods in their warehouse. For this reason they need a Server Client application which really isn't the problem.
I never did something with the Glass before and i want to know if it is possible to run a custom Application on boot and to jail the user into it.
Yesterday i rooted the device which gives me full access but i don't know how to go on.
Thank you!
Yes, it is possible.
As you have rooted the device, so you can create system app that can be recognised by the reboot event. Rest of the steps are totally similar to android mobile.
How to do it:
If you need to know the steps you can search on the web or you can try the following:
First, you need the permission in your AndroidManifest.xml:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Also, in yourAndroidManifest.xml, define your service and listen for the BOOT_COMPLETED action:
<service android:name=".MyService" android:label="My Service">
<intent-filter>
<action android:name="com.myapp.MyService" />
</intent-filter>
</service>
<receiver
android:name=".receiver.StartMyServiceAtBootReceiver"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Then you need to define the receiver that will get the BOOT_COMPLETED action and start your service.
public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, MySystemService.class);
context.startService(serviceIntent);
}
}
}
And now your service should be running when the phone starts up.

Android - Start a program immediately on startup of device

Hello everyone and thanks for your trouble,
I have a program detailed here. This uses a microphone icon in order to start listening for voice. However, I want this program to run immediately on start up of the device. How is this possible? Also, I want the program to run without any visuals and simply return the text translation to my running program, which will take care of what command to execute. Any help on any of these topics? It will be greatly appreciated.
Yes you can do it. For this you'll need set permission to AndroidManifest.xml.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
In your AndroidManifest.xml, define your service and listener for the BOOT_COMPLETED action:
<service android:name=".MyService" android:label="My Service">
<intent-filter>
<action android:name="com.myapp.MyService" />
</intent-filter>
</service>
<receiver
android:name=".receiver.StartMyServiceAtBootReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Then you have to define the receiver that will get the BOOT_COMPLETED action and start your service.
public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, MySystemService.class);
context.startService(serviceIntent);
}
}
}
Hope this helps .. :)

Starting background service when Android turns on

I need to have ALWAYS a background service that will synchronize my Android application and a server. I know how to launch it through my application, but when the Android turns off, then the background service will die.
How can I do to keep the background service always running? (Even when the device turns off and then turns on...)
I need to add to the starts programs of Android my background service. Any hints?
use <action android:name="android.intent.action.BOOT_COMPLETED" /> for starting your service when the device turns on.
In AndroidManifest.xml:
<receiver android:name=".BootBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Add permission in your AndroidManifest.xml as:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
</uses-permission>
In code part BootBroadcastReceiver:
public class BootBroadcastReceiver extends BroadcastReceiver {
static final String ACTION = "android.intent.action.BOOT_COMPLETED";
#Override
public void onReceive(Context context, Intent intent) {
// BOOT_COMPLETED” start Service
if (intent.getAction().equals(ACTION)) {
//Service
Intent serviceIntent = new Intent(context, StartOnBootService.class);
context.startService(serviceIntent);
}
}
}
EDIT: if you are talking about device screen on/off then you need to register <action android:name="android.intent.action.USER_PRESENT" /> and <action android:name="android.intent.action.SCREEN_ON" /> for starting your service when user is present or screen is on.
(Even when the device turns off and then turns on..
The OS broadcasts ACTION_BOOT_COMPLETED when it has finished booting. Your app can ask to receive this notification by requesting permission in your manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
</uses-permission>
http://blog.gregfiumara.com/archives/82
http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/

Cannot receive broadcast in ICS

I writing 1 app for Android 4.0, and it's started via broadcastreceiver. My code is below:
In AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name="com.Android.Exercise.StartUpReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<!--<action android:name="StartInstrument" />
<action android:name="PrintControlName" /> -->
</intent-filter>
</receiver>
<service android:enabled="true" android:name="StartAUT_Service">
<intent-filter>
<action android:name="com.Android.Exercise.StartAUT_Service" />
</intent-filter>
</service>
</application>
In StartUpReceiver class:
public class StartUpReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Log.i("Broadcast", "onReceive");
Intent i = null;
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
i = new Intent(context, StartAUT_Service.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
context.startService(i);
}
}
After I rebooted my device, I can not receive broardcast.
Please help me, thank so much
Starting from Android 3.0, application state was introduced.
All applications are now installed with a state set to inactive, making all it's BroadcastReceivers inactive.
To make the state as active, the user must launch the application at least once and the OS will automatically activate the app and all its BroadcastReceivers.
In your case, you need to add an activity, be it a license agreement or a help page. This will create an icon for your app for the user to click and activate the app.
Note that the application's state will be set to back inactive if the user force-closes the application.
I faced a similar problem: Android ICS not receiving data sms
I hope that solves your problem or at least put you on the right track.
regards,
Ahmad
Try
<uses-permission android:name="android.intent.action.BOOT_COMPLETED" />
below Internet's uses permission
You need to do the following to overcome this security feature.
If your API level is below 12, then set the following to your intent before broadcasting it:
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 32);
Otherwise, add the following flag to include packages which are marked as Stopped too:
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent. FLAG_INCLUDE_STOPPED_PACKAGES);

Categories

Resources