项目作者: pichillilorenzo

项目描述 :
A Flutter plugin that allows you to check if an app is installed/enabled, launch an app and get the list of installed apps.
高级语言: Dart
项目地址: git://github.com/pichillilorenzo/flutter_appavailability.git
创建时间: 2018-09-12T11:05:40Z
项目社区:https://github.com/pichillilorenzo/flutter_appavailability

开源协议:MIT License

下载


Flutter AppAvailability Plugin

Pub

A Flutter plugin that allows you to check if an app is installed/enabled, launch an app and get the list of installed apps.

This plugin was inspired by the plugin AppAvailability for Cordova.

Getting Started

For help getting started with Flutter, view our online
documentation.

For help on editing plugin code, view the documentation.

Installation

First, add flutter_appavailability as a dependency in your pubspec.yaml file.

Methods available

  • checkAvailability(String uri)
  • getInstalledApps() (only for Android)
  • isAppEnabled(String uri) (only for Android)
  • launchApp(String uri)

See the docs.

Example

Here is a small example flutter app displaying a list of installed apps that you can launch.

  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'dart:io';
  4. import 'package:flutter_appavailability/flutter_appavailability.dart';
  5. void main() => runApp(new MyApp());
  6. class MyApp extends StatefulWidget {
  7. @override
  8. _MyAppState createState() => new _MyAppState();
  9. }
  10. class _MyAppState extends State<MyApp> {
  11. List<Map<String, String>> installedApps;
  12. List<Map<String, String>> iOSApps = [
  13. {
  14. "app_name": "Calendar",
  15. "package_name": "calshow://"
  16. },
  17. {
  18. "app_name": "Facebook",
  19. "package_name": "fb://"
  20. },
  21. {
  22. "app_name": "Whatsapp",
  23. "package_name": "whatsapp://"
  24. }
  25. ];
  26. @override
  27. void initState() {
  28. super.initState();
  29. }
  30. // Platform messages are asynchronous, so we initialize in an async method.
  31. Future<void> getApps() async {
  32. List<Map<String, String>> _installedApps;
  33. if (Platform.isAndroid) {
  34. _installedApps = await AppAvailability.getInstalledApps();
  35. print(await AppAvailability.checkAvailability("com.android.chrome"));
  36. // Returns: Map<String, String>{app_name: Chrome, package_name: com.android.chrome, versionCode: null, version_name: 55.0.2883.91}
  37. print(await AppAvailability.isAppEnabled("com.android.chrome"));
  38. // Returns: true
  39. }
  40. else if (Platform.isIOS) {
  41. // iOS doesn't allow to get installed apps.
  42. _installedApps = iOSApps;
  43. print(await AppAvailability.checkAvailability("calshow://"));
  44. // Returns: Map<String, String>{app_name: , package_name: calshow://, versionCode: , version_name: }
  45. }
  46. setState(() {
  47. installedApps = _installedApps;
  48. });
  49. }
  50. @override
  51. Widget build(BuildContext context) {
  52. if (installedApps == null)
  53. getApps();
  54. return MaterialApp(
  55. home: Scaffold(
  56. appBar: AppBar(
  57. title: const Text('Plugin flutter_appavailability app'),
  58. ),
  59. body: ListView.builder(
  60. itemCount: installedApps == null ? 0 : installedApps.length,
  61. itemBuilder: (context, index) {
  62. return ListTile(
  63. title: Text(installedApps[index]["app_name"]),
  64. trailing: IconButton(
  65. icon: const Icon(Icons.open_in_new),
  66. onPressed: () {
  67. Scaffold.of(context).hideCurrentSnackBar();
  68. AppAvailability.launchApp(installedApps[index]["package_name"]).then((_) {
  69. print("App ${installedApps[index]["app_name"]} launched!");
  70. }).catchError((err) {
  71. Scaffold.of(context).showSnackBar(SnackBar(
  72. content: Text("App ${installedApps[index]["app_name"]} not found!")
  73. ));
  74. print(err);
  75. });
  76. }
  77. ),
  78. );
  79. },
  80. ),
  81. ),
  82. );
  83. }
  84. }

Android:
screenshot_1536780581

iOS:
simulator screen shot - iphone x - 2018-09-12 at 21 27 05