简体   繁体   English

为什么即使具有必要的权限,我的应用程序也无法发送SMS?

[英]Why is my app not able to send SMS even with requisite permissions?

My app is trying to send a sms to another number. 我的应用正在尝试向另一个号码发送短信。 I have the requisite permission(SEND_SMS) granted by the user. 我具有用户授予的必要权限(SEND_SMS)。 The message however does not get sent.The default messaging app display the message with a "failure to send/Resend" prompt. 但是,该消息不会发送。默认的消息传递应用程序显示消息,并带有“发送/重新发送失败”提示。 What is the reason behind this and how do I fix this? 这背后的原因是什么,我该如何解决? My code is pretty straightforward- 我的代码非常简单-

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneno, null, txt, null, null);

Note- My app operates well below the sms frequency limit Edit : It works fine when run from an activity but fails when run from a service. 注意-我的应用程序在短信频率限制以下运行良好。编辑:从活动运行时,它运行正常,但从服务运行时,则运行失败。 What's the reasoning behind this ? 这背后的原因是什么?

The problem seemed to be because of where the code was getting called from . 问题似乎是由于从哪里调用了代码。 I had a service (running on a seperate thread) spawn a new thread to send out the SMSs , for some reason this seemed to lead to problems. 我有一个服务(在单独的线程上运行)产生了一个新的线程来发送SMS,出于某种原因,这似乎导致了问题。 After I removed all that unnecessary complexity and have the sms sent directly from the service it works fine. 在删除所有不必要的复杂性并直接从服务发送短信后,它可以正常工作。

Use this code instead: 请改用以下代码:

Intent sInt = new Intent(Intent.ACTION_VIEW);
sInt.putExtra("address", new String[]{txtMobile.getText().toString()});
sInt.putExtra("sms_body",txtMessage.getText().toString());
sInt.setType("vnd.android-dir/mms-sms");

Make sure you have this tag in your manifest: 确保清单中有此标记:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在Google Play控制台中收到短信和CALL_LOG警告,当我的应用程序DOESNT使用甚至远程接近这些权限的任何内容时? - Why am I getting SMS and CALL_LOG warning in Google Play console, when my app DOESNT use anything even remotely close to these permissions? 即使通过模拟器和真机也无法发送短信 - Not able to send SMS even through the emulator and a real phone 如何将短信从我的短信应用发送到应用 - how to send sms from my sms app to app 我的短信传输相关应用因违反权限政策而被拒绝 - My SMS Transfer related App rejected due to Violation of Permissions policy 为什么Account Kit不再通过短信将代码发送到我的Android应用程序? - Why does Account Kit no longer send codes via SMS to my Android app? 即使从应用程序中删除了所有与策略相关的权限,Android 应用程序仍因违反通话记录或短信权限策略而被拒绝? - Android app rejected for Call Log or SMS permissions policy violation even after removing all policy related permissions from the app? 在发布具有SMS权限的应用程序时出现问题 - Problem publishing an app with SMS permissions 从联系人视图,如何发送联系人号码到我的短信应用程序,发送短信给它 - From a contact view, how to send a contact number to my sms app, to send an sms to it 在phonegap应用中发送短信 - send sms in phonegap app 如何从我的应用程序向其他Android设备发送短信 - How to send SMS message to another android device from my app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM