Create your custom broadcast receiver to receive sms. write the logic to abort the boradcast so that the message will not be available to your inbox
public class SMSReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
this.abortBroadcast();
}
}
<receiver android:name=".SMSReceiver">
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
Not working any suggestion ...
Still show notification and message reaching in inbox
They removed this ability several versions ago. Only the chosen SMS app of the user can delete messages or prevent them from hitting the inbox.
Related
I am trying to get the Android BroadcastReceiver to run when a Firebase Cloud message notification is received by the Android system.
public class MyBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "MyBroadcastReceiver";
#Override
public void onReceive(final Context context, Intent intent) {
Toast.makeText(context, "EVENT OCCURED", Toast.LENGTH_LONG).show();
}
}
It is required in the AndroidManifest to specify receiver tags as such:
<receiver
android:name=".MyBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</receiver>
As you can see in the Manifest above I've added:
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
to make sure the BroadcastReceiver fires when I plug cable to Android device. It works fine.
Therefore the issue lies with the:
<action android:name="com.google.firebase.MESSAGING_EVENT" />
Is this intent-filter action not recognized by the BroadcastReceiver?
Is there another intent-filter action for Firebase messaging the BroadcastReceiver uses?
The Android Intent messaging system processes Intents in three "channels": Activities, Services and BroadcastReceivers. The methods for publishing an Intent indicate the channel type: startActivity(), startService() and sendBroadcast(). An intent published with startService() will only match the intent filter of a Service. It is not tested against Activities and BroadcastReceivers.
Because action com.google.firebase.MESSAGING_EVENT is normally received by a Service derived from FirebaseMessagingService, it must be the case that the action is published in the Service channel. You will not be able to receive it with a BroadcastReceiver.
This should be fairly easy but I somehow can't get a Broadcast receiver's onReceive method triggered. Details below:
App B provides a broadcast receiver.
Manifest:
<receiver android:name=".MyNotificationReceiver">
<intent-filter>
<action android:name="com.go.foo.A_ACTION" />
</intent-filter>
</receiver>
Java:
public class MyNotificationReceiver extends BroadcastReceiver {
private final String TAG= "MyNotificationReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "this is not shown" , Toast.LENGTH_LONG).show();
}
}
App A is Broadcast Sender App:
Java
Intent intent = new Intent();
intent.setAction("com.go.foo.A_ACTION");
sendBroadcast(intent);
Log.d(TAG, "broadcast intent sent...");
I can see the log statement that the broadcast is sent but the receiver's onReceive() callback is not getting triggered. Am I doing something wrong?
Interesting why it's not working. Try this one out. I know the default values of exported and enabled are true. But still have a try at it.
<receiver android:name=".MyNotificationReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.go.foo.A_ACTION" />
</intent-filter>
</receiver>
Learned something new today. As of Android 4.1, the system no longer sends broadcasts to app components without an activity. The broadcast received started working after I added an activity in the manifest.
I hope an app can forward SMS automatically when an SMS arrives. I think the service need to keep run in foreground to monitor SMS.
And I have to start and stop the service,and the service starts automatically when moblie phone power on. How can I do this? Thanks!
Add android:permission="android.permission.RECEIVE_BOOT_COMPLETED" to your manifest and Create a BroadcastReceiver like following:
public class autostart extends BroadcastReceiver
{
public void onReceive(Context arg0, Intent arg1)
{
Intent intent = new Intent(arg0,yourService.class);
arg0.startService(intent);
Log.i("Autostart", "started");
}
}
You can monitor the sms using this piece of code.Create a Broadcast reciever as Yup said and send sms using service.
<receiver android:name=".SmsReceiver" android:exported="true" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
I'm developing an Android application, i have a service running in background that i want to lauch it by introducing a custom ussd number. For example when i call #12345# my service starts.Thank you in advance
You can register a BroadcastReceiver in your manifest that listens for android.provider.Telephony.SECRET_CODE intents. You also specify the secret code in the manifest.
For example, this manifest entry registers MyBroadcastReceiver for the secret code *#*#12345#*#*.
<receiver android:name="MyBroadcastReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE"/>
<data android:scheme="android_secret_code" android:host="12345"/>
</intent-filter>
</receiver>
MyBroadcastReceiver should look something like this:
public class MyBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// Create an intent to start your Service.
}
}
In my application I want to delete all SMS from selected number using broadcast receivers. and it should be perform after every read message(I don't want to delete unread message).
Does anyone can help me to solve this problem?
Sorry about my English (I'm not speaking good).
Thanks
There are hundreds of SMS clients. You will need to contact each of their developers and ask them that question.
With respect to the Messenger application that is part of the Android open source project, it has no documented or supported APIs for this.
I couldn't found any solution for my question. but I got the solution to delete SMS before receiving using abortBroadcast() method in receiver.
public class SMSReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(/*is selected no*/) {
//store SMS info in separate file
abortBroadcast();
}
}
}
and In manifest file:
<receiver android:name=".SMSReceiver" android:enabled="true">
<intent-filter android:priority="1000" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>