2012-02-21 4 views
0

こんにちは私は完璧に動作するスキャナを得ることができますが、それは完全にデコードしますが、結果を表示するには画像とURLが表示されますが、私はそれを取得するように見えます。そうその簡単な修正が突く楽しさをいけないしてください場合は、ちょうど私がちょうど開発に勉強したいとAndroidはところで私はQrコードスキャン結果のURLをクリックする方法?

Javaファイル

/* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
* http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

package com.jwetherell.quick_response_code; 

import android.view.Display; 
import android.view.WindowManager; 
import android.app.Activity; 
import android.graphics.Bitmap; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.ImageView; 
import android.widget.TextView; 
import com.google.zxing.BarcodeFormat; 
import com.google.zxing.WriterException; 


/** 
* Example Encoder Activity. 
* 
* @author Justin Wetherell ([email protected]) 
*/ 
public final class EncoderActivity extends Activity { 
private static final String TAG = EncoderActivity.class.getSimpleName(); 

@Override 
public void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    setContentView(R.layout.encoder); 

    // This assumes the view is full screen, which is a good assumption 
    WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); 
    Display display = manager.getDefaultDisplay(); 
    int width = display.getWidth(); 
    int height = display.getHeight(); 
    int smallerDimension = width < height ? width : height; 
    smallerDimension = smallerDimension * 7/8; 

    try { 
     QRCodeEncoder qrCodeEncoder = null; 
     //qrCodeEncoder = new QRCodeEncoder("AT", null, Contents.Type.TEXT, BarcodeFormat.CODABAR.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("HI", null, Contents.Type.TEXT, BarcodeFormat.CODE_39.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("Hello", null, Contents.Type.TEXT, BarcodeFormat.CODE_128.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("1234567891011", null, Contents.Type.TEXT, BarcodeFormat.EAN_13.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("12345678", null, Contents.Type.TEXT, BarcodeFormat.EAN_8.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("1234", null, Contents.Type.TEXT, BarcodeFormat.ITF.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("2345", null, Contents.Type.TEXT, BarcodeFormat.PDF_417.toString(), smallerDimension); 
     qrCodeEncoder = new QRCodeEncoder("Hello", null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("12345678910", null, Contents.Type.TEXT, BarcodeFormat.UPC_A.toString(), smallerDimension);` 
    Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); 
    ImageView view = (ImageView) findViewById(R.id.image_view); 
    view.setImageBitmap(bitmap); 

    TextView contents = (TextView) findViewById(R.id.contents_text_view); 
    contents.setText(qrCodeEncoder.getDisplayContents()); 
    setTitle(getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle()); 
} catch (WriterException e) { 
    Log.e(TAG, "Could not encode barcode", e); 
} catch (IllegalArgumentException e) { 
    Log.e(TAG, "Could not encode barcode", e); 
} 
で実験したオープンsoureプロジェクトを使用しています最善の方法だった私を修正します

} }

Xmlファイル

 <?xml version="1.0" encoding="UTF-8"?> 
<!-- 
Copyright (C) 2008 ZXing authors 

Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

     http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, software 
    distributed under the License is distributed on an "AS IS" BASIS, 
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
    See the License for the specific language governing permissions and 
    limitations under the License. 
    --> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/encode_view" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:fillViewport="true" 
       android:background="@color/encode_view" 
       android:orientation="vertical" 
       android:gravity="center"> 

    <ImageView android:id="@+id/image_view" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:scaleType="center"/> 

    <ScrollView android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:gravity="center 

    <TextView android:id="@+id/contents_text_view" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:gravity="center" 
       android:textColor="@color/contents_text" 
       android:textSize="18sp" 
       android:paddingBottom="8dip" 
       android:paddingLeft="8dip" 
       android:paddingRight="8dip"/> 

    </ScrollView> 

</LinearLayout> 

おかげ

+0

あなたはsetTextを使用できますか? –

答えて

1

は、あなたのTextViewのためにこれを呼び出します。

TextView tv = (TextView) findViewById(R.id.text2); 
tv.setMovementMethod(LinkMovementMethod.getInstance()); 

Linkifyクラスについて学ぶ...

これは、全てのリンク(URLや電話番号など)クリッカブルを作るです。

関連する問題