How to receive BOOT_COMPLETED on Android TV - android

I'm developing an app for Android TV. I have a sticky service & a broadcast receiver that should restart this service after system reboot.
The code works perfect for any phone, but, in the case of the TV, any of the actions that I defined in the receiver's intent isn't received, when turning on the TV from standby(using the remote). It works when I unplug the TV and plug it again.
Has anyone tried something similiar? Any advice might help. Thanks
I've tried BOOT_COMPLETED, QUICKBOOT_POWERON, REBOOT, ACTION_POWER_CONNECTED.
Here is the receiver I've configured.
<receiver
android:name=".MyReceiver"
android:directBootAware="true"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"
/>
<action
android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
<action
android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action
android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Expected to catch the action of turning on the device in the broadcast.

Please check if you have added following permission.
uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"

Related

BOOT_COMPLETED not triggered on a Gionee device with Lollipop ver

UPDATE : I am receiving BOOT_COMPLETED on Gionee but only if I follow these steps -
1. Open "Auto start" and then close it
2. Open the app and close it
If I do above steps and then turn off and on the phone, BOOT_COMPLETED gets triggered. Next time if I just turn it off and on, it is not triggered. Am able to simulate this consistently. What might be the reason ?
I have this declared in the manifest. It is working on phones like Samsung, Motorola etc but on Gionee I found that the receiver is not getting triggered on phone bootup. The phone has Lollipop ver. Please let me know what might be missing here. Appreciate your help.
<receiver
android:name=".BootUpReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="999">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
This worked on my Gionee Phone:
<receiver
android:name=".BootUpReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="999">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
<action android:name="com.gionee.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

Launching application when receiving on DATA_SMS_RECEIVED

I have declared a broadcast receiver in manifest for receiving DATA_SMS_RECEIVED, the broadcast receiver triggered when the application is running, but when the application is closed nothing happens and no broadcasts are received.
<receiver android:name="edu.sharif.iis.khasis.SmsReceiver" android:exported="true" android:enabled="true">
<intent-filter android:priority="999">
<action android:name="android.intent.action.DATA_SMS_RECEIVED"/>
<data android:scheme="sms" android:host="*" android:port="8901" />
</intent-filter>
</receiver>
I have tested this scheme with BOOT_COMPLETED and it works well, but doesn't works with DATA_SMS_RECEIVED. could someone tell me what is the problem?
Add this
<action android:name="android.permission.RECEIVE_SMS" />
It is OS generated action.

android.intent.action.MY_PACKAGE_REPLACED Not getting triggered

I have this receiver declared in my Manifest file. I am receiving the broadcast in one phone that is Samsung Note 2 Jelly bean but not receiving the broadcast on another phone, Redmi 4.4.4. Please let me know what might be the issue.
<receiver
android:name=".UpgradeReceiver"
android:enabled="true"
android:exported="false">
<intent-filter android:priority="999" >
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
</receiver>

BOOT_COMPLETED Receiver works on hard power down/power up, but not simple restart

After a weird issue, I finally got my BootReceiver receiving the BOOT_COMPLETED signal from Android, kind of. It only works for hard power off/power on boots, it doesn't detect restarts from devices like HTC. I have implemented QUICKBOOT intent-filters in my Receivers, but still no luck.
My manifest contains:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
....
<receiver android:name="com.smashingboxes.speed.BootReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.ACTION_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<receiver android:name="com.smashingboxes.speed.ShutdownReceiver" >
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
</intent-filter>
</receiver>
I do not detect Shutdown or Boot if I do a HTC restart. Any ideas why it only seems to be working on hard shutdown/boots?
AFAIK, those aren't the right "quickboot" actions. There are no actions with the names you have specified in the Android source code.
Try com.htc.intent.action.QUICKBOOT_POWERON and com.htc.intent.action.QUICKBOOT_POWEROFF.

Android: Start Service on boot?

I'm reaaaaally new to Java, but an experienced C#-coder.
I've created a service which I can start/stop from an activity.
My question is, how do I "install" this service so it does start upon boot of my device?
I found this:
Trying to start a service on boot on Android
I've tried to implemented this like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="james.jamesspackage" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:debuggable="true">
<activity android:name=".jamessActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name=".MyService">
<intent-filter>
<action android:name="james.jamesspackage.MyService" />
</intent-filter>
</service>
<receiver android:name="james.jamesspackage.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
</application>
</manifest>
What's wrong? Can I have an activity and a service/receiver in one manifest?
Thanks
James
How to start service on device boot(autorun app, etc.)
For first: since version Android 3.1+ you don't recieve BOOT_COMPLETE if user never started yor app at least once or user "force closed" application.
This was done to prevent malware automaticaly register service. This security hole was closed in newer versions of Android.
Solution:
Create app with activity. When user run it once app can recieve BOOT_COMPLETE broadcast message.
For second: BOOT_COMPLETE is sent before external storage is mounted. if app is installed to external storage it won't receive BOOT_COMPLETE broadcast message.
In this case there is two solution:
Install your app to internal storage
Instal another small app in internal storage. This app recieves BOOT_COMPLETE and run second app on external storage.
If your app already installed in internal storage then code below can help you understand how to start service on device boot.
In Manifest.xml
Permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Register your BOOT_COMPLETED reciever:
<receiver android:name="org.yourapp.OnBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Register your service:
<service android:name="org.yourapp.YourCoolService" />
In reciever OnBoot.java:
public class OnBoot extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
// Create Intent
Intent serviceIntent = new Intent(context, YourCoolService.class);
// Start service
context.startService(serviceIntent);
}
}
For HTC you maybe need also add in Manifest this code if device don't catch RECEIVE_BOOT_COMPLETED:
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
Reciever now look like this:
<receiver android:name="org.yourapp.OnBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
How to test BOOT_COMPLETED without restart emulator or real device?
It's easy. Try this:
adb -s device-or-emulator-id shell am broadcast -a android.intent.action.BOOT_COMPLETED
How to get device id? Get list of connected devices with id's:
adb devices
adb in ADT by default you can find in:
adt-installation-dir/sdk/platform-tools
Enjoy! )
Looks like the name in the receiver section is wrong. This is what my application entry in the AndroidManifest.xml looks like:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name=".BootListener"
android:enabled="true"
android:exported="false"
android:label="BootListener">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".UpdateService">
</service>
<activity android:name=".Info"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TravelMapperPreferences"
android:label="Settings">
</activity>
</application>
Note that the names are relative to the package in the manifest declaration. Your receiver name should be ".MyBroadcastReceiver" since the package of the manifest contains james.jamesspackage

Categories

Resources