我想知道在Android中是否可以使用QR Code阅读器启动应用程序。我想要实现的目标是:
我创建QR码,用QR码阅读器扫描后,我需要用一些参数启动我的应用程序,也许它看起来像这样:myApp://org.hardartcore.myApp?myParams或类似的东西,不是真的当然。
无论如何要实现这一点,并获得在qr代码中构建的param以启动应用程序。
我想知道在Android中是否可以使用QR Code阅读器启动应用程序。我想要实现的目标是:
我创建QR码,用QR码阅读器扫描后,我需要用一些参数启动我的应用程序,也许它看起来像这样:myApp://org.hardartcore.myApp?myParams或类似的东西,不是真的当然。
无论如何要实现这一点,并获得在qr代码中构建的param以启动应用程序。
使用此文本创建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"/>
这应该工作。
是。在 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
在 斑马线 以此为例进行说明。
是可以通过使用意图。
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();
}
}
}
使用此文本创建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"/>
这应该工作。
是。在 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
在 斑马线 以此为例进行说明。
是可以通过使用意图。
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();
}
}
}