Android: where is android.provider.Telephony.SMS_RECEIVED located?

I am writing an application that should receive SMS, everyone uses the "Android intent android.provider.Telephony.SMS_RECEIVED_ACTION" in their code, but it looks like the API layer no longer supports it! Where is he now? I also did not find SMS_RECEIVED_ACTION in the class "android.telephony"! please tell me i am completely confused. Should I use older APIs?

+4
source share
4 answers

The Telephony class does not have a document API until API 19 (4.4 - KitKat). The lack of a class does not mean that what you are trying to do does not work. You must request this permission:

<uses-permission android:name="android.permission.RECEIVE_SMS"/> 

And if you register your receiver in your manifest, it will look something like this:

  <receiver android:name=".SmsIntentReceiver"> <intent-filter android:priority="1"> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> 

From android. Provider. Telephony AOSP:

 public static final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED"; 

Here is the source link for grepcode.com:

http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/2.3.2_r1/android/provider/Telephony.java/?v=source

Pay attention to the "@hide" immediately before the class declaration - it is, but is not displayed to developers. This is why it is not recognized in ADT.

+9
source

We need to read this document.

Android Developers Blog - Getting Your SMS Apps for KitKat

Starting with Android 4.4, you should stop listening to the SMS_RECEIVED_ACTION broadcast , which you can do at run time by checking the platform version, and then turn off the broadcast receiver for SMS_RECEIVED_ACTION using PackageManager.setComponentEnabledSetting (). However, you can continue to listen to this broadcast if your application only needs to read special SMS messages, for example, to check the phone number. Please note that starting with Android 4.4, any attempt by your application to interrupt the broadcast of SMS_RECEIVED_ACTION will be ignored, so that all interested applications can receive it.

I think we need to prepare for KitKat. This is a petty thing. :)

+6
source

android.telephony class provides information on the states of phones that are represented at api level 1. For more information, please read this android. telephony

android.telephony.SmsManager designed to receive message information from the device’s incoming messages. Here you can watch telephony.SmsManager

There is no indication that they are deprecated at api level 17.

0
source

You can use Telephony.Sms.Intents.SMS_RECEIVED_ACTION in your code.

Below is my working code:

 public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) { Bundle bundle = intent.getExtras(); if (bundle != null) { } } } 

You need to import import android.provider.Telephony;

0
source

Source: https://habr.com/ru/post/1499451/


All Articles