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 .
Related
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.
I rely on broadcast send/receive for my app to work.
This code works perfectly on all platforms, but on latest Android Preview L, the broadcast is not received:
Intent intent = new Intent("com.my.BROADCAST_RECEIVED");
sendBroadcast(intent);
Receiver is registered in the manifest, as usual:
<receiver
android:name=".SimpleBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.my.BROADCAST_RECEIVED" />
</intent-filter>
</receiver>
Note: if the receiver is registered in runtime (i.e. via registerReceiver(..)) - it does receive the broadcast.
Any information about this?
Found a different answer related to not receiving boot complete on SmartTv .
So as an act of despair I decided to give it a try and it worked!
Add a category tag to the intent filter. It's not documented anywhere:
<receiver
android:name=".SimpleBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.my.BROADCAST_RECEIVED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Hope this helps someone.
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've read in a few places that PhoneApp (com.android.phone.PhoneApp.java), is a "persistent process" which is "started early in the boot sequence." Can anybody explain exactly how and when this happens? Thanks.
Answering my own question....
The following entry in the AndroidManifest.xml file instructs the ActivityManager to start the specified activity.
<!-- Broadcast Receiver that will process BOOT Complete and launch OTA
-->
- <receiver android:name="OtaStartupReceiver" android:exported="false">
- <intent-filter android:priority="100">
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
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.