【问题标题】:send sms from enulator android从模拟器android发送短信
【发布时间】:2017-03-05 13:38:07
【问题描述】:

MainActivity.java

Button sendTestSMSButton = (Button)findViewById(R.id.sendTestSMSButton);
        sendTestSMSButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                System.out.println("Send SMS");

                try
                {
                    SmsManager smsManager = SmsManager.getDefault();
                    smsManager.sendTextMessage("+972526855556", null, "shenkin", null, null);
                }

                catch (Exception e)
                 {
                    e.printStackTrace();
                }
             }

        });

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.smssong.admin.smstosong">

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="22" />
    <uses-permission android:name="android.permission.SEND_SMS" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
     App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>

</manifest>

我收到错误“发送 SMS 消息:uid 10063 没有 android.permission.SEND_SMS。”

即使在 AndroidManifest.xml 中也有启用权限的代码。 我错过了什么?

【问题讨论】:

  • 我正在使用模拟器 SDK 22 但仍然无法发送短信
  • “模拟器 SDK”到底是什么意思?你的意思是你在 Lollipop 上运行?
  • targetSdkVersion 设置为 22,因为 23 不允许从 android 发送短信
  • 如果您使用的是 Android Studio,您在清单中设置的 SDK 版本将被 build.gradle 文件中的值覆盖。在那里查看targetSdkVersion 的设置。另外,是的,您仍然可以使用 23 发送短信;如果您的目标是该版本或更高版本,您只需要处理运行时权限。

标签: sms emulation send


【解决方案1】:

使用非法SDK出现权限错误

【讨论】:

    猜你喜欢
    • 2014-01-09
    • 1970-01-01
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多