Receive SMS to Android app without opening the app at least once - android

I am trying to receive SMS from my android app. I have following receiver specified in my manifest.
<receiver android:exported="true" android:name="com.lahiruchandima.myapp.SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
SMSReceiver successfully receives SMS if my app is installed and opened once (app does not need to be running at the moment the SMS is received to the device). But, if i do not open my app at least once after a fresh install, it doesn't receive any SMS.
Does anybody know a way to make it possible to receive SMS without opening the app at least once?

Does anybody know a way to make it possible to receive SMS without opening the app at least once?
It can't be done, on newer Android versions at least. Ever since Android 3.1, apps are installed in a stopped state, and require that the user open it at least once before components like your BroadcastReceiver can function. This is for security reasons, to prevent, or at least hamper, malicious program behavior.

Related

Wear App doesn't work if the phone App isn't running or the the phone is locked

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

Android: SMS is blocked by ChatON app

I have written an app which receives incoming SMSes, saves it and displays it to the users. Suddenly my app stopped receiving SMS due to Samsung's ChatOn app update.
Here is the my Manifest.xml:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<receiver android:name="com.myapp.sms.service.SMSReceiver"
android:permission="android.permission.BROADCAST_SMS" android:exported="true">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
I had this issue earlier with Hangout which started supporting SMS. So, at that time I added priority to 999 (max value) in manifest file. And this worked.
But after recent update of ChatOn app, my app stopped receiving SMS. Please tell me how can I overcome with this.
For work around, I unchecked SMS option on ChatOn app.
Any help is appreciated.
There is no guaranteed way that your app can get "first crack" at SMS messages, on Android 4.3 and below. Even if you set your app to be the highest possible priority, other apps can do the same. GoSMS notably does this, and you have indicated that ChatOn does as well. If they get the message first and abort the broadcast, you will not receive the message.
There is nothing that you can do, other than to detect this possibility (using PackageManager) and alert users as to the potential behavior.
Note that on Android 4.4, this is a lot different:
The broadcast can no longer be aborted
There are separate broadcasts for apps that are monitoring SMS and the actual final SMS client app

app isn't woken up on receiving gcm message broadcast

I've recently added GCM messaging to my app using google's helper classes (GCMBroadcastReceiver, GCMBaseIntentService). It works beautifully when the app is running, both when it's in the foreground and when it's not. However, when it's not running, nothing works.
As a test, I extended GCMBroadcastReceiver and added log statements to getGCMIntentServiceClassName() and peekService(). When the app is running and a message arrives I see the former called. The OS then instantiates my service class, which eventually results in onMessage() being called.
When the app isn't running getGCMIntentServiceClassName() never gets called.
My manifest is pretty much the boiler-plate code from Google's GCM examples.
Is there an extra permission or flag I need to set in order for the OS to wake up my app when it's not running and a message arrives w/ the correct intent category? My receiver is defined as:
<receiver
android:name=".GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="PACKAGENAME" />
</intent-filter>
</receiver>
Bear in mind: this works when the app is running in the background.
Bleh. Figured it out. David Wasser's answer here:
BroadcastReceiver isn't working
explains why I'm not seeing the broadcasts when my app isn't running. I was force quitting it from Manage Applications, which puts it into the "stopped" state (and thereby causes the system to exclude it from broadcasts by default).
When I install the app, launch it, power down the device, then power it on again, I'm receiving the broadcasts properly.
I had same issue and fixed by just running the through RUN button from Android Studio.
I think in Debug Mode it doesn't work

android : detect the reinstall of an app from the app code

Is there a way to detect from app code when it is being reinstalled.
I saw that app update from market can be detected by listening to PACKAGE_REPLACED event in broadcast receiver. But that these events are not delivered to the app , if the app is reinstalled from editor (eclipse ).
My requirement is that i am disabling a component(Launcher activity). The app install will fail if it is not enabled. SO everytime before reinstall i want to enable this component.
I am talking about the reinstall before publishing in market. While developing , each time i reinstall the app to test some modification, i want to detect this from my app and make the component enabled.
I saw from my example that the following events will be broadcasted when an app is reinstalled from eclipse.
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
</intent-filter>
I defined a broadcast receiver for these actions and from onreceive i am able to enable my component

Android broadcast receiver not getting called immediately after install

I have an Android app that listens to SMS messages. This is in the manifest:
<receiver android:name=".IncomingSMSBroadcastReceiver" android:enabled="true">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
The broadcast receivers works fine if the app is installed and opened. But I want the receiver to be able to be called immediately after install, in case user has remotely installed from the Android Market website and is not present in front of the phone. When I install APK using adb
./adb install myapp.apk
I can see the app is installed. But when I send a SMS message, my app doesnt respond. After I open the app once, it appears all the initialization happens at this point, and now the app responds to SMS messages just fine.
One possibility is that the ADB install is different from the Market install.
Any ideas?
It is not Possible. AFAIK until receiver is not registered then it can not detect any action.You have not any problem with code.But your receiver will work when it start one.For this we have to run our application at least one time.So that Manifest Register the Receiver

Categories

Resources