- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从我的内置默认消息应用程序发送消息,但我不知道如何使用 dart 代码 [flutter]
最佳答案
实际上,要以编程方式发送 SMS,您需要实现平台 channel 并使用 SMSManager 发送 SMS。
例子:
安卓部分:
首先在AndroidManifest.xml中添加适当的权限。
<uses-permission android:name="android.permission.SEND_SMS" />
然后在你的 MainActivity.java
中:
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")),
),
);
}
}
关于android - flutter : How we can use inbuilt message app for send message using package?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49419843/
我在其他帖子中看到了如何使用“ it contains my result DataRow[] foutput = table.Select("YEARWEEK(Date) = 'YEARWEE
我在很多地方都查找过struts2中的拦截器。所有很棒的教程和链接都解释了拦截器的含义及其工作原理。 但据我了解,拦截器的真正威力在于理解 struts2-core 库中内置拦截器的作用。 作为一个例
在使用Swift内置的字符串hashValue生成哈希值时,我们发现了两个不同的字符串生成相同哈希值的情况……但是碰撞的原因非常扑朔迷离…… 取这两个字符串: var str1 = """ 00000
我正在使用 Java 读取和写入 SQLite3 数据库。我正在使用 SQLiteJDBC Java 驱动程序与数据库交互。 SQLiteJDBC Java JDBC 驱动程序中是否内置了任何哈希函数
我刚刚了解了 Symbol Animation由 Google API 提供。 在我的代码中一切正常,但我只想知道我是否可以在下面的代码中传递图像而不是符号。 var lineSymbol = {
我想从我的内置默认消息应用程序发送消息,但我不知道如何使用 dart 代码 [flutter] 最佳答案 实际上,要以编程方式发送 SMS,您需要实现平台 channel 并使用 SMSManager
这是适用于 Protractor 的所有 npm 包的一般问题。 一个例子是linkuisref-locator包: Home 要选择上面的元素,有两种方法: 1) by.css() 或 by.xp
我知道这可以通过.Containes()方法来完成。在一次采访中,我被问到如何在没有CONTAINS方法的情况下做到这一点。
我是一名优秀的程序员,十分优秀!