Android如何将第三方信息应用设置为默认信息应用?

1.利用反射(无弹框)

```java
public static final String CLASS_SMS_MANAGER = "com.android.internal.telephony.SmsApplication";
public static final String METHOD_SET_DEFAULT = "setDefaultApplication";
private void setDefaultSmsApplication(String packageName) {
    Log.d(TAG, "setDefaultApplication: " + packageName);
    try {
        Class smsClass = Class.forName(CLASS_SMS_MANAGER);
        Method method = smsClass.getMethod(METHOD_SET_DEFAULT, String.class, Context.class);
        method.invoke(null, packageName, this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
```

2.有弹框的方式

```java
private void setDefaultSmsApplication() {
    String packageName = getPackageName();
    if (!Telephony.Sms.getDefaultSmsPackage(this).equals(packageName)) {
        Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
        intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName);
        startActivity(intent);
    }
}
```

参考博客:

https://blog.csdn.net/qq_33829413/article/details/81354728

你可能感兴趣的:(Android基础,android,反射)