我试图找到一种解决方案,只需通过短信发送加号(+)。目前,我使用URL_launcher发送短信,但是加号可以像某些智能手机中的空格一样解释...即使我将\%2B转换为加号
我尝试使用“ flutter_sms 0.0.5”,但是星系电话存在问题...
插件“ sms 0.2.4”与具有短信许可的Google新隐私政策不兼容...
最后一个解决方案,让我如何与平台通道,本机android sms桥接,但我不知道如何
我在平台频道中找到了此代码,但它使用了短信权限 ” Android部分:
首先向AndroidManifest.xml添加适当的权限。
<uses-permission android:name="android.permission.SEND_SMS" />
然后在您的MainActivity.java中:
package com.yourcompany.example;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "sendSms";
private MethodChannel.Result callResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if(call.method.equals("send")){
String num = call.argument("phone");
String msg = call.argument("msg");
sendSMS(num,msg,result);
}else{
result.notImplemented();
}
}
});
}
private void sendSMS(String phoneNo, String msg,MethodChannel.Result result) {
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, msg, null, null);
result.success("SMS Sent");
} catch (Exception ex) {
ex.printStackTrace();
result.error("Err","Sms Not Sent","");
}
}
}
Dart代码:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/services.dart';
void main() {
runApp(new MaterialApp(
title: "Rotation Demo",
home: new SendSms(),
));
}
class SendSms extends StatefulWidget {
@override
_SendSmsState createState() => new _SendSmsState();
}
class _SendSmsState extends State<SendSms> {
static const platform = const MethodChannel('sendSms');
Future<Null> sendSms()async {
print("SendSMS");
try {
final String result = await platform.invokeMethod('send',<String,dynamic>{"phone":"+91XXXXXXXXXX","msg":"Hello! I'm sent programatically."}); //Replace a 'X' with 10 digit phone number
print(result);
} on PlatformException catch (e) {
print(e.toString());
}
}
@override
Widget build(BuildContext context) {
return new Material(
child: new Container(
alignment: Alignment.center,
child: new FlatButton(onPressed: () => sendSms(), child: const Text("Send SMS")),
),
);
}
}
”
现在,谷歌隐私权政策删除了使用短信权限的应用,因此,如果有人知道如何修改此平台来启动短信本机应用,请使用编写配方,编写正文短信,但让用户手动发送短信。这是唯一的解决方案。