zoukankan      html  css  js  c++  java
  • Flutter中的打电话、发短信、调起外部浏览器、打开外部APP

    我们通过url_launcher来实现调起电话、短信、外部浏览器、外部APP的功能。

    pubspec:

      url_launcher: ^5.0.3
      get_it: ^1.0.3+2
    import 'package:flutter/material.dart';
    import 'package:url_launcher/url_launcher.dart';
    
    class SuccessScreen extends StatefulWidget {
      @override
      _SuccessScreenState createState() => _SuccessScreenState();
    }
    
    class _SuccessScreenState extends State<SuccessScreen> {
      //拨打电话
      _call() async {
        const url = 'tel:10086';
        if (await canLaunch(url)) {
          await launch(url);
        } else {
          throw 'Could not launch $url';
        }
      }
    
      //发送短信
      _message() async {
        const url = 'sms:133224455';
        if (await canLaunch(url)) {
          await launch(url);
        } else {
          throw 'Could not launch $url';
        }
      }
    
      //打开外部浏览器
      _openBrower() async {
        const url = 'https://flutter.dev';
        if (await canLaunch(url)) {
          await launch(url);
        } else {
          throw 'Could not launch $url';
        }
      }
    
      //打开外部应运用
      _openOtherApp() async {
        /**
         * weixin://
         * alipays://
         */
        const url = 'alipays://';
        if (await canLaunch(url)) {
          await launch(url);
        } else {
          throw 'Could not launch $url';
        }
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: Text("url_launchDemo")),
          body: Column(
            children: <Widget>[
              RaisedButton(
                onPressed: () {
                  _call();
                },
                child: Text("拨打电话"),
              ),
              SizedBox(height: 10),
              RaisedButton(
                onPressed: () {
                  _message();
                },
                child: Text("发送短信"),
              ),
              SizedBox(height: 10),
              RaisedButton(
                onPressed: () {
                  _openBrower();
                },
                child: Text("打开外部浏览器"),
              ),
              SizedBox(height: 10),
              RaisedButton(
                onPressed: () {
                  _openOtherApp();
                },
                child: Text("打开外部应用"),
              ),
            ],
          ),
        );
      }
    }

    另外一个封装好的,但是没跑起来

    https://segmentfault.com/a/1190000019691815

  • 相关阅读:
    数据库表设计
    solr的schame.xml
    搭建solr服务器
    lucene&solr索引维护之查询
    lucene&solr索引维护之删除和修改
    lucene&solr查询索引实例
    lucene&solr入门实例
    java集合排序整理
    HahMap(jdk=1.8)源码解读
    APIO2020 游记
  • 原文地址:https://www.cnblogs.com/ssjf/p/12105951.html
Copyright © 2011-2022 走看看