Sms Permissions not working. No matter where I put

2019-07-19 16:39发布

问题:

I'm just trying to send a simple text to my self.. of course the exception is java.lang.SecurityException: Sending SMS message: uid 10263 does not have android.permission.SEND_SMS

This is what my Manifest file looks like

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.homesafe"
    android:versionCode="1"
    android:versionName="1.0" 
    android:permission="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>

Right now it is under the Manifest tag.. but even if I move the permission under the application tag, I still get the same error. I'm confused..

回答1:

All you need to do is this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.homesafe"
    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>


回答2:

Add Your permissions after use-sdk like that:

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

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

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

    <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>