0

Whats wrong with my manifest file? my app crashes saying no permissions to send sms even added in my manifest file

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

        <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>
            <activity android:name=".AdminActivity" />
            <activity android:name=".ConductExam" />
            <activity android:name=".ResultActivity"></activity>
        </application>

    </manifest>

1 Answers1

0

Your Android Manifest is fine for getting permissions. However, if you are trying this on Android 6.0, the app will fail because the Permission System in Android Marshmallow is different. SEND_SMS is classified as "Dangerous" permission, so you need to use checkSelfPermission() and requestPermissions() in Marshmallow. Like this -

//This code will fail on devices below Android 6.0, so the below if statement is neccessary
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED) {
        ContextCompat.requestPermissions(thisActivity,
            new String[]{Manifest.permission.SEND_SMS});
    }
}
FadedCoder
  • 1,517
  • 1
  • 16
  • 36
  • I tried to implement this code but it says cannot find symbol method requestPermissions(this,String[]) –  Mar 02 '16 at 05:55