I want to send a simple message and i have
in my manifest, but I always get: java.la
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);
}
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.
i had same problem you need to get runtime permission on setting>app>"your app" >enable sms permission
That should work
PackageManager pm = this.getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
System.out.println("Supported");
} else {
System.out.println("nope");
}
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);
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.