📌  相关文章
📜  android.intent.action.DATA_SMS_RECEIVED (1)

📅  最后修改于: 2023-12-03 15:13:22.191000             🧑  作者: Mango

android.intent.action.DATA_SMS_RECEIVED

The android.intent.action.DATA_SMS_RECEIVED is a constant that represents the action to indicate that a data SMS has been received by the device. This action is broadcasted by the system when a data SMS message is received and ready to be processed by an application.

Intent Action constant
String ACTION_DATA_SMS_RECEIVED = "android.intent.action.DATA_SMS_RECEIVED";
Intent Filter Example
<intent-filter>
    <action android:name="android.intent.action.DATA_SMS_RECEIVED" />
    <data android:scheme="sms" />
    <data android:host="localhost" />
</intent-filter>
Broadcast Receiver Example
public class DataSmsReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.intent.action.DATA_SMS_RECEIVED")) {
            // Process the received data SMS here
        }
    }
}

Explanation:

When a data SMS message is received, the DATA_SMS_RECEIVED action is broadcasted by the system. To handle this action, you can define a broadcast receiver in your application's manifest file with an intent filter specifying the android.intent.action.DATA_SMS_RECEIVED action.

The example intent filter above shows that it filters for data SMS messages received via the "sms" scheme and the "localhost" host. You can modify this to match your specific requirements.

In the broadcast receiver's onReceive method, you can implement the logic to process the received data SMS. You can access the SMS data and perform any necessary actions based on the content of the message.

Remember to obtain the necessary permissions, such as RECEIVE_SMS and READ_SMS, in order to receive and read the data SMS messages.

By using the android.intent.action.DATA_SMS_RECEIVED action, your application can be notified when a data SMS is received, allowing you to handle and process the data accordingly.