19

I want to open a bunch of music app links using links data I have in firebase. I want to open, amazonPrimeMusic, Ganna, Spotify, Wynk, JioSavaan to name some.

Widget buildResultCard(data) {
  List items = [Text(data['Ganna']),
    IconButton(icon:Icon(Icons.all_inclusive),
      onPressed: ()=> {Text("Ganna")}
    ),

    Text(data['Wynk']),
    IconButton(icon:Icon(Icons.all_inclusive),
      onPressed: ()=> {Text("Ganna")}
    ),

    Text(data['JioSavaan']),
    IconButton(icon:Icon(Icons.all_inclusive),
      onPressed: ()=> {Text("Ganna")}
    ),

    Text(data['PrimeMusic']),
    IconButton(icon:Icon(Icons.all_inclusive),
      onPressed: ()=> {Text("Ganna")}
    )
  ];

  return ListView.builder(
    padding: EdgeInsets.only(top: 20),
    itemCount: items.length,
    itemBuilder: (BuildContext context, int index) {
      return items[index];
    },
  );
}

when I tap the button in the list it should open up the particular app for which the link is, for example for AmazonPrimeMusic link, it should open the Amazon music app.

Hasen
  • 11,710
  • 23
  • 77
  • 135
Lokesh Karki
  • 515
  • 1
  • 3
  • 9

7 Answers7

18

add this to the pubspec.yaml file under dependencies-

  device_apps:
  android_intent:
  url_launcher:

and add these to the top -

import 'package:device_apps/device_apps.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:android_intent/android_intent.dart';

and here is the sample code -

_openJioSavaan (data) async
{String dt = data['JioSavaan'] as String;
  bool isInstalled = await DeviceApps.isAppInstalled('com.jio.media.jiobeats');
if (isInstalled != false)
 {
    AndroidIntent intent = AndroidIntent(
      action: 'action_view',
      data: dt
  );
  await intent.launch();
 }
else
  {
  String url = dt;
  if (await canLaunch(url)) 
    await launch(url);
   else 
    throw 'Could not launch $url';
}
}
Lokesh Karki
  • 515
  • 1
  • 3
  • 9
  • 2
    Probably newer than your answer, but `DeviceApps` has a `DeviceApps.openApp`, so no need to use `AndroidIntent` – Jan Jul 30 '20 at 20:08
  • 1
    DeviceApps package not working for ios,any other soltution for ios guys? – Zeeshan Ansari Sep 15 '20 at 13:38
  • 7
    it does not support iOS. – Mr Special Feb 20 '21 at 09:05
  • `device_apps` doesn't support iOS because it is more complicated. You cannot just launch arbitrary apps on iOS. The app-to-be-opened must register for a URL Scheme, or support a Universal link which you try to open from your own app. – Ben Butterworth Sep 17 '21 at 12:42
8

You can use flutter_appavailability package. This plugin allows you to check if an app is installed in mobile and using this plugin you can launch an app.

If already installed then launch otherwise open link in WebView using url_launcher.

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65
  • 1
    Thanks, but I want to open the specific music app, instead of opening web in a browser. I was able to launch the music app using **device_apps** but I want to search the app also for that link. I will be glad if you can help. – Lokesh Karki Apr 20 '19 at 11:11
  • 2
    `_openGanna () async {bool isInstalled = await DeviceApps.isAppInstalled('com.jio.media.jiobeats'); if (bool != false) DeviceApps.openApp('com.ganna.'); else Text("Cannot open app"); }` – Lokesh Karki Apr 20 '19 at 11:15
  • 1
    you can launch specific application using flutter_appavailability too, but you've use package name of specific application instead of link. In my suggestion if app not installed in your user device open playstore or AppStore application link – Abhishek Aryan Apr 20 '19 at 11:19
  • I want to open the app and search for that particular link, opening the app is not enough. Can we do that using flutter? – Lokesh Karki Apr 20 '19 at 11:24
  • what do you mean by search for that particular link – Abhishek Aryan Apr 20 '19 at 11:25
  • I want to open a particular music app by clicking on the button(which will open the song link in the music app), and play the song in that music app. – Lokesh Karki Apr 20 '19 at 11:29
  • I don't think so it is possible because, deep linking handled differently by different application. – Abhishek Aryan Apr 20 '19 at 11:31
  • @LokeshKarki did you find the solution for this? – Krishan Madushanka May 29 '21 at 14:20
  • How can I do this in flutter windows app? I want to open a windows app, for example xbox from inside flutter desktop – Benyamin Dec 16 '22 at 12:55
6

Hello you actually need two packages. Check the versions before you use them. First of all you need the id of the app. For example for facebook lite the id is com.facebook.lite. You acn find the id if you go to playstore click share and cope the link. The link for facebook lite is https://play.google.com/store/apps/details?id=com.facebook.lite from this one you can easily understand that the id is after "id=". Its the same on the other apps too.

device_apps: ^2.1.1 url_launcher: ^6.0.3

try {
  ///checks if the app is installed on your mobile device
  bool isInstalled = await DeviceApps.isAppInstalled('si.modula.android.instantheartrate');
  if (isInstalled) {
     DeviceApps.openApp("si.modula.android.instantheartrate");
   } else {
     ///if the app is not installed it lunches google play store so you can install it from there
   launch("market://details?id=" +"si.modula.android.instantheartrate");
   }
} catch (e) {
    print(e);
}

so the code above check if you have already installed the application. If you have done it it will lunch the application if not it is going to open google playstore so you can see it there. It works only for android devices.

3

Updated : url_launcher: ^6.1.4

          void launchAnotherApp() async {
            if (!await launchUrl(Uri.parse("https://www.instagram.com/username/"),
                mode: LaunchMode.externalApplication)) {
              throw 'Could not launch ';
            }
          }

It opens another app on your phone. If targeted app not installed on your device it will open in webview.

Paras Arora
  • 605
  • 6
  • 12
0

I think you can use external_app_launcher: ^3.0.0

https://pub.dev/packages/external_app_launcher

0

You can easily do it with the help of external_app_launcher.

A Flutter plugin that helps you to open another app from your app. The package asks you for four parameters out of which two are mandatory.

Example code:

RaisedButton(
  color: Colors.blue,
  onPressed: ()  {
    LaunchApp.openApp(
      androidPackageName: 'net.pulsesecure.pulsesecure',
      iosUrlScheme: 'pulsesecure://',
      appStoreLink: 'itms-apps://itunes.apple.com/us/app/pulse-secure/id945832041',
    );
    // Enter the package name of the App you want to open and for iOS add the URLscheme to the Info.plist file.
    // The `openStore` argument decides whether the app redirects to PlayStore or AppStore.
    // For testing purpose you can enter com.instagram.android
  },
  child: Container(
    child: Center(
      child: Text("Open",
        textAlign: TextAlign.center,
      ),
    ),
  ),
)
ravipatel0508
  • 358
  • 2
  • 14
0

All you need to do is just install the URL launcher and external app launcher in case your user doesn't have an app installed. So he can be redirected to the play store link.

import 'package:external_app_launcher/external_app_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';

onTap: () async {
            var teamsAppUrl = 'msteams:';
            try {
              await launchUrlString(teamsAppUrl); // Attempt to launch the Teams app
            } catch (e) {
              var openAppResult = await LaunchApp.openApp(
                androidPackageName: 'com.microsoft.teams',
                iosUrlScheme: 'msteams:',
              );/
            }
},
Aman Singh
  • 41
  • 2