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

  • 相关阅读:
    java.lang.RuntimeException: HRegionServer Aborted的问题
    Solr 读数据流程
    Solr 写数据流程
    solr索引创建流程
    Solr 倒排索引
    Solr 核心组成
    Solr的关键特性
    poj3308 Paratroopers --- 最小点权覆盖-&gt;最小割
    YII 路由配置
    MySQL具体解释(5)-----------函数超全总结
  • 原文地址:https://www.cnblogs.com/ssjf/p/12105951.html
Copyright © 2011-2022 走看看