为什么sendTextMessage需要READ_PHONE_STATE权限? [英] Why would sendTextMessage require READ_PHONE_STATE permission?

查看:155
本文介绍了为什么sendTextMessage需要READ_PHONE_STATE权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序将此堆栈跟踪发送给了我,这似乎是引擎盖下发生了非常错误的事情.

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

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

java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10089 nor current process has android.permission.READ_PHONE_STATE.

   at android.os.Parcel.readException(Parcel.java:1218)
   at android.os.Parcel.readException(Parcel.java:1206)
   at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getLine1Number(IPhoneSubInfo.java:223)
   at android.telephony.TelephonyManager.getLine1Number(TelephonyManager.java:764)
   at android.telephony.SmsManager.sendTextMessage(SmsManager.java:129)
   at android.telephony.SmsManager.sendTextMessage(SmsManager.java:108)
   at com.emergency.button.SMSSender.safeSendSMS(SMSSender.java:91)
   at com.emergency.button.EmergencyActivity$EmergencyThread.sendSMS(EmergencyActivity.java:294)
   at com.emergency.button.EmergencyActivity$EmergencyThread.sendMessages(EmergencyActivity.java:386)
   at com.emergency.button.EmergencyActivity$EmergencyThread.run(EmergencyActivity.java:266)

所以我应该只捕获sendTextMessage周围的所有异常吗?这是谁的错?

So should I just catch any and all exceptions around sendTextMessage? Who's fault is this?

推荐答案

我的应用程序将此堆栈跟踪发送给了我,这似乎是引擎盖下发生了非常错误的事情.

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

你这么说,我想这是你第一次看到这个问题,而在其他手机上不会发生.

The way you say this, I assume this is the first time you've seen this problem and it doesn't happen on other phones.

在此手机型号的Android实现中,SmsManager是否有可能在尝试发送SMS消息之前尝试检查手机的状态".这纯粹是一种猜测,但尽管SMS Manager的Telephony API文档没有提及它,但这似乎也不是没有道理的事情.也许不是,我不确定.

Is it possible that in the Android implementation on this phone model, the SmsManager attempts to check the phone 'state' before attempting to send an SMS message. That's purely a guess but it doesn't seem an unreasonable thing to do although the Telephony API docs for SMS Manager don't mention it. Maybe not, I'm not sure.

由于在您的应用中发送SMS消息非常关键,因此,是的,您当然应该尽一切可能捕获与发送消息有关的任何异常(并在可能的情况下从异常状态中恢复).

As sending an SMS message is quite critical in your app, then yes you should certainly be doing all you can to catch any exceptions possibly related to sending the messae (and recovering from the exception state if possible).

似乎无法解决此特定问题,为什么不将READ_PHONE_STATE的uses-permission声明到清单中?

As it seems this particular problem cannot be recovered from, why not declare uses-permission for READ_PHONE_STATE into your manifest?

这篇关于为什么sendTextMessage需要READ_PHONE_STATE权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆