can Send Sms - Android Phone

Android examples for Phone:SMS

Description

can Send Sms

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.provider.Telephony;

import android.telephony.TelephonyManager;

public class Main {
    public static boolean canSendSms(Context context) {
        if (!canPerformCall(context))
            return false;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            String defaultSmsPackageName = Telephony.Sms
                    .getDefaultSmsPackage(context);
            return defaultSmsPackageName != null;
        } else {//from   www  . jav  a  2  s .  c o m
            return true;
        }
    }

    public static boolean canPerformCall(Context context) {
        boolean canPerformCall = context.getPackageManager()
                .hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
        if (!canPerformCall)
            return false;

        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        return TelephonyManager.SIM_STATE_READY == tm.getSimState()
                && (TelephonyManager.PHONE_TYPE_NONE != tm.getPhoneType());
    }
}

Related Tutorials