Is it possible to show a notification in android wear after the system has been restarted. I can see Weather notification comes up automatically after the android wear is restarted.
I would like to get my app's notification to come up the same way? Is there a bootup receiver?
Is this possible? if so how?
Thanks!
The mechanism is the same as on standard Android devices. Please follow these steps:
Create your MyBootCompletedReceiver in Java code:
public class MyBootCompletedReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
// do your things - show notification for example
}
}
}
Add permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Register a receiver in your manifest:
<receiver android:name=".MyBootCompletedReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Related
Ideally, we want our app to be the first one to get launched after every reboot, it is a system app so can we set it as default through code?
best you can do is BOOT_COMPLETED handling
manifest
<receiver
android:name="custom.package.BootReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Java side
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
// your code
}
}
}
but I'm afraid that with this approach you can never be sure if it will be called at first. And I know one "kind" of apps that will be called/opened earlier that any app will receive above broadast - devices Launcher
I have an app that have push notification feature. I notice that some of the device especially chinese phone like xiamoi,oppo,one plus etc having option for auto start and this control the push notification. Am not getting Push Notification when the app is not in background or in recent list.By default my app auto start is OFF
But am confused why the app like Flipkart,Amazon, Whatsapp, Hike the auto start is ON by default.
Is there is any option to set the auto start as ON by default
I think, better way is using default Android API features to run service after boot, not use custom features like used in chinese phones.
To make autrun by default Android way, you should add to mainfest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:name=".BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
And write Boot receiver:
public class BootReceiver extends BroadcastReceiver {
public BootReceiver() {
// TODO Auto-generated constructor stub
}
#Override
public void onReceive(Context context, Intent intent) {
//Run your service here
}
}
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);
}
}
}
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.
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/