安卓 设置默认短信应用(两种实现)

1、无弹框(利用反射)

 public static final String CLASS_SMS_MANAGER = "com.android.internal.telephony.SmsApplication";

    public static final String METHOD_SET_DEFAULT = "setDefaultApplication";

    private void setDefaultSms(Boolean isMyApp) {
        try {
            Class smsClass = Class.forName(CLASS_SMS_MANAGER);
            Method method = smsClass.getMethod(METHOD_SET_DEFAULT, String.class, Context.class);
            method.invoke(null, "要设置的包名", this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

 

2、有弹窗

 Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
 intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, "要设置的包名");
 startActivity(intent);

 

你可能感兴趣的:(安卓干货)