簡體   English   中英

我的應用掃描二維碼后,沒有任何反應

[英]After my app scans the QR code nothing happens

我遵循了將zxing集成到我的應用程序中的教程,並且效果很好,現在唯一的問題是,當我掃描qr代碼時,什么也沒有啟動,我是一個完整的newb,有些輸入將對您有很大的幫助。 我的Java是:

public class MainActivity extends Activity implements OnClickListener {


private Button scanBtn;
private TextView formatTxt, contentTxt;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    scanBtn = (Button)findViewById(R.id.scan_button);
    formatTxt = (TextView)findViewById(R.id.scan_format);
    contentTxt = (TextView)findViewById(R.id.scan_content);
    scanBtn.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public void onClick(View v){
    //respond to clicks
    if(v.getId()==R.id.scan_button){
        IntentIntegrator scanIntegrator = new IntentIntegrator(this);
        scanIntegrator.initiateScan();
        }
    }

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    if (scanningResult != null) {
        String scanContent = scanningResult.getContents();
        String scanFormat = scanningResult.getFormatName();
        formatTxt.setText("FORMAT: " + scanFormat);
        contentTxt.setText("CONTENT: " + scanContent);
        }else{
            Toast toast = Toast.makeText(getApplicationContext(),
                    "No scan data received!", Toast.LENGTH_SHORT);
                toast.show();
            }
    }

}

我想啟動瀏覽器,但是我確定我缺少什么

您實際上從未啟動任何結果。 如果您掃描的文字原來是網站鏈接,則需要啟動一個意圖以使網絡瀏覽器打開。

在讀取結果后的活動結果中,您將執行以下操作:

Intent i= new Intent(Intent.ACTION_VIEW, Uri.parse(<INSERT URL>));
startActivity(i);

從QR代碼中獲取字符串后,您需要通過以下方式啟動瀏覽器:

String url = "Url String";
Intent myIntent = new Intent(Intent.ACTION_VIEW,
        Uri.parse(url));
try {  
      // Start the activity  
      startActivity(myIntent);
      this.finish();
    } catch (ActivityNotFoundException e) {  
      // Raise on activity not found  
      Toast toast = Toast.makeText(context, "Browser not found.", Toast.LENGTH_SHORT);  
    }  

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM