Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中从自定义浏览器导航到应用程序?_Android_Android Activity_Browser_Payu - Fatal编程技术网

如何在Android中从自定义浏览器导航到应用程序?

如何在Android中从自定义浏览器导航到应用程序?,android,android-activity,browser,payu,Android,Android Activity,Browser,Payu,我在我的应用程序中集成了自定义浏览器以进行PayU集成。我没有向PayU URL()发送任何参数。我正在服务器端执行此操作(将参数发送到PayU)。我只需要自定义浏览器,这就是为什么我使用这个。这对我来说很好,但在付款成功后,它会显示空的白色屏幕。如何在这个白色的空屏幕后导航到我的应用程序 如何获取自定义浏览器的URL 参考链接: 依赖关系: compile 'com.payu.custombrowser:payu-custom-browser:5.2.2' 代码: custombrowser

我在我的应用程序中集成了自定义浏览器以进行PayU集成。我没有向PayU URL()发送任何参数。我正在服务器端执行此操作(将参数发送到PayU)。我只需要自定义浏览器,这就是为什么我使用这个。这对我来说很好,但在付款成功后,它会显示空的白色屏幕。如何在这个白色的空屏幕后导航到我的应用程序

如何获取自定义浏览器的URL

参考链接:

依赖关系:

compile 'com.payu.custombrowser:payu-custom-browser:5.2.2'
代码:

custombrowserxl:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/r_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal">
    <FrameLayout
        android:id="@+id/parent"
        android:visibility="gone"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:id="@+id/trans_overlay"
        android:layout_height="match_parent"
        android:orientation="horizontal"
       >
    </LinearLayout>
</RelativeLayout>
我更喜欢这个代码

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


    btnBuy.setOnClickListener(new OnClickListener() {

        @SuppressLint({ "SetJavaScriptEnabled", "ShowToast" }) @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(f_nm && f_pn  && f_email )
            {
                webview.setVisibility(View.VISIBLE);
                Integer randomNum = randInt(0, 9999999);
                txnid=randomNum.toString();
                firstname=etName.getText().toString();
                email=etEmail.getText().toString();
                amount=study_material_price;
                productinfo=study_material_name;
                phone=etPhone.getText().toString();
                String hashSequence = merchant_key+"|"+txnid+"|"+amount+"|"+productinfo+"|"+firstname+"|"+email+"|||||||||||"+salt;
                hash = hashCal("SHA-512", hashSequence);
                webview.addJavascriptInterface(new PayUJavaScriptInterface(), "PayUMoney");
                String json ="txnid="+txnid+"&key="+merchant_key+"&amount="+amount+"&hash="+hash+"&productinfo="+productinfo+"&surl="+SURL+"&furl="+FURL+"&firstname="+firstname+"&email="+email+"&phone="+phone+"&service_provider=payu_paisa";
                webview.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
                webview.getSettings().setDomStorageEnabled(true);
                webview.getSettings().setJavaScriptEnabled(true);
                webview.getSettings().setSupportMultipleWindows(true);
                webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
                webview.getSettings().setSupportZoom(true);       //Zoom Control on web (You don't need this
                //if ROM supports Multi-Touch
                webview.getSettings().setBuiltInZoomControls(true);
                webview.setWebViewClient(new WebViewClient());
                webview.setWebViewClient(
                        new SSLTolerentWebViewClient()
                        );
                webview.postUrl("https://secure.payu.in/_payment", EncodingUtils.getBytes(json, "BASE64"));

                try {

                    webview.setWebViewClient(new WebViewClient() {
                        @Override
                        public void onReceivedError(WebView view, int errorCode,
                                String description, String failingUrl) {
                            Log.d("WEB_VIEW_TEST", "error code:" + errorCode + " - " + description);
                        }

                        @Override
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            // handle different requests for different type of files
                            // this example handles downloads requests for .apk and .mp3 files
                            // everything else the webview can handle normally
                            if (url.endsWith(".mp3")||url.endsWith(".zip") || url.endsWith(".pdf") || url.endsWith(".jpg")|| url.endsWith(".doc")|| url.endsWith(".png")|| url.endsWith(".docx")|| url.endsWith(".xml")|| url.endsWith(".gif")) {
                                String urlSplit[] = url.split("/");
                                String fileName = urlSplit[urlSplit.length-1];
                                Uri source = Uri.parse(url);
                                // Make a new request pointing to the .apk url
                                DownloadManager.Request request = new DownloadManager.Request(source);
                                // appears the same in Notification bar while downloading
                                request.setDescription("Description for the DownloadManager Bar");
                                request.setTitle(fileName);
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                    request.allowScanningByMediaScanner();
                                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                                }
                                // save the file in the "Downloads" folder of SDCARD
                                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,fileName);
                                // get download service and enqueue file
                                DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
                                manager.enqueue(request);
                            }
                            // if there is a link to anything else than .apk or .mp3 load the URL in the webview
                            else view.loadUrl(url);
                            return true;                
                        }
                    });


                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                Toast.makeText(getApplicationContext(), "Please fill all the fields.", 1000).show();
            }
        }
    });
}   

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getAction() == KeyEvent.ACTION_DOWN){
        switch(keyCode)
        {
        case KeyEvent.KEYCODE_BACK:
            if(webview.canGoBack()){
                webview.goBack();
            }else{
                finish();
            }
            return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}

private final class PayUJavaScriptInterface {
    PayUJavaScriptInterface() {
    }

    /**
     * This is not called on the UI thread. Post a runnable to invoke
     * loadUrl on the UI thread.
     */
    @JavascriptInterface
    public void success(long id, final String pId) {
        mHandler.post(new Runnable() {
            public void run() {
                mHandler = null;
                Toast.makeText(getApplicationContext(), "Your Transaction is Successful", 1000).show();
                status="Success";
                paymentId=pId;
                new StoreTransactionData().execute();
                Intent intent = new Intent();
                intent.putExtra("status", "success");
                intent.putExtra("transaction_id", paymentId);
                setResult(RESULT_OK, intent);
                studyDownloadPaid();
                finish();
            }
        });
    }



    @JavascriptInterface
    public void failure(final String id, String error) {
        Log.d("transaction data fail id", id +"   " +study_material_name);
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                paymentId=id;
                status="Faluire";
                new StoreTransactionData().execute();
                cancelPayment();
            }
        });
    }

    @JavascriptInterface
    public void failure() {
        failure("");
    }

    @JavascriptInterface
    public void failure(final String params) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                paymentId=params;
                status="Faluire";
                new StoreTransactionData().execute();
                Log.d("transaction data fail param", params);
                Intent intent = new Intent();
                intent.putExtra("status", params);
                setResult(RESULT_CANCELED, intent);
                finish();
            }
        });
    }

}

private void cancelPayment() {
    Intent intent = new Intent();
    intent.putExtra("status", "cancel");
    //mWebView.destroy();
    setResult(RESULT_CANCELED, intent);
    finish();
}

public static String hashCal(String type, String str) {
    byte[] hashseq = str.getBytes();
    StringBuffer hexString = new StringBuffer();
    try {
        MessageDigest algorithm = MessageDigest.getInstance(type);
        algorithm.reset();
        algorithm.update(hashseq);
        byte messageDigest[] = algorithm.digest();
        for (int i = 0; i < messageDigest.length; i++) {
            String hex = Integer.toHexString(0xFF & messageDigest[i]);
            if (hex.length() == 1) {
                hexString.append("0");
            }
            hexString.append(hex);
        }
    } catch (NoSuchAlgorithmException nsae) {
    }
    return hexString.toString();
}

public static int randInt(int min, int max) {
    // Usually this should be a field rather than a method variable so
    // that it is not re-seeded every call.
    Random rand = new Random();

    // nextInt is normally exclusive of the top value,
    // so add 1 to make it inclusive
    int randomNum = rand.nextInt((max - min) + 1) + min;

    return randomNum;
}


private class SSLTolerentWebViewClient extends WebViewClient {

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed(); // Ignore SSL certificate errors
    }

}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.payment\u home);
setOnClickListener(新的OnClickListener(){
@SuppressLint({“SetJavaScriptEnabled”,“ShowToast”})@Override
公共void onClick(视图v){
//TODO自动生成的方法存根
如果(f_nm和f_pn和f_电子邮件)
{
设置可见性(View.VISIBLE);
整数randomNum=randInt(09999999);
txnid=randomNum.toString();
firstname=etName.getText().toString();
email=etEmail.getText().toString();
金额=研究材料价格;
productinfo=研究材料名称;
phone=etPhone.getText().toString();
字符串hashSequence=merchant_key+“|”+txnid+“|”+金额+“|”+产品信息+“|”+名字+“|”+电子邮件+“||||||”+盐;
hash=hashCal(“SHA-512”,hashSequence);
addJavascriptInterface(新的PayUJavaScriptInterface(),“PayUMoney”);
String json=“txnid=“+txnid+”&key=“+merchant\u key+”&amount=“+amount+”&hash=“+hash+”&productinfo=“+productinfo+”&surl=“+surl+”&furl=“+furl+”&firstname=“+firstname+”&email=“+email+”&phone=“+phone+”&service\u provider=payu paisa”;
webview.getSettings().setUserAgentString(“Mozilla/5.0(Linux;U;Android 2.0;en-us;Droid Build/ESD20)AppleWebKit/530.17(KHTML,类似Gecko)版本/4.0 Mobile Safari/530.17”);
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setSupportMultipleWindows(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview.getSettings().setSupportZoom(true);//web上的缩放控件(您不需要这个
//如果ROM支持多点触摸
webview.getSettings().setBuilTinZoomControl(true);
setWebViewClient(新的WebViewClient());
webview.setWebViewClient(
新的SSLTolerentWebViewClient()
);
webview.postrl(“https://secure.payu.in/_payment,EncodingUtils.getBytes(json,“BASE64”);
试一试{
setWebViewClient(新的WebViewClient(){
@凌驾
接收错误时公共无效(WebView视图,int错误代码,
字符串说明,字符串失败(URL){
Log.d(“网络视图测试”,“错误代码:“+errorCode+”-“+description”);
}
@凌驾
公共布尔值shouldOverrideUrlLoading(WebView视图,字符串url){
//处理不同类型文件的不同请求
//此示例处理.apk和.mp3文件的下载请求
//webview可以正常处理的所有其他内容
如果(url.endsWith(“.mp3”)| url.endsWith(“.zip”)| url.endsWith(“.pdf”)| url.endsWith(“.jpg”)| url.endsWith(.doc”)| url.endsWith(.png”)| url.endsWith(.docx”)| url.endsWith(.xml”)| url.endsWith(.gif){
字符串urlSplit[]=url.split(“/”);
字符串文件名=urlspit[urlspit.length-1];
urisource=Uri.parse(url);
//发出指向.apk url的新请求
DownloadManager.Request-Request=新的DownloadManager.Request(源);
//下载时在通知栏中显示相同内容
request.setDescription(“下载管理器栏的说明”);
setTitle(文件名);
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.HONEYCOMB){
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.request.VISIBILITY\u VISIBLE\u NOTIFY\u完成);
}
//将文件保存在SD卡的“下载”文件夹中
request.setDestinationNexternalPublicDir(Environment.DIRECTORY\u下载,文件名);
//获取下载服务并将文件排队
DownloadManager=(DownloadManager)getSystemService(Context.DOWNLOAD\u服务);
排队(请求);
}
//如果有指向.apk或.mp3以外的任何内容的链接,请在webview中加载URL
else view.loadUrl(url);
返回true;
}
});
}捕获(例外e){
e、 printStackTrace();
}
}否则{
Toast.makeText(getApplicationContext(),“请填写所有字段。”,1000).show();
}
}
});
}   
@凌驾
公共布尔onKeyDown(int k
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.payment_home);


    btnBuy.setOnClickListener(new OnClickListener() {

        @SuppressLint({ "SetJavaScriptEnabled", "ShowToast" }) @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(f_nm && f_pn  && f_email )
            {
                webview.setVisibility(View.VISIBLE);
                Integer randomNum = randInt(0, 9999999);
                txnid=randomNum.toString();
                firstname=etName.getText().toString();
                email=etEmail.getText().toString();
                amount=study_material_price;
                productinfo=study_material_name;
                phone=etPhone.getText().toString();
                String hashSequence = merchant_key+"|"+txnid+"|"+amount+"|"+productinfo+"|"+firstname+"|"+email+"|||||||||||"+salt;
                hash = hashCal("SHA-512", hashSequence);
                webview.addJavascriptInterface(new PayUJavaScriptInterface(), "PayUMoney");
                String json ="txnid="+txnid+"&key="+merchant_key+"&amount="+amount+"&hash="+hash+"&productinfo="+productinfo+"&surl="+SURL+"&furl="+FURL+"&firstname="+firstname+"&email="+email+"&phone="+phone+"&service_provider=payu_paisa";
                webview.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
                webview.getSettings().setDomStorageEnabled(true);
                webview.getSettings().setJavaScriptEnabled(true);
                webview.getSettings().setSupportMultipleWindows(true);
                webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
                webview.getSettings().setSupportZoom(true);       //Zoom Control on web (You don't need this
                //if ROM supports Multi-Touch
                webview.getSettings().setBuiltInZoomControls(true);
                webview.setWebViewClient(new WebViewClient());
                webview.setWebViewClient(
                        new SSLTolerentWebViewClient()
                        );
                webview.postUrl("https://secure.payu.in/_payment", EncodingUtils.getBytes(json, "BASE64"));

                try {

                    webview.setWebViewClient(new WebViewClient() {
                        @Override
                        public void onReceivedError(WebView view, int errorCode,
                                String description, String failingUrl) {
                            Log.d("WEB_VIEW_TEST", "error code:" + errorCode + " - " + description);
                        }

                        @Override
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            // handle different requests for different type of files
                            // this example handles downloads requests for .apk and .mp3 files
                            // everything else the webview can handle normally
                            if (url.endsWith(".mp3")||url.endsWith(".zip") || url.endsWith(".pdf") || url.endsWith(".jpg")|| url.endsWith(".doc")|| url.endsWith(".png")|| url.endsWith(".docx")|| url.endsWith(".xml")|| url.endsWith(".gif")) {
                                String urlSplit[] = url.split("/");
                                String fileName = urlSplit[urlSplit.length-1];
                                Uri source = Uri.parse(url);
                                // Make a new request pointing to the .apk url
                                DownloadManager.Request request = new DownloadManager.Request(source);
                                // appears the same in Notification bar while downloading
                                request.setDescription("Description for the DownloadManager Bar");
                                request.setTitle(fileName);
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                    request.allowScanningByMediaScanner();
                                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                                }
                                // save the file in the "Downloads" folder of SDCARD
                                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,fileName);
                                // get download service and enqueue file
                                DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
                                manager.enqueue(request);
                            }
                            // if there is a link to anything else than .apk or .mp3 load the URL in the webview
                            else view.loadUrl(url);
                            return true;                
                        }
                    });


                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                Toast.makeText(getApplicationContext(), "Please fill all the fields.", 1000).show();
            }
        }
    });
}   

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getAction() == KeyEvent.ACTION_DOWN){
        switch(keyCode)
        {
        case KeyEvent.KEYCODE_BACK:
            if(webview.canGoBack()){
                webview.goBack();
            }else{
                finish();
            }
            return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}

private final class PayUJavaScriptInterface {
    PayUJavaScriptInterface() {
    }

    /**
     * This is not called on the UI thread. Post a runnable to invoke
     * loadUrl on the UI thread.
     */
    @JavascriptInterface
    public void success(long id, final String pId) {
        mHandler.post(new Runnable() {
            public void run() {
                mHandler = null;
                Toast.makeText(getApplicationContext(), "Your Transaction is Successful", 1000).show();
                status="Success";
                paymentId=pId;
                new StoreTransactionData().execute();
                Intent intent = new Intent();
                intent.putExtra("status", "success");
                intent.putExtra("transaction_id", paymentId);
                setResult(RESULT_OK, intent);
                studyDownloadPaid();
                finish();
            }
        });
    }



    @JavascriptInterface
    public void failure(final String id, String error) {
        Log.d("transaction data fail id", id +"   " +study_material_name);
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                paymentId=id;
                status="Faluire";
                new StoreTransactionData().execute();
                cancelPayment();
            }
        });
    }

    @JavascriptInterface
    public void failure() {
        failure("");
    }

    @JavascriptInterface
    public void failure(final String params) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                paymentId=params;
                status="Faluire";
                new StoreTransactionData().execute();
                Log.d("transaction data fail param", params);
                Intent intent = new Intent();
                intent.putExtra("status", params);
                setResult(RESULT_CANCELED, intent);
                finish();
            }
        });
    }

}

private void cancelPayment() {
    Intent intent = new Intent();
    intent.putExtra("status", "cancel");
    //mWebView.destroy();
    setResult(RESULT_CANCELED, intent);
    finish();
}

public static String hashCal(String type, String str) {
    byte[] hashseq = str.getBytes();
    StringBuffer hexString = new StringBuffer();
    try {
        MessageDigest algorithm = MessageDigest.getInstance(type);
        algorithm.reset();
        algorithm.update(hashseq);
        byte messageDigest[] = algorithm.digest();
        for (int i = 0; i < messageDigest.length; i++) {
            String hex = Integer.toHexString(0xFF & messageDigest[i]);
            if (hex.length() == 1) {
                hexString.append("0");
            }
            hexString.append(hex);
        }
    } catch (NoSuchAlgorithmException nsae) {
    }
    return hexString.toString();
}

public static int randInt(int min, int max) {
    // Usually this should be a field rather than a method variable so
    // that it is not re-seeded every call.
    Random rand = new Random();

    // nextInt is normally exclusive of the top value,
    // so add 1 to make it inclusive
    int randomNum = rand.nextInt((max - min) + 1) + min;

    return randomNum;
}


private class SSLTolerentWebViewClient extends WebViewClient {

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed(); // Ignore SSL certificate errors
    }

}