Just create a method channel
class MainActivity : FlutterActivity() {
private val CHANNEL = "com.example.chat/chat"
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
if (call.method == "setDefaultSms") {
try {
var intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(
Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
<the app package name>
);
startActivity(intent);
result.success("Success")
} catch (ex: Exception) {
result.error("UNAVAILABLE", "Setting default sms.", null)
}
} else {
result.notImplemented()
}
}
}
}
after that in your dart code call the method channel
static const platform = const MethodChannel("com.example.chat/chat");
try {
final result = await platform.invokeMethod('setDefaultSms');
print("Result: $result");
} on PlatformException catch (e) {
print("Error: $e");
}
}
Note the above solution won't make your app qualify to a default SMS app
You may need to add something to your manifest file for more info check out this post Check this out