Dart 有人能告诉我如何使用flutter打开另一个应用程序吗?
我想使用firebase中的链接数据打开一组音乐应用程序链接。我想公开,亚马逊音乐,Ganna,Spotify,Wynk,Jiosavan等等Dart 有人能告诉我如何使用flutter打开另一个应用程序吗?,dart,flutter,explicit-intent,Dart,Flutter,Explicit Intent,我想使用firebase中的链接数据打开一组音乐应用程序链接。我想公开,亚马逊音乐,Ganna,Spotify,Wynk,Jiosavan等等 Widget buildResultCard(data) { List items = [Text(data['Ganna']), IconButton(icon:Icon(Icons.all_inclusive), onPressed: ()=> {Text("Ganna")} ), Text(data[
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];
},
);
}
当我点击列表中的按钮时,它应该打开链接所在的特定应用程序,例如AmazonPrimeMusic链接,它应该打开Amazon音乐应用程序。您可以使用软件包。此插件允许您检查手机中是否安装了应用程序,并使用此插件可以启动应用程序
如果已经安装,则使用启动WebView中的打开链接 将其添加到依赖项下的pubspec.yaml文件中-
device_apps:
android_intent:
url_launcher:
并将这些添加到顶部-
import 'package:device_apps/device_apps.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:android_intent/android_intent.dart';
这是示例代码-
_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';
}
}
要在Flatter中实现此功能,请创建本机平台集成,或使用现有插件,如
external_app_launcher
flatter插件可帮助您从应用程序中打开另一个应用程序
dependencies:
external_app_launcher: ^0.0.1 // add letest version
import 'package:external_app_launcher/external_app_launcher.dart';
- 用于在android中打开应用程序
要在android中从应用程序打开外部应用程序,您需要提供应用程序的packageName
如果pluggin在设备中找到应用程序,则会打开该应用程序,但如果该应用程序未安装在设备中,则会允许用户链接到应用程序的playstore
但如果您不想在未安装应用程序的情况下导航到playstore,请将
属性设置为openStore
false
- 用于在ios中打开应用程序
在Ios中,要从应用程序打开外部应用程序,需要提供目标应用程序的URL方案
在部署中,目标值大于或等于9,则还需要更新infoPlist中的外部应用程序信息
<key>LSApplicationQueriesSchemes</key> <array> <string>pulsesecure</string> // url scheme name of the app </array>
LSApplicationQueriesSchemes
import 'package:flutter/material.dart';
import 'package:external_app_launcher/external_app_launcher. dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
Color containerColor = Colors.red;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Container(
height: 50,
width: 150,
child: RaisedButton(
color: Colors.blue,
onPressed: () async {
await LaunchApp.openApp(
androidPackageName: 'net.pulsesecure. pulsesecure',
iosUrlScheme: 'pulsesecure://',
appStoreLink:
'itms-apps://itunes.apple.com/us/ app/pulse-secure/id945832041',
// openStore: false
);
// Enter thr package name of the App you want to open and for iOS add the URLscheme to the Info.plist file.
// The second arguments decide wether the app redirects PlayStore or AppStore.
// For testing purpose you can enter com. instagram.android
},
child: Container(
child: Center(
child: Text(
"Open",
textAlign: TextAlign.center,
),
))),
),
),
),
);
}
}
导入“包装:颤振/材料.省道”;
“导入”包:外部应用程序启动器/外部应用程序启动器。省道';
void main(){
runApp(MyApp());
}
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>\u MyAppState();
}
类MyAppState扩展了状态{
@凌驾
void initState(){
super.initState();
}
颜色容器颜色=Colors.red;
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
appBar:appBar(
标题:const Text(“插件示例应用程序”),
),
正文:中(
子:容器(
身高:50,
宽度:150,
孩子:升起按钮(
颜色:颜色,蓝色,
onPressed:()异步{
等待LaunchApp.openApp(
androidPackageName:'net.pulsesecure.pulsesecure',
iosUrlScheme:'脉冲安全:/',
appStoreLink:
“itms-apps://itunes.apple.com/us/ app/pulse secure/id945832041',
//openStore:错误
);
//输入要打开的应用程序的软件包名称,对于iOS,将URLSHEMA添加到Info.plist文件中。
//第二个参数决定应用程序是重定向PlayStore还是重定向AppStore。
//出于测试目的,您可以输入com.instagram.android
},
子:容器(
儿童:中心(
子:文本(
“开放”,
textAlign:textAlign.center,
),
))),
),
),
),
);
}
}
谢谢,但我想打开特定的音乐应用程序,而不是在浏览器中打开web。我可以使用设备应用程序启动音乐应用程序,但我也想在应用程序中搜索该链接。如果您能提供帮助,我将非常高兴。\u openGanna()async{bool isInstalled=wait DeviceApps.isAppInstalled('com.jio.media.jiobeats');if(bool!=false)DeviceApps.openApp('com.ganna');else Text(“Cannot open app”);}
您也可以使用flatter\u appavailability启动特定的应用程序,但您使用的是特定应用程序的包名,而不是链接。在我的建议中,如果用户设备中未安装应用程序open playstore或AppStore应用程序链接我想打开应用程序并搜索特定链接,打开应用程序是不够的。我们可以使用flatter吗?搜索可能比您的答案更新的特定链接是什么意思,但是DeviceApps
有一个DeviceApps.openApp
,所以不需要使用Androident
DeviceApps包,它不适用于ios,还有其他针对ios玩家的解决方案吗?它不支持ios.iosUrlScheme:'pulsesecure://',-它可以工作,但如果我传递诸如iosUrlScheme:'pu'之类的参数lsesecure://abc.com?arg=123' . 它不起作用。你知道为什么吗@Paresh Mangukiya未在IOS中测试它是否也在IOS中工作?这可以打开具有特定url的应用程序吗?例如,如果我有一个youtube链接,它会用该链接打开youtube应用程序吗?