2016-04-22 13 views
0

私はqrコードスキャンアプリケーションを作成しています。私はZXingライブラリを使用しました。 QRコードのURLを使用してWebページにリダイレクトする方法は? アプリケーションを使用してWebページにリダイレクトする(ブラウザを使用しない)助けてください これは私のコードです。QRコードのURLを使ってウェブページにリダイレクトする方法は?

ScanActivity.java

package app.num.barcodescannerproject; 

import android.app.AlertDialog; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 

import com.google.zxing.Result; 
import me.dm7.barcodescanner.zxing.ZXingScannerView; 

public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler { 
private ZXingScannerView mScannerView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

} 

public void QrScanner(View view){ 


    mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view 
    setContentView(mScannerView); 

    mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results. 
    mScannerView.startCamera();   // Start camera 

} 

@Override 
public void onPause() { 
    super.onPause(); 
    mScannerView.stopCamera();   // Stop camera on pause 
} 

@Override 
public void handleResult(Result rawResult) { 
    // Do something with the result here 

    Log.e("handler", rawResult.getText()); 
    Log.e("handler", rawResult.getBarcodeFormat().toString()); 

    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setTitle("Kết quả :"); 
    builder.setMessage(rawResult.getText()); 
    AlertDialog alert1 = builder.create(); 
    alert1.show(); 


    mScannerView.resumeCameraPreview(this); 
} 
} 

main.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="app.num.barcodescannerproject.MainActivity"> 

<Button android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:text="QRScanner" 
    android:onClick="QrScanner" /> 
</RelativeLayout> 

ActivityMainfest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="app.num.barcodescannerproject"> 
<uses-permission android:name="android.permission.CAMERA" /> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

</manifest> 

答えて

0

私はQR読み取りが成功したと仮定します。

rawResult.getText() // working url 

URLを取得したら、WebViewにURLを渡す/ロードする必要があります。 WebViewのための

あなたのマニフェストファイルに、

<uses-permission android:name="android.permission.INTERNET" /> 

を与える必要があります。

詳しくは

[WebViewの]、参照:http://developer.android.com/reference/android/webkit/WebView.html

関連する問題