机器人:如何打开从我的应用程序另一个应用程序?应用程序、我的、机器人

2023-09-11 12:46:38 作者:自作多情死于非命

我知道如何使用意图和startActivity()开在我自己的应用程序,另一个活动时,但你如何启动不同的应用程序?具体做法是:

I understand how to use intents and startActivity() when opening another activity within my own app, but how do you start a different app? specifically:

如何确定用户是否已经安装在他们的设备上的应用程序所需? 如何启动该应用程序? 如何将参数传递给该应用程序? 你怎么找到这一切信息了特定的应用程序(比如Adobe Reader,请或谷歌地图)?

推荐答案

如何看是否原意是可用的:

尝试调用意图和处理 ActivityNotFoundException 如果不使用

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


try {
    startActivity(intent);
} 
catch (ActivityNotFoundException e) {
    Toast.makeText(OpenPdf.this, 
        "No Application Available to View PDF", 
        Toast.LENGTH_SHORT).show();
}

查询软件包管理器来看看如果是提前:

PackageManager packageManager = getPackageManager();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("application/pdf");


List list = packageManager.queryIntentActivities(intent,
    PackageManager.MATCH_DEFAULT_ONLY);


if (list.size() > 0) {
    intent.setDataAndType(path, "application/pdf");
    startActivity(intent);
}

如何传递参数给应用程序或知道它的功能:

可用意图的谷歌应用程序 列表 意图的 名单由第三方@ OpenIntents软件 List of Available Intents for Google Applications List of Intents by 3rd parties @ OpenIntents
 
精彩推荐
图片推荐