Android: Auto Start issue cause not getting push notification - android

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
}
}

Related

android P actions - app not receiving intent action in broadcastReceiver

What i am doing is making an app that when user uses google assistant to say "turn on my app" then it asked "do you want to turn on my app" and then user replies "yes" or "yes please" and i want it to open my app. I am expecting that a broadcastReciever will be called with the intent that the google assistant sent and i will know how to react. Lets see what i have done so far and i am testing this all on Android P emulator:
here is what the server side has on google:
then in the android manifest i have declared a broadcastreciever so that it can listen for the custom intent action i created above called action_intent_OPEN_CALL_MUSIC:
<receiver android:name=".receivers.MyGoogleAssistantReceiver">
<intent-filter>
<action android:name="action_intent_OPEN_CALL_MUSIC" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
when i then use the google assistant in the emulator no broadcast is received in the app, what am i doing wrong ?
public class MyGoogleAssistantReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.v("myTag","got an intent:" + intent.getAction()); //nothing hits here,why ?
}
}
do i have to add something in xml/actions.xml even though its all local ?

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.

Is it possible to have Android app without any Activities, but only with Services?

How can you make an app that does not contain Activity as main launcher, but contain service as main launcher?
Yes it is possible. Just don't define any activity in your AndroidManifest and you're fine.
What you should do however to be able for your services to be called, is to listen on some phone-actions with a broadcast receiver.
Something like this:
<receiver android:name="com.example.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>
The actions BOOT_COMPLETED and MY_PACKAGE_REPLACED are triggered when the user's device is rebooted (obviously) but also whenever an upgrade of your application (or initial install) is done (via the Play Store for example).
Then you can start your service again (or schedule an alarm for you service to be triggered x minutes/hours/days/...).
If you don't have any possible user input, another useful action is ACTION_USER_PRESENT. This one will be triggered whenever your user unlocks his phone.
CAUTION:
For the BOOT_COMPLETED action you need to add a permission in the manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Then in your 'MyBroadcastReciever' class you should not do anything special to check the actions. You know you will only get in there by the actions specified in the manifest, so your broadcast receiver will look something like this:
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Do your work here...
}
}
All services that will be ever triggered should be defined in the manifest also! Don't forget about that!

Bootup Receiver in Android wear

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>

How to start an application directly (without asking) at startup on Android 4.0

I want to start my application at startup in Android 4.0. To do that, I wrote some codes and these are completely the same with the #Ahmad's codes (in the answer). However, although I select my application as always, when tablet opens, it asks 'What do you prefer?' (Android's default launcher or my application). I don't want it to ask that question and it must start my application automatically.
Use the BOOT_COMPLETED Intent.
Broadcast Action: This is broadcast once, after the system has
finished booting. It can be used to perform application-specific
initialization, such as installing alarms. You must hold the
RECEIVE_BOOT_COMPLETED permission in order to receive this broadcast.
In your Manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Set up a Broadcastreceiver:
<receiver android:name="com.example.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
This is how your BroadcastReceiver could look like:
public class MyBroadcastreceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MyActivity.class);
startActivity(i);
}
}

Categories

Resources