Hi I know this question has been asked multiple times but my requirement is a little different so pls bear with me.
I use two different libraries in my android application. One is for parse push notification which has the following declarations:
<receiver
android:name="com.parse.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="com.airloyal.ladooo" />
</intent-filter>
</receiver>
and the declaration for the other receiver is:
<receiver
android:name="com.google.android.gcm.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="com.airloyal.ladooo" />
</intent-filter>
</receiver>
I definitely need both the libraries in my app so removing one is not an option. I use both the receivers for different purposes. But when I declare both the receivers there is a conflict and I am not able to receive any push notifications.
Can someone pls point me in the right direction?
P.S Both the libraries are jar files and I do not have control over the receivers of both. So forwarding is not an option.
Any help would be appreciated. Thanks
If the broadcast receivers are conflict with each other, you may try to set the priority of your receiver in the AndroidManifest.xml in <intent-filter>
Use this attribute only if you really need to impose a specific order in which the broadcasts are received, or want to force Android to prefer one activity over others.
The value must be an integer, such as "100". Higher numbers have a higher priority. The default value is 0. The value must be greater than -1000 and less than 1000.
sample code:
<intent-filter android:icon="drawable resource"
android:label="string resource"
android:priority="integer" >
. . .
</intent-filter>
Also, another way to solve, please refer to here.
Related
migrating from Parse I got stuck by not being able to override PushBots notification creation code like I used to do with getNotification function in ParsePushBroadcastReceiver. My project needs multiline and separate push notifications, but PushBots default behavior is to show single line and group notifications by application.
I tried canceling notification in the onReceive function of BroadcastReceiver (PBConstants.EVENT_MSG_RECEIVE event), so I could create & display my own push, but I don't know notification ID and CancelAll() didn't work (also would be a bad idea).
Pushbots.sharedInstance() does have a setNotificationBuilder function, which accepts PBGenerate object, but I have no idea how to construct it properly and if this actually would help my case.
Couldn't find any documentation & get a response from support yet, so asking here if maybe someone knows a solution or a way to workaround this issue.
Here's how receivers are defined in AndroidManifest.xml
<receiver
android:name="com.pushbots.google.gcm.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="com.my.app" />
</intent-filter>
</receiver>
<receiver android:name="com.my.app.MyPushReceiver" />
<service android:name="com.pushbots.push.GCMIntentService" />
Thank you in advance!
I create simple "ParseStarterProject" as default of parse.com project. It works. I send notification from one device to other device successfully via setchannel method.
But the problem is I do not use receiver class(I do not know how can I use that) so when a notification comes I need to get its message ? it is possible? or if I use set data can I get its data ?
I use this code to send message:
ParsePush push = new ParsePush();
String yourMessage = "Selam from LG G2";//I want to get this message from other device?
push.setChannel("device2");
push.setMessage(yourMessage);
//push.setData("exampledata"); if I use this can I get this data from other device?
push.sendInBackground();
my manifest file:
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.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" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
thanks in advance
Create a class that extends BroadcastReceiver, here we call it MyCustomReceiver. Declare the usage of this receiver in your manifest:
<receiver android:name="com.example.MyCustomReceiver" android:exported="false">
<intent-filter>
<action android:name="com.example.UPDATE_STATUS" />
</intent-filter>
</receiver>
I'm not sure what you mean by you have problems with "MyCustomReceiver class on the main activity", in your comment to #kingspeech's answer.
In the worst case, you can create your own Receiver which extends the ParseBroadcastReceiver (and reference the extended class in the manifest). Then it should work by default, but you'll be able to hook into onReceive(Context, Intent)
As Parse tutorial directs, you ca use JSONObject to set data and you can put whatever you want.
Then when you receive Push notification you can have a access to read the previously prepared JSONObject. Please look at the Android tutorial https://parse.com/docs/push_guide#options/Android.
Hope this helps,
Regards.
I have tried to use the sendDataMessage() of android.telephony.SmsManager with the help of almost every sample that i could come accross.. Yet no success..
[In case u want to see the code then simply check the "Sending Sms android" link on mobiForge, i guess its the most popular one (and the one that i've used).]
This is one of the examples in reference to this question.
When i use the standard receiver shown in samples as follows, my Broadcast Receiver does indeed get activated and i am able to see the Toast which contains my message thus proving that my receiver is successfully running. [By the way, i am calling the SmsManager.sendTextMessage() which is working successfully so no issues there].
<receiver android:name=".SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
However when i use the following receiver, i am unable to get the Toast which means that my receiver is clearly not getting activated, hence no Toast.
<receiver android:name=".SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<data android:port="8901"/>
<data android:scheme="sms"/>
</intent-filter>
</receiver>
My question here is Why?
In case some of you are thinking that the port number in my sendDataMessage() is not right then i assure you that its 8901 which is a short value.
Hence i would like to request anyone with a solution to this to either explain the solution or provide a working example.
Thanking anyone who can help in advance!
Best Regards,
Siddhant
Well i seem to have found out the problem in my code.
The fix was to change the android:name value in the above shown receiver from android.provider.Telephony.SMS_RECEIVED to android.intent.action.DATA_SMS_RECEIVED
So the new receiver will look like:
<receiver android:name=".SMSReceiver">
<intent-filter>
<action android:name="android.intent.action.DATA_SMS_RECEIVED" />
<data android:port="8901"/>
<data android:scheme="sms"/>
</intent-filter>
</receiver>
Thanks to KRVarma SMSDemo which provided some really useful insight after understanding the code.
Here are details of a possible bug with the Android emulator regarding this functionality.
I tried to use a receiver to get Information about battery when received a system broadcast, but it failed without doing anything.
Here is the code:
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction()))
{//doing
1...
}
and in AndroidManifest.xml
<receiver android:name=".BroadCastReceiver_battery">
<intent-filter>
<action android:name="android.intent.action.BATTERY_CHANGED" />
</intent-filter>
</receiver>
quasharou ,
I found this tutorial useful
Hope it helps .
i want receive all start app intents (i think MAIN/LAUNCHER, see below) to log how often i used the application. So i do not want create an activity... I tried several receiver blocks, but for now nothing works:
with, without priority, only the action, both, only the category and so on..
<receiver android:name=".Receiver" android:enabled="true"
android:process=".e">
<intent-filter priority="100000" android:priority="100000">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
Have anyone an idea?
Thanks
I want receive all start app intents
You cannot do that, sorry.