2012-02-22 7 views
0

私は結果にqrスキャナを含むアプリケーションを作成しています。コードのURLで表示されたテキストがあります。結果からテキストを呼び出し、openそのブラウザでもしそうなら、私はそれを行うことができますどのようテキスト文字列で開くURLを呼び出す

のJavaスニペット

Button browser = (Button) findViewById(R.id.ulibutton); 
     browser.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent i = new Intent(Intent.ACTION_VIEW, url = new URL(
         getString(R.string.contents_text))); 

       startActivity(i); 

      } 
     }); 

     ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); 
     if (barcode == null) { 
      barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(
        getResources(), R.drawable.icon)); 
     } else { 
      barcodeImageView.setImageBitmap(barcode); 
     } 

     TextView formatTextView = (TextView) findViewById(R.id.format_text_view); 
     formatTextView.setText(rawResult.getBarcodeFormat().toString()); 

     TextView typeTextView = (TextView) findViewById(R.id.type_text_view); 
     typeTextView.setText(resultHandler.getType().toString()); 

     DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, 
       DateFormat.SHORT); 
     String formattedTime = formatter.format(new Date(rawResult 
       .getTimestamp())); 
     TextView timeTextView = (TextView) findViewById(R.id.time_text_view); 
     timeTextView.setText(formattedTime); 

     TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); 
     View metaTextViewLabel = findViewById(R.id.meta_text_view_label); 
     metaTextView.setVisibility(View.GONE); 
     metaTextViewLabel.setVisibility(View.GONE); 
     Map<ResultMetadataType, Object> metadata = rawResult 
       .getResultMetadata(); 
     if (metadata != null) { 
      StringBuilder metadataText = new StringBuilder(20); 
      for (Map.Entry<ResultMetadataType, Object> entry : metadata 
        .entrySet()) { 
       if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { 
        metadataText.append(entry.getValue()).append('\n'); 
       } 
      } 
      if (metadataText.length() > 0) { 
       metadataText.setLength(metadataText.length() - 1); 
       metaTextView.setText(metadataText); 
       metaTextView.setVisibility(View.VISIBLE); 
       metaTextViewLabel.setVisibility(View.VISIBLE); 
      } 
     } 

     TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); 
     contentsTextView.setMovementMethod(LinkMovementMethod.getInstance()); 
     CharSequence displayContents = resultHandler.getDisplayContents(); 
     contentsTextView.setText(displayContents); 
     // Crudely scale betweeen 22 and 32 -- bigger font for shorter text 
     int scaledSize = Math.max(22, 32 - displayContents.length()/4); 
     contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); 
    } 
} 

答えて

0
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse(YourUrl))); 
startActivity(i); 
関連する問題