QR Code讀取

QR-Droid 提供三種功能供外部 App 整合使用,包括:

1. Scan: 開啟 QRDroid 的掃描功能。

2. Encode: 產生 QR-Code,回傳為Local Storage 路徑 或 remote QRCode Image URL。

3. Decode: 輸入一 QR-Code 的圖片URL, 解析出內容。

1. 開啟 QR-Droid Scan Activity

Intent i = new Intent("la.droid.qr.scan"); //使用QRDroid的掃描功能

i.putExtra( "la.droid.qr.complete" , true); //完整回傳,不截掉scheme

try {

//開啟 QRDroid App 的掃描功能,等待 call back onActivityResult()

startActivityForResult(i, 0);

} catch(ActivityNotFoundException ex) {

//若沒安裝 QRDroid,則開啟 Google Play商店,並顯示 QRDroid App

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=la.droid.qr"));

startActivity(intent);

}

2. 實作 onActivityResult,QR-Droid 掃描結果會 call back onActivityResult 方法

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if( 0==requestCode && null!=data && data.getExtras()!=null ) {

//掃描結果存放在 key 為 la.droid.qr.result 的值中

String result = data.getExtras().getString("la.droid.qr.result");

mScanResult.setText(result); //將結果顯示在 TextVeiw 中

}

}

資料來源:http://elviselle.blogspot.tw/2013/06/android-app-qr-code.html