SMS static broadcastReceiver called twice Android Kitkat - android

I am implementing sms receive functionality in Android kitkat 4.4+. I am able to set my application as default successfully but when an sms is received broadcast receiver is called twice. I am unable to find the cause of this problem.
here is how I have declared my Broadcast reciever in manifest
<receiver
android:name="com.package.SmsRecieverKitkat"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS" >
<intent-filter >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
</receiver>

when an sms is recieved broadcast reciever is called twice
That is because you are asking for both SMS_RECEIVED and SMS_DELIVER broadcasts. If you only want one of those, only listen for that one.

Related

Will android install referrer receiver also listen to broadcasts of other apps installed with a referrer?

I have a Install referrer receiver in my manifest.
<receiver
android:name="xx.yy.zz.InstallReferrerReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
And I get the referrer in the broadcast receiver as:
String referrer = intent.getStringExtra("referrer");
My doubt is would the receiver also listen to broadcasts of other apps which are installed with a referrer.
I want to listen to broadcasts for my app only.
If this problem exists, what would be the solution for it?
<receiver
android:name="xx.yy.zz.InstallReferrerReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
**<data android:scheme="package" />**
</intent-filter>
</receiver>
add your package in the receiver and while receive the broadcast in the OnReceive method check for your package
this will solve your problem

prevent other apps from sending broadcasts to my broadcastReceiver

I have a broadcastReceiver registered in manifest that receives broadcasts sent from one of my services with a custom action. I have it already working but for security reasons i want to prevent other apps from sending fake broadcast to my receiver. How can i do that?
Manifest
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="MyAction"/>
</intent-filter>
</receiver>
Every reciever with exported tag set to false will only receive broadcasts sent from its own application process.
so it will be:
<receiver android:name=".MyReceiver"
android:exported="false">
<intent-filter>
<action android:name="MyAction"/>
</intent-filter>
</receiver>
As another solution i found that i can use permissions.
more on here

BroadcastReceiver for Incoming SMS is not working in Android 4.4 and above

In my project I am having BroadcastReceiver for listening to incomming SMS.
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<receiver android:name="com.project.cdacReceiver" android:exported="true">
<intent-filter android:priority="2147483647" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
This code is working fine but if I do Kill/Force Close the application in Android 4.4.2 then the application is not receiving Broadcast for Incoming SMS. I have tried in Android 5.0 also, am getting the same problem.
is anything am doing wrong or from android 4.4 and above are they have done any changes?

Broacast receiver not receiving intent if another app registered for same intent before (PHONE_STATE)?

My app registers in the manifest a broadcastreceiver for PHONE_STATE intent.
<receiver android:name=".receiver.PhoneStateReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
<action android:name="android.intent.action.PHONE_STATE"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Everything worked fine until i installed another app which handles phone calls (in specific it records audio of phone calls). From that moment my registered receiver does not fire every time. If i remote the second app all returns to be ok.
I assume that this app (as mine) registers a broadcastreceiver for PHONE_STATE intent. Is it possible that this app "consumes" the broadcastreceiver and so it will not fire mine?
i assume that the other broadcast consumer has called the abortBroadcast() method, that ... will prevent any other broadcast receivers from receiving the broadcast.

Registration GCM Broacast Receiver

According with this:
Note that Google may periodically refresh the registration ID, so you should design your >Android application with the understanding that the >com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times.
I'm using the new GCM ( Google Play Services ), so i thinked to use a Broadcast Receiver for this intent:
<receiver
android:name="com.example.gcmclient.RegistrationHandler"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
</receiver>
I would use this Broadcast Receiver to be able to detect that Registration_ID is changed and send it to my server. Can i do this or i am on a wrong way?

Categories

Resources