Launching application when receiving on DATA_SMS_RECEIVED - android

I have declared a broadcast receiver in manifest for receiving DATA_SMS_RECEIVED, the broadcast receiver triggered when the application is running, but when the application is closed nothing happens and no broadcasts are received.
<receiver android:name="edu.sharif.iis.khasis.SmsReceiver" android:exported="true" android:enabled="true">
<intent-filter android:priority="999">
<action android:name="android.intent.action.DATA_SMS_RECEIVED"/>
<data android:scheme="sms" android:host="*" android:port="8901" />
</intent-filter>
</receiver>
I have tested this scheme with BOOT_COMPLETED and it works well, but doesn't works with DATA_SMS_RECEIVED. could someone tell me what is the problem?

Add this
<action android:name="android.permission.RECEIVE_SMS" />
It is OS generated action.

Related

How to receive BOOT_COMPLETED on Android TV

I'm developing an app for Android TV. I have a sticky service & a broadcast receiver that should restart this service after system reboot.
The code works perfect for any phone, but, in the case of the TV, any of the actions that I defined in the receiver's intent isn't received, when turning on the TV from standby(using the remote). It works when I unplug the TV and plug it again.
Has anyone tried something similiar? Any advice might help. Thanks
I've tried BOOT_COMPLETED, QUICKBOOT_POWERON, REBOOT, ACTION_POWER_CONNECTED.
Here is the receiver I've configured.
<receiver
android:name=".MyReceiver"
android:directBootAware="true"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"
/>
<action
android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
<action
android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action
android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Expected to catch the action of turning on the device in the broadcast.
Please check if you have added following permission.
uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"

android.intent.action.MY_PACKAGE_REPLACED Not getting triggered

I have this receiver declared in my Manifest file. I am receiving the broadcast in one phone that is Samsung Note 2 Jelly bean but not receiving the broadcast on another phone, Redmi 4.4.4. Please let me know what might be the issue.
<receiver
android:name=".UpgradeReceiver"
android:enabled="true"
android:exported="false">
<intent-filter android:priority="999" >
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
</receiver>

is having two broadcast receivers valid in android?

i don't know if this is okay having two broadcast receivers in my android app. I separated them cause the one receiver with the boot_completed, it will do a different task and the other receiver with also do different task when they receive a broadcast.
<receiver android:name=".Autostart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name=".AlarmManagerBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
That is perfectly valid you should always try to seperate your concerns which part of a good architecture/good design principles.

Registering a Phonestate receiver after rebooting

I have implemented a receiver like this (in the manifest file)
<receiver android:name="com.phonelight.realparrot.RecorderBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE">
</action>
</intent-filter>
</receiver>
If the state of the phone changes, the recorder broadcast receiver is invoked.
Everything is fine. However, If I reboot the device, the receiver is never invoked until I run my application.
I need to register (not invoking) this receiver after booting.
Many thank,
[Edit]
I solved the problem by adding the following receiver to the Manifest file
<receiver android:name="com.phonelight.realparrotpro.RecorderBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
I did not register the RecorderBroadcastReceiver in the java code though.
I only added the above receiver. It means invoking anything from an app will register all the receivers written in the Manifest file.
You need to create a receiver for onBootComplete and then register your receiver there. This way your receiver will get registered even after reboot.
<receiver android:name="App_Receiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Android broadcastreceiver static registering problems

I understand that I can register a broadcast receiver either statically through the manifest or programmatically by registering and unregistering the receiver in an activity. In my case I want the OS to instantiate and call my broadcast receiver when my code is not in memory. So I included my receiver in my manifest. Unfortunately if my code is not in memory, my broadcast receiver never runs. I am very confused as to why this is. I have included snippets of my manifest below. Please let me know if there is something wrong/missing with this. Thank you.
<receiver android:name=".DesktopConnectionReceiver"
android:enabled="true"
android:exported="true"
android:process=":remote">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
<action android:name="android.intent.action.UMS_CONNECTED"/>
</intent-filter>
</receiver>

Categories

Resources