Send sms permission doesn't work

前端 未结 7 462
南方客
南方客 2021-01-14 07:37

I want to send a simple message and i have in my manifest, but I always get: java.la

相关标签:
7条回答
  • 2021-01-14 08:05

    You may try this way:

    private void sendSms(String phoneNumber, String message) {
       Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) ); 
       intent.putExtra( "sms_body", message ); 
       startActivity(intent);
    }
    
    0 讨论(0)
  • 2021-01-14 08:07

    All you need to do is,

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

    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.

    0 讨论(0)
  • 2021-01-14 08:10

    i had same problem you need to get runtime permission on setting>app>"your app" >enable sms permission

    0 讨论(0)
  • 2021-01-14 08:11

    That should work

    PackageManager pm = this.getPackageManager();
    
     if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
         System.out.println("Supported");
     } else {
         System.out.println("nope");
     }
    
    0 讨论(0)
  • 2021-01-14 08:11

    If you message is too long using smsManager.sendTextMessage(.. will fail quietly.

    You need to use smsManager.sendMultipartTextMessage(...

    SmsManager smsManager = SmsManager.getDefault();
    ArrayList<String> messageList = smsManager.divideMessage(message.toString());
    smsManager.sendMultipartTextMessage(phoneNumber, null, messageList, null, null);
    
    0 讨论(0)
  • 2021-01-14 08:16

    I tried this in Huawei Android 8, besides adding permission READ_PHONE_STATE in manifest, the phone needs to allow to "access phone ID" to the app. Then it works.

    0 讨论(0)
提交回复
热议问题