Checks if the device can send SMS messages - Android android.telephony

Android examples for android.telephony:SmsManager

Description

Checks if the device can send SMS messages

Demo Code

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.util.Log;
import java.util.List;

public class Main{

    /** Checks if the device can send SMS messages.
     */*from ww w .j a  va  2 s . co  m*/
     * @param context Context for obtaining the package manager.
     * @return true if you can send SMS, false otherwise.
     */
    public static boolean canSendSms(Context context) {
        Uri smsUri = Uri.parse("smsto:12345");
        Intent smsIntent = new Intent(Intent.ACTION_SENDTO, smsUri);
        PackageManager smspackageManager = context.getPackageManager();
        List<ResolveInfo> smsresolveInfos = smspackageManager
                .queryIntentActivities(smsIntent, 0);
        if (smsresolveInfos.size() > 0) {
            return true;
        } else {
            return false;
        }
    }

}

Related Tutorials