Java Android显示在浏览器中打开的内部警报

Java Android显示在浏览器中打开的内部警报,java,android,Java,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原生开发的新手, 我想在警报消息中显示“在浏览器中打开”图标

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
我的清单如下所示:
还有我的结果处理程序
@凌驾
公共无效HandlerResult(结果rawResult){
//在这里对结果做点什么
Log.v(“TAG”,rawResult.getText());//打印扫描结果
Log.v(“TAG”,rawResult.getBarcodeFormat().toString());//打印扫描格式(qrcode、pdf417等)
AlertDialog.Builder=新建AlertDialog.Builder(此);
建造商名称(“UTQode结果”);
setMessage(rawResult.getText());
AlertDialog alert1=builder.create();
alert1.show();
//Toast.makeText(getApplicationContext(),“我的消息”,
//吐司。长度(短)。show();
Toast.makeText(this,rawResult.getText(),Toast.LENGTH_LONG.show();
//如果要恢复扫描,请调用以下方法:
mScannerView.resumeCameraPreview(本);
}
我正在使用上述代码进行测试,但我需要打开警报结果并在浏览器中查询它

在警报对话框中执行此操作:

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

谢谢Bruno,这有助于我处理警报,但当我单击“在浏览器中打开”时,我需要搜索警报中的结果。案例:我从二维码中得到一个URL,我会得到一个警报(现在它在浏览器中打开:),但当我点击“在浏览器中打开”时,我会在警报中得到URL(结果)需要打开。我用你需要的完整代码更新了问题。Bruno。谢谢你。它成功了。我正在与软件包经理一起工作,希望你能帮助我。很好,我帮助了你,如果我帮助你回答了其他有同样问题的人,我知道你找到了解决方案,我在这里帮助的任何问题都被接受了,我如何操作n在此之前的packagemanager?我的意思是,它直接在默认浏览器中打开,我希望它在我选择的浏览器中打开,每次(每次)。2个问题无法解决openInBrowser()的问题;当我点击“否”时,应用程序被挂起,这是关于警报的,但我甚至想打开在警报中得到的结果,以便在另一个应用程序或浏览器中打开
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();