2017-07-16 1 views
-1

Androidのネイティブ開発には初めてです。 アラートメッセージに「ブラウザで開く」アイコンを表示します。Androidのショーをアラート内のブラウザで開く

Case: 
I have a QR code scanned and showing the result in a toast or Alert. 
In the scanned Result, I want to Show up "Open In Browser" with the code result or Alert message 

私はこの機能を達成できません。親愛なることで私にこれを行う方法を教えてください。私はAndroidを学ぶことでさらに進歩することができます。

My Manifest goes like this: 

<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> 



And my Result handler 
    @Override 
    public void handleResult(Result rawResult) { 
     // Do something with the result here 
     Log.v("TAG", rawResult.getText()); // Prints scan results 
     Log.v("TAG", rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.) 
     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
       builder.setTitle("UTQode Result"); 
       builder.setMessage(rawResult.getText()); 
       AlertDialog alert1 = builder.create(); 
       alert1.show(); 
//  Toast.makeText(getApplicationContext(), "My Message", 
//    Toast.LENGTH_SHORT).show(); 
     Toast.makeText(this, rawResult.getText(), Toast.LENGTH_LONG).show(); 

     // If you would like to resume scanning, call this method below: 
     mScannerView.resumeCameraPreview(this); 
    } 

I am testing with the above code, but I need to open the alert result and Query it in Browser 

答えて

-1

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
       builder.setTitle("UTQode Result"); 
       builder.setMessage(rawResult.getText()); 
       builder..setIcon(getResources().getDrawable(android.R.drawable.your_icon)); 
       AlertDialog alert1 = builder.create(); 
       alert1.show(); 

テキストとボタンは、「ブラウザで開く」したい場合は、これを行います「ブラウザで開く」をクリックすると、ボタンを押してメソッドを追加できます。

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
      context); 

     // set title 
     alertDialogBuilder.setTitle("Your Title"); 

     // set dialog message 
     alertDialogBuilder 
      .setMessage("Click yes to exit!") 
      .setCancelable(false) 
      .setPositiveButton("Open in Browser",new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog,int id) { 
        openInBrowser(); 
       } 
       }) 
      .setNegativeButton("No",new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog,int id) { 
        // if this button is clicked, just close 
        // the dialog box and do nothing 
        dialog.cancel(); 
       } 
      }); 

      // create alert dialog 
      AlertDialog alertDialog = alertDialogBuilder.create(); 

      // show it 
      alertDialog.show(); 

アラートの上部にあるアイコンのみを使用する場合は、.setIcon()

+0

2つの問題openInBrowser()を解決できません.Noをクリックすると、アプリケーションがハングアップしました。これはアラートに関するものですが、取得するアラートで取得したrawResultを開きたい別のアプリで開かれたまたはブラウザ –

0

警告ダイアログでこれを行います。あなたは、ブラウザを開きたい場合は

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
         builder.setTitle("UTQode Result"); 
         builder.setMessage(rawResult.getText()); 
         builder.setIcon(getResources().getDrawable(android.R.drawable.your_icon)); 
    builder.setPositiveButton("Open in browser", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        //do things 
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(your result url))); 
       } 
      }); 
         AlertDialog alert1 = builder.create(); 
         alert1.show(); 
+0

感謝の気持ちブルーノは、アラートで私を助けましたが、私の場合です。ブラウザで開くをクリックすると、結果私はアラートに入った。ケース:QRコードからURLを取得しました。(今はブラウザで開きます: "しかし、"ブラウザで開く "をクリックしたとき)アラート内のURL(rarResult)を開く必要があります –

+0

私はあなたが必要とする完全なコードで質問を更新します –

+0

Bruno。ありがとうございましたパッケージマネージャーで働いています。私が助けてくれることを祈っています –

関連する問題