Hi We are working on an android application where we are using reboot receiver in which I am starting few services where I am performaning some network operation.
I figured it out that in some android devices like xiaomi etc reboot receiver is not working.
Earlier I got to know that In HTC devices also it does not work so I added one more intent filter to it <action android:name="android.intent.action.QUICKBOOT_POWERON" /> then it started working fine. Now other phones like xiaomi it's still not working.
What I have to set additionally so it works fine in all the devices without asking user to update any settings manually.
<receiver
android:name="com.xyz.broadcastreceiver.ServiceStarter"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
Thanks in advance.
Xiaomi phones running MIUI have a inbuilt startup apps blocker. Maybe that is interfering with your boot receiver.
Ok, let's try again. MIUI has a a built-in Security app. In the Security app there is a 'Startup' section, where the user can configure which app can and which app can't run on startup. Your application is disabled default. Also if you examine your Logcat you can see a "permission denied" message at startup.
Put your app manually to the whitelisted apps, unfortunately that is your users can only do.
There is an internal feature of MIUI which prevents apps from restarting for saving battery & RAM. You have to manually toggle Auto Start option on in order to receive broadcast for BOOT_COMPLETED. Go to Settings> Installed Apps> Your App. Then just toggle on the auto start option. There is no option to prevent this programmatically. Instead, you can inform your app's users if they face problems while using your app (ex: Alarm is not triggering properly), they can enable Auto Start from Settings.
Try adding the android.intent.category.DEFAULT category. It is mandatory for implicit intents, but maybe it is being tweaked for some reason in Xiaomi phones and the intent is not passing one of the tests to being received by your application.
Add this in your manifest file in intent-filter
<action android:name="android.intent.action.BOOT_COMPLETED" />
You need to add
android:enabled="true"
and
android:exported="true"
exported can be false, but it is necessary to include exported.
I think it's a problem with ROM Xiaomi.eu, tested with the dev version, I used the MIUI 6.5.19 Beta version 7.4 on a Xiaomi Redmi Note 2 Prime. I have not checked with the stable version that can not be downloaded at this time for server maintenance. Broadcast receiver doesn't work on boot.
Probe the same app in a Xiaomi Mi 4 with stable Xiaomi Global ROM, MIUI 7.1.2, there worked perfectly after activating the autostart in the manager. Restart and perfectly worked the broadcast receiver and permissions required.
Now, I tested with Xiaomi.EU 7.3 stable, MIUI 7.3.2, Broadcast receiver works fine on boot and reboot. I registered my receiver with autostart in security manager, it doesn't work in ROM dev version. I don't tested with Xiaomi Official ROM Global dev.
My permissions:
<receiver android:name=".service.BootBroadcastReceiver"
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"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Xiomi has a reported bug for only using this reciever 5 minutes after the system actually boot-up -
http://xiaomi.eu/community/threads/alarmmanager-_wakeup-problem.21430/
You can try and add the -
android:enabled="true" and android:exported="true"
even though they should be set to true by default due to manufacturer system changes
it might be different on Xiomi android customized OS.
Just pay attention for their meaning
Since the android:exported="true"
Will let other applications access to your reciever.
you should see here. In Xiaomi devices, they block some permissions even if you require it. The only way to slove it is you must allow your app this permission manually.
I was suggesting to add android:enabled="true" but it was already offered.
So I can tell you that you first make sure yourself if the receiver registered properly or not. You can also try the other version of registering it - that is doing registration programmatically (preferably in onPause() & onResume()) and see if it's receiving the broadcast message or not.
Try to disable the MUIU Optimization from the Developer Options. It worked for me.
1- Go to Settings
2- Open Additional Settings
3- Open Developer Options
4- Find the Turn on MIUI optimization
5- Disable the switch button.
Related
I have implemented RECEIVE_BOOT_COMPLETED by making an entry in manifest and implementing MyBootReceiver.onReceive(..).
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
....
<receiver
android:name=".MyBootReceiver"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
It works well when run on an emulator (Pixel 2 API 21). However, when it is run on a API Level 30 or on PHysical device, OnePlus 6 (Oxygen 10.3.7), the BOOT notification isn't received.
But, when phone is restarted, other applications like Whatsapp, Sms etc are able to receive messages from server, possibly using some notification event. How is that possible ?
Am I missing something ?
one plus and Mi have customized their OS on top of Android. So they have overriden this function. refer Broadcast Receiver Not Working After Device Reboot in Android
On newer Android versions, you need to run adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -p com.mypackage.name. Without restricting the broadcast to your app, your device will actually reboot
regd your question,
But, when phone is restarted, other applications like Whatsapp, Sms
etc are able to receive messages from server, possibly using some
notification event. How is that possible ?
It's also possible by accessing the Phone Network State
I use the latest (3.4.1) version of the KNOX libraries, and trying to activate my license.
My AndroidManifest entry:
<receiver
android:name=".receiver.KnoxLicenseReceiver"
tools:ignore="ExportedReceiver">
<intent-filter>
<action android:name="com.samsung.android.knox.intent.action.LICENSE_STATUS" />
</intent-filter>
</receiver>
And activating the license like this:
KnoxEnterpriseLicenseManager
.getInstance(context)
.activateLicense(context.getString(R.string.const_kpe_key), getPackageName.exec())
It shows the Toast that the license was activated successfully (and works fine — I can, for example, disable the camera), but the receiver is never called.
I've tried on multiple devices with different Android versions (5.1 and 7.1) with no luck. What's wrong?
Well, Samsung docs are not correct. Correct intent action is
com.samsung.android.knox.intent.action.KNOX_LICENSE_STATUS
while action in docs is
com.samsung.android.knox.intent.action.LICENSE_STATUS
I want to listen to APN Changes in my Android App.
Therefore I start a Service on android.intent.action.BOOT_COMPLETED.
This Service starts a ContentObserver which listens to changes to
content://telephony/carriers/preferapn.
I tested this setup on a few different devices (e.g. LG Spirit with Android 5.0, Samsung A3 with 6.0, Emulator Nexus5 with 7.0 and Huawei P9 Lite with 7.0)
On the Huawei phone onCreate of my Service is not called.
My other approach with android.intent.action.ANY_DATA_STATE in combination with a BroadcastReceiver which is registerd in the Manifest doesn't work either on this phone.
relevant parts of my manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
...
<receiver android:name=".ConnectivityChangeReceiver">
<intent-filter>
<action android:name="android.intent.action.ANY_DATA_STATE" />
</intent-filter>
</receiver>
<receiver android:name=".APNChangedServiceStarter" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
<service android:name=".APNChangedService"></service>
Just for an update, Huawei changed the menu path in the Android 9 version.
On Huawei Mate 10 pro the way to get to this menu:
Settings -> Battery -> App launch -> Disable automatic management for your app.
A pop-up will appear, asking what you want to allow (all true by default). make sure that the first, Auto-launch is enabled
Huawei Phones have a built-in startup manager, it could be that the app is not yet enabled.
Go to Settings > All, and choose Startup manager.
This program is used to manage startup apps on Android phone.
Allow or disallow app to run automatically after the Huawei phone starts up.
I'm working on an android wear app that exchanges some information (using the Wearable Data Layer API) with a another android app installed in the phone device .
But if the Phone app is not running or the phone is locked the information cant be exchanged.
Basically I don't wont to look to my phone when I'm using my wearable device(Smartwatch).
any solutions ?
Thank you !
You will basically need to implement a WearableListenerService. You can find more on the section With a WearableService here.
This will spin up a service on the Android device to which you can communicate to.
Don't forget to add the permission in the AndroidManifest.
<service android:name=".DataLayerListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
Btw a handy library that gets away a lot of the boilerplate is Courier
I'm working with Mark Murphy's excellent Commonsware books - but it's a lot to digest. I built the 'FakePlayer' app (pretends to be an mp3 player). It contains a service. As a learning experience I tried to write a trivial app (has only a button) whose click handler does:
Intent i = new Intent();
i.setAction("com.example.cwfakeplayer.MyPlayerService");
Context context = getApplicationContext();
context.startService(i);
It worked fine - the service start ok. I noticed Eclipse complaining about no permission on the service, so I updated the service's manifest by adding 2 lines, android:permissions and android:exported:
<service
android:name="MyPlayerService"
android:permission="com.example.fakeplayer.permission.MY_PLAYER_PERMISSION"
android:exported="true"
<intent-filter>
<action android:name="com.example.fakeplayer.MyPlayerService"></action>
</intent-filter>
</service>
I reloaded the player app onto the device (I'm using a Galaxy S2) using 'debug' under eclipse. It seemed to work; the starter app caused a permission exception, which I expected.
I then added to the starter app's manifest (to give it the permission):
<manifest
...
<uses-sdk ....
....
<uses-permission android:name="com.example.fakeplayer.permission.MY_PLAYER_PERMISSION" />
I reloaded the starter app onto the device (using debug under Eclipse). Still get the permission error in the starter app.
I removed both apps from the device and reinstalled (using debug...), service app first, then starter. Still get perm error.
I am working my way through the 'how to use a remote service' section of Mr. Murphy's Advanced Android book, so I realized this is not the best way perhaps to work across apps.
I did a 'adb shell dumpsys package', located the starter app, and found it had 'permissionsFixed=false' and no 'grantedPermissions' section. I take this to mean the manifest change in the starter app did not manage to get the perm added to the app. But I have no idea why. As a learning experience, it's generated only confusion so far....
Any clues greatly appreciated! Thanks!
I updated the service's manifest by adding 2 lines, android:permissions and android:exported
Technically, android:exported="true" is superfluous, as having the <intent-filter> automatically makes the <service> be exported.
I removed both apps from the device and reinstalled (using debug...), service app first, then starter. Still get perm error.
You do not show where you ever declare the custom permission with the <permission> element. In practice, if you control both apps, put the same <permission> element in both manifests, so the order of installation of your two apps no longer matters.
Try replace this in your manifest
<service android:name="com.example.fakeplayer.MyPlayerService"></service>
instead of
<service
android:name="MyPlayerService"
android:permission="com.example.fakeplayer.permission.MY_PLAYER_PERMISSION"
android:exported="true"
<intent-filter>
<action android:name="com.example.fakeplayer.MyPlayerService"></action>
</intent-filter>
</service>
If this doesn't work, kindly post out your error.