【问题标题】:How to launch my Android app from a QR reader?如何从 QR 阅读器启动我的 Android 应用程序?
【发布时间】:2013-04-22 17:32:21
【问题描述】:

我尝试搜索类似的问题,但没有一个关于这个主题的问题非常清楚。

所以,我有一个应用程序,我想使用 QR 码阅读器来启动它。例如,如果我拍摄 QR 码的照片,QR 阅读器会将其翻译成网址并以该地址作为参数启动我的应用程序。我该怎么做呢?我无法访问 QR 阅读器,因为它可以是商店中的任何应用程序。如何让我的应用出现在处理参数的可用程序列表中?

【问题讨论】:

    标签: android parameters launch


    【解决方案1】:

    如何从 QR 阅读器启动我的 Android 应用程序?

    你确实没有。您允许基于特定的Intent 结构启动您的 Android 应用,其中一个或多个结构可能会被二维码阅读器使用。

    例如,如果我拍摄 QR 码的照片,QR 阅读器会将其翻译成网址并使用该地址作为参数启动我的应用程序。我该怎么做呢?

    在您的 <activity> 上有一个 <intent-filter>,表示它处理该 URL,例如:

            <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:host="www.this-so-does-not-exist.com"
                    android:path="/something"
                    android:scheme="http"/>
            </intent-filter>
    

    &lt;intent-filter&gt; 将匹配 URL http://www.this-so-does-not-exist.com/something。更改 &lt;data&gt; 元素将更改您匹配的 URL。

    【讨论】:

      【解决方案2】:

      或者你可以像这样设置自己的方案。

          <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:host="something"
                  android:scheme="myapp"/>
          </intent-filter>
      

      如果您输入“myapp://someting/string to send to app”,您的应用将启动,您将使用以下代码获得最后一部分

      getIntent().getData().getLastPathSegment()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-27
        • 2016-06-13
        • 2012-01-26
        相关资源
        最近更新 更多