问题 Android启动应用程序从QR码与params


我想知道在Android中是否可以使用QR Code阅读器启动应用程序。我想要实现的目标是:

我创建QR码,用QR码阅读器扫描后,我需要用一些参数启动我的应用程序,也许它看起来像这样:myApp://org.hardartcore.myApp?myParams或类似的东西,不是真的当然。

无论如何要实现这一点,并获得在qr代码中构建的param以启动应用程序。


8746
2018-04-21 11:51


起源



答案:


使用此文本创建QR CODE: myApp://extraString 并使用任何qr代码阅读器阅读。甚至你可以使用自己的qr代码阅读器集成 Zxing的开源。你可以得到 extraString 正如@Sean Owen所提到的那样 getIntent().getDataString()。并且不要忘记在清单文件中添加它:

<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="myApp"/>

这应该工作。


10
2018-05-08 07:38





是。在 AndroidManifest.xml, 在你的 <activity>,声明应用响应此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:scheme="myApp" android:host="org.hardartcore.myApp" android:path="/"/>
  </intent-filter>

(我认为你可能不得不在“?”之前以“/”结尾,以便工作。)

然后,使用该平台解析URL的任何内容都将打开您的应用。 Web浏览器中的超链接将起作用。

可以使用以下方式检索URL本身 getIntent().getDataString()。你可以把它解析为 android.net.Uri 随你便。

看着 CaptureActivity 在 斑马线 以此为例进行说明。


3
2018-04-21 12:36





是可以通过使用意图。

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);

public void onActivityResult(int requestCode, int resultCode, Intent intent) 
{
if (requestCode == 0) 
{
if (resultCode == RESULT_OK) 
     {
              final String contents = intent.getStringExtra("SCAN_RESULT");
        Toast.makeText(this, contents, Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED) 
        {
    Toast.makeText(this, "Not proper QRCODE...!",Toast.LENGTH_SHORT).show();
    }
}
}

-1
2018-04-21 12:26



这让应用程序启动条形码扫描仪。 OP正在询问条码扫描器如何使用QR码启动应用程序。 - Sean Owen


答案:


使用此文本创建QR CODE: myApp://extraString 并使用任何qr代码阅读器阅读。甚至你可以使用自己的qr代码阅读器集成 Zxing的开源。你可以得到 extraString 正如@Sean Owen所提到的那样 getIntent().getDataString()。并且不要忘记在清单文件中添加它:

<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="myApp"/>

这应该工作。


10
2018-05-08 07:38





是。在 AndroidManifest.xml, 在你的 <activity>,声明应用响应此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:scheme="myApp" android:host="org.hardartcore.myApp" android:path="/"/>
  </intent-filter>

(我认为你可能不得不在“?”之前以“/”结尾,以便工作。)

然后,使用该平台解析URL的任何内容都将打开您的应用。 Web浏览器中的超链接将起作用。

可以使用以下方式检索URL本身 getIntent().getDataString()。你可以把它解析为 android.net.Uri 随你便。

看着 CaptureActivity 在 斑马线 以此为例进行说明。


3
2018-04-21 12:36





是可以通过使用意图。

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);

public void onActivityResult(int requestCode, int resultCode, Intent intent) 
{
if (requestCode == 0) 
{
if (resultCode == RESULT_OK) 
     {
              final String contents = intent.getStringExtra("SCAN_RESULT");
        Toast.makeText(this, contents, Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED) 
        {
    Toast.makeText(this, "Not proper QRCODE...!",Toast.LENGTH_SHORT).show();
    }
}
}

-1
2018-04-21 12:26



这让应用程序启动条形码扫描仪。 OP正在询问条码扫描器如何使用QR码启动应用程序。 - Sean Owen