【问题标题】:how to call android activity from dart file in flutter如何在flutter中从dart文件中调用android活动
【发布时间】:2019-05-12 03:09:54
【问题描述】:

谁能告诉我如何在颤振中从 dart 文件中调用 android 活动。 谢谢。

代码:

class FlutterScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Screen'),
      ),
      body: Center(
        child: RaisedButton(
          child: Text('Android'),
          onPressed: () {
            // Navigate to Android activity screen when tapped!
          },
        ),
      ),
    );
  }
}

【问题讨论】:

    标签: android dart flutter


    【解决方案1】:

    我认为您正在寻找的是android_intent library

    有了它,很容易触发一个意图。尽管不支持 iOS,但您必须确保不要在 iOS 上以相同的方式使用它。

    来自 android_intent 自述文件的示例代码:

    if (platform.isAndroid) {
      AndroidIntent intent = new AndroidIntent(
          action: 'action_view',
          data: 'https://play.google.com/store/apps/details?'
              'id=com.google.android.apps.myapp',
          arguments: {'authAccount': currentUserEmail},
      );
      await intent.launch();
    }
    

    【讨论】:

    • 这里我想在 android 平台上编写一些本机代码,以便通过蓝牙从 dart 文件中打印。所以我需要从颤振转移到原生 android
    • 如果这就是您真正要问的,那么这个问题与stackoverflow.com/questions/49099408/… 重复。您还可以通过flutter.io/docs/development/platform-integration/… 查看文档
    • 好的。我试过这个。导入 io.flutter.plugin.common.MethodChannel 显示错误。进口不走。扩展 FlutterActivity 也没有显示 :(
    • @kartheekij 你应该为这些问题创建另一个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    • 2021-04-02
    • 1970-01-01
    • 2019-11-21
    相关资源
    最近更新 更多