发送短信权限无效 [英] Send sms permission doesn't work

查看:161
本文介绍了发送短信权限无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发送一条简单的消息,清单中有<uses-permission android:name="android.permission.SEND_SMS"/>,但我总是得到:java.lang.SecurityException: Sending SMS message: uid 10064 does not have android.permission.SEND_SMS.

I want to send a simple message and i have <uses-permission android:name="android.permission.SEND_SMS"/> in my manifest, but I always get: java.lang.SecurityException: Sending SMS message: uid 10064 does not have android.permission.SEND_SMS.

我检查了此答案,但仍然无法正常工作.

I checked this answer, but it still doesn't work.

这是我的清单:

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


<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"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

这是我的代码:

package com.roa.sendsms;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.telephony.SmsManager;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    Button sendButton =  (Button)findViewById(R.id.sendButton);
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            sendSms(phoneNumber, "you get message from roish app!!");
        }
    });
}

private void sendSms(String phoneNumber, String message){
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, null, null);
}

}

感谢所有人.

推荐答案

所有您需要做的,

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.roa.sendsms"
    android:versionCode="1"
    android:versionName="1.0">

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:name="com.example.homesafe.MainActivity"
            android:label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

尝试运行到移动设备中,而不是将其检查到仿真器中.仅仅因为模拟器没有我们的手机拥有的SIM卡,所以.

Try to run into the mobile instead checking it to the emulator. Just because emulator does not have the sim card as our mobiles have, so.

这篇关于发送短信权限无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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