Why would sendTextMessage require READ_PHONE_STATE permission?

后端 未结 3 1570
情话喂你
情话喂你 2021-02-20 06:42

My app sent home this stack trace which seems as though something very wrong is going on under the hood.

phone_model=SKY IM-A630K, android_version=2.1-update1

         


        
3条回答
  •  甜味超标
    2021-02-20 07:19

    I had the same problem with an HTC phone (Desire 728G) Dual Sim and I had to include "READ_PHONE_STATE" but now Google is asking for a privacy policy, and because I am too lazy to do it :) I did some research and I found a better way without the use of "READ_PHONE_STATE". The problem is that some devices (mainly dual sim) need the "READ_PHONE_STATE" permission to look for the default "SubscriptionId" that is what happens when you call "SmsManager.getDefault()". Below is the code I am using to avoid this issue by assigning the value (1) to SubscriptionId if any exception accrued:

                SmsManager smsManager = SmsManager.getDefault();
    
                if (android.os.Build.VERSION.SDK_INT >= 22){
                    Log.e("Alert","Checking SubscriptionId");
                try {
                    Log.e("Alert","SubscriptionId is " + smsManager.getSubscriptionId());
                } catch (Exception e) {
                    Log.e("Alert",e.getMessage());
                    Log.e("Alert","Fixed SubscriptionId to 1");
                    smsManager = SmsManager.getSmsManagerForSubscriptionId(1);
                }
                }
    
                smsManager.sendTextMessage(mobileNumber, null, msgStr, null, null);
    

提交回复
热议问题