我在我的应用程序中集成了自定义浏览器以进行 PayU 集成。我没有向 PayU URL ( https://secure.payu.in/_payment ) 发送任何参数。我正在服务器端执行此操作(向 PayU 发送参数)。我只需要自定义浏览器,这就是我使用这个的原因。这对我来说很好,但付款成功后它显示空白屏幕。在这个白色的空白屏幕之后如何导航到我的应用程序。
如何获取自定义浏览器的 URL?
参考链接:https ://github.com/payu-intrepos/Android-Custom-Browser/wiki/v5.2.2
依赖:
compile 'com.payu.custombrowser:payu-custom-browser:5.2.2'
代码:
自定义浏览器XL:
<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>
custombrowser.java
try {
Class.forName("com.payu.custombrowser.Bank");
final Bank bank = new Bank() {
@Override
public void registerBroadcast(BroadcastReceiver broadcastReceiver, IntentFilter filter) {
mReceiver = broadcastReceiver;
registerReceiver(broadcastReceiver, filter);
}
@Override
public void unregisterBroadcast(BroadcastReceiver broadcastReceiver) {
if(mReceiver != null){
unregisterReceiver(mReceiver);
mReceiver = null;
}
}
@Override
public void onHelpUnavailable() {
findViewById(R.id.parent).setVisibility(View.GONE);
findViewById(R.id.trans_overlay).setVisibility(View.GONE);
}
@Override
public void onBankError() {
findViewById(R.id.parent).setVisibility(View.GONE);
findViewById(R.id.trans_overlay).setVisibility(View.GONE);
}
@Override
public void onHelpAvailable() {
findViewById(R.id.parent).setVisibility(View.VISIBLE);
}
};
Bundle args = new Bundle();
args.putInt("webView", R.id.webview);
args.putInt("tranLayout",R.id.trans_overlay);
args.putInt("mainLayout",R.id.r_layout);
args.putBoolean("showCustom", true);
bank.setArguments(args);
findViewById(R.id.parent).bringToFront();
try {
getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.cb_fade_in, R.anim.cb_face_out).add(R.id.parent, bank).commit();
}catch(Exception e)
{
e.printStackTrace();
finish();
}
webView.setWebChromeClient(new PayUWebChromeClient(bank));
webView.setWebViewClient(new PayUWebViewClient(bank));
} catch (ClassNotFoundException e) {
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.addJavascriptInterface(new Object() {
@JavascriptInterface
public void onSuccess() {
onSuccess("");
}
@JavascriptInterface
public void onSuccess(final String result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Intent intent = new Intent();
intent.putExtra("result", result);
setResult(RESULT_OK, intent);
finish();
}
// }
});
}
@JavascriptInterface
public void onFailure() {
onFailure("");
}
@JavascriptInterface
public void onFailure(final String result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Intent intent = new Intent();
intent.putExtra("result", result);
setResult(RESULT_CANCELED, intent);
finish();
}
});
}
}, "PayU");
webView.setWebChromeClient(new WebChromeClient() {
});
webView.setWebViewClient(new WebViewClient());
}
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
String PostData="UserUniqueID=" + UUUID + "&OrderID=" + orderid + "&PFID=" + pid + "&ReloadCash=" + reloadcash + "&DeviceID=" + DEVICEID ;
webView.postUrl(WebUrl.Bankurl, PostData.getBytes());
//Weburl.posturl is my server side bank url.
}
@Override
public void onBackPressed(){
boolean disableBack = false;
if(cancelTransaction){
cancelTransaction = false;
Intent intent = new Intent();
intent.putExtra("result", "Transaction canceled due to back pressed!");
setResult(RESULT_CANCELED, intent);
super.onBackPressed();
return;
}
try {
Log.v("TAG_PAUSEURLL", "" + "PAUSEURL");
Bundle bundle = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA).metaData;
disableBack = bundle.containsKey("payu_disable_back") && bundle.getBoolean("payu_disable_back");
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if(!disableBack) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setCancelable(false);
alertDialog.setMessage("Do you really want to cancel the transaction ?");
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cancelTransaction = true;
dialog.dismiss();
onBackPressed();
}
});
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
webView.clearCache(true);
webView.clearHistory();
webView.destroy();
}