2010-10-13 189 views
22

我有一个应用程序在电话上注册自定义URI的处理程序。我可以通过从手机网页链接到“myapp:// act/launch”来启动应用程序。这仅在我的应用程序安装在设备上时有效。 我想要做的就是检测浏览器是否支持URI方案,然后提示我自己的消息说:“请下载应用程序等...”,如果没有找到URI方案的处理程序。检测应用程序是否安装?

有没有一种方法可以从Web浏览器中检测或查找手机上URL计划处理程序的列表?

+0

可能的复制(http://stackoverflow.com/questions/18752202/check-if-application-is-installed-android ) – 2016-01-12 13:48:45

回答

61

Android How-to's

如果你需要知道,如果是安装在用户的设备上的特定应用程序,你可以使用PackageManager。从Context类(例如Activity或Service)中,您可以调用getPackageManager()。这为您提供了多种方法,其中之一是getPackageInfo()。以下是您可能使用的一种方法。你可以这样调用它:

isAppInstalled("com.simexusa.campusmaps_full"); 

private boolean isAppInstalled(String packageName) { 
    PackageManager pm = getPackageManager(); 
    boolean installed = false; 
    try { 
     pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); 
     installed = true; 
    } catch (PackageManager.NameNotFoundException e) { 
     installed = false; 
    } 
    return installed; 
} 
+13

他特别要求通过网络浏览器完成。 – 2012-04-19 15:31:42

+3

无论如何:“uri”是该方法的正确参数名称吗? packageName会更好吗? – 2012-08-03 11:51:55

+0

@GlennBech:是的,_packageName_比_uri_更具描述性 – 2012-08-13 07:38:52

14
  1. 您需要创建一个网页上,如果应用程序是不是 用户安装的土地。说http://www.yourcompany.com/android/android_app_is_not_installed_landing_page.html

  2. 的应用程序需要在清单XML文件中主机www.yourcompany.com注册, 模式“http”和路径参数去应用未安装的着陆页, 清单意图过滤器:

    <!-- These intents are used to launch the app from the web page--> 
    <intent-filter> 
        <action android:name="android.intent.action.VIEW" /> 
        <category android:name="android.intent.category.DEFAULT" /> 
        <category android:name="android.intent.category.BROWSABLE" /> 
        <data android:scheme="http" 
         android:host="www.yourcompany.com" 
         android:path="/android/android_app_is_not_installed_landing_page.html" 
        /> 
    </intent-filter> 
    
  3. 在网页中调用您的应用程序指定完整链接 android_app_is_not_installed_landing_page.html其次是无论 PARAMS要传递给应用

    现在:

http://www.yourcompany.com/android/ android_app_is_not_installed_landing_page.html? '>点击此处启动 应用程序是,如果安装

如果安装应用程序将启动,并通过整个 http://www.yourcompany.com/android/android_app_is_not_installed_landing_page.html? 意图它需要解析,提​​取 并做任何它 应该做。

如果未安装该应用程序,然后在Android网页浏览器将打开 “Android应用程序未安装”着陆页 http://www.yourcompany.com/android/android_app_is_not_installed_landing_page.htmlØ 。该页面应该向用户发送消息以安装该应用并提供 链接以从Android Marketplace进行安装。

发现这个写在这里了:的[检查是否安装了应用程序 - Android电子] https://groups.google.com/forum/m/?fromgroups#!topic/android-developers/RGLHkGUpRoA

+2

那么,为什么驱动器downvote,因为它实际上回答他问的问题? – boatcoder 2013-11-19 21:05:16

相关问题