Registration GCM Broacast Receiver - android

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?

Related

Can I remove category name from GCMBroadcastReceiver or is there any alternative name to be given instead of package name

In my application, I have to implement GCM Push Notification.In the manifest file the receiver will be as follows:
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.companyname.project" />
</intent-filter>
</receiver>
I want to remove the package name from the category name. Is it possible or is there any alternative value that can be given as category name.
category name should be there. It is used to filter the GCM messages. The point of the is to filter incoming GCM notifications based on your app / package name.
The docs for GCM show and as you have to register specific apps to allow GCM, this makes sense.
If you think about it, there may be any number of apps on an Android device which are registered for GCM. The fact they will all be receiving messages using the same core software means there has to be some way to 'route' the messages to the correct app - if there wasn't a way to do this, all GCM-registered apps would receive each others' messages.

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

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.

SMS static broadcastReceiver called twice Android Kitkat

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.

Android - SMS - intent-filters priority listing

I was wondering if it is possible to find a list that includes all the receivers associated to a certain action.
For example I have the following receiver that executes everytime that an SMS is received:
<receiver android:name=".SmsReceiver" android:enabled="true">
<intent-filter android:priority="101">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
So with the priority="101" it´s executed even before than the default message service in Android.
I would like to find all the intent-filter associated to a certail action, in this case "android.provider.Telephony.SMS_RECEIVED"
I tried to get into /data/data/com.android.provider.telephony/databases but no info is stored in ther.
It would be great if anybody could tell me where can I find that info, and even if it is possible.
Regards,
Pablo
Use PackageManager and queryBroadcastReceivers() to find out all of the BroadcastReceivers that will respond to a given Intent. In your case, you would create an SMS_RECEIVED Intent.

Categories

Resources