My app needs to receive SMS. So far it seems to work on real devices and emulators from Gingerbread to JellyBean. I'm now testing it in a KitKat emulator, and the Broadcast Receiver is not fired.
I'm registering a the receiver in the manifest using the classic sms action:
<receiver android:name=".receivers.MyReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
I've also added the SMS permission in the manifest:
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
I've read the blog post on SMS changes in KitKat, where they say this intent filter should still work:
Any filters for the SMS_RECEIVED_ACTION broadcast in existing apps will continue to work the same on Android 4.4, but only as an observer of new messages, because unless your app also receives the SMS_DELIVER_ACTION broadcast, you cannot write to the SMS Provider on Android 4.4.
Which is fine because I just need to listen for new messages, and I don't need my app to be the default SMS app nor modify the provider (This is a very simple app with no activities, only a receiver and a service that is called from the receiver).
The emulator is very laggy, so I think it might be a problem with the emulator only. Too bad I don't have any KitKat device to test it. For now I'm testing in KitKat using the DDMS telephony tab. I've added logging to the receiver but I don't see anything in logcat. There are no exceptions nor any other message that could indicate problems. It looks the receiver is not being notified, but on the other hand I've double-checked and the app is installed.
What could be going wrong?
As #Seshu Vinai has pointed in the comments, the problem turns out to be the security restriction introduced in Android 3.1. I thought it was not the case since i had tested it before on JellyBean devices and emulators and the app seemed to work. But it did so only because I had previously launched an activity fron some unit tests, and thus the app was activated.
You can find more info in the following questions:
How to start a Service when .apk is Installed for the first time
Android BroadcastReceiver won't work
Android BroadcastReceiver not working after install
The broadcast receiver will not be called unless your app is the default app in KITKAT. You will be able get the contents directly, but you will not be able to listen to new messages. I had the same problem. I got to know after making my App as default.
Try making your app the default. You will notice the difference.
Related
Issue : Activity recognition API has an intent service which will get the motion activities and will get as part of intent (onHandleIntent). When I changed my app to target android Oreo, the functionality behaves as below
While app is in foreground, app detects activities.
while app in background, it doesn't detect activities
I tried to change the intent service to JobIntentService but not working.
Can anyone help on this?
Thanks in advance.
I faced the same issue. My app worked like charm on previous versions of Android, but no location updates in Oreo.
Found the solution in:
https://developer.android.com/about/versions/oreo/background-location-limits.html
I have a service as location listener that runs in the background. In orea background services get only few location updates. It has to be changed to a foreground service.
The only thing I had to do is calling startForeground() within onCreate() of the service.
You should check for location retreiving limitations for apps on Oreo when in background or using background services. The answer is to use foreground service or bring app to foreground.
I have seen many pages about this problem but didn't help me.
I have a service that should run in background even when the screen is off.
but some android devices (like many huawei phones) have battery care stuff that can kill service when screen is off, and android 6 has that option (keep running after screen off) but user should give that permission himself.
I see that telegram service get killed too, but how whatsapp service doesn't stop even when the screen is off.
this is my service in androidManifest
<service android:name=".myservice" />
is there any option in manifest that can keep service running when the screen is off? I can't use sticky-services because it runs over and over after screen turns on but my service should start once!
or any other solution for this problem?? thanks!
Good morning,
I'm facing this problem. I developed an Android Wear App that sends messages to the Mobile App using the DataApi and PutDataRequest.
Everything works fine, and the mobile receives the messages and I can store them in a DataBase, etc.
The problem is that when the App in the phone is close, not in background, but completely closed, then it does not receive any messages. That means that all the info that I was sending from the Smartwatch to the Phone is lost.
Once I open the App in the Phone, all the data that was sent while the App was closed, is not syncronized anymore.
I would like to Open the mobile Phone from the Smartwatch, when it checks that is closed, so the info that it sends won't be lost. It is that possible to do??
Thanks!
Carlos
You need to create a Service on your phone that extends WearableListenerService and then declare it in your manifest as follows :
<service
android:name=".MessageListener"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
You don't need to start this service, it will be started when a message, or a data change will be received.
Basically I am trying to make an activity containing a button which reboots the device and after the reboot returns to the same activity.
I understand that this question may get confused with others about rebooting the device, but that is not the focus of this question as I can get the device to reboot fine.
I have made the button reboot the device but the only way I can get it to start the activity after it's finished rebooting is to register a broadcast receiver for BOOT_COMPLETED in the manifest. The trouble is that this method starts the activity every time the device boots which is undesirable. When I register the receiver on the button click listener it does not start the activity after the reboot.
I was wondering if there might be an extra in BOOT_COMPLETED that I could use to decide if it had been purposefully rebooted.
Any advice would be appreciated, thanks in advance!
Just save an integer corresponding to device purposely being rebooted through your activity. Use SharedPreference for the same. On reboot, in your broadcast receiver, check if the value is set. If it is set, start your activity, otherwise, let it go.
EDIT :
Always, unset this value when reboot is complete and your Activity is in front.
Your XML should be stored in a file named AndroidManifest.xml, not manifest.java.
Another reason your code is not being run, might be that your App is installed on external storage (sdcard). BOOT_COMPLETE is sent to applications before external storage is mounted. So if application is installed to external storage it won't receive BOOT_COMPLETE broadcast message.
If that isn't the problem, there is already a very good description of how to get boot completed receivers working on Android.
Trying to start a service on boot on Android
Is this completely and utterly impossible in android Kitkat since Google has made so many changes to the way messaging works? I have tried using broadcast receivers and abortBroadcast, but to no avail.
Is there any way to block SMS programmatically in Android KitKat?
No. Starting with KitKat, the SMS_RECEIVED broadcast cannot be aborted, so any app with the RECEIVE_SMS permission can still listen for it and retrieve the incoming message. If your app is the default app, it can choose not to write the message to the Provider, so it will not appear to any app querying the Provider for messages, but even the default app cannot abort the SMS_RECEIVED broadcast.