function json_responce($len=null){
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: application/json');
if(!is_null($len)){
header('Content-Length: ' . $len);
}
}
remoteDevice = defaultAdapter.getRemoteDevice(getMacAddress());
createRfcommSocketToServiceRecord = remoteDevice.createRfcommSocketToServiceRecord(myUUID);
createRfcommSocketToServiceRecord.connect();
dataOutputStream = new DataOutputStream(createRfcommSocketToServiceRecord.getOutputStream());
public class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view,final String url) {
//try to find browse activity to handle uri
final Uri parsedUri = Uri.parse(url);
AlertDialog alertdialog = new AlertDialog.Builder(activity)
.setIcon(R.mipmap.alert)
.setTitle(Objects.requireNonNull(RawPrinterApp.getAppContext()).getString(R.string.open_url))
.setMessage(url).setNegativeButton(Objects.requireNonNull(RawPrinterApp.getAppContext()).getString(R.string.btn_no),null)
.setPositiveButton(Objects.requireNonNull(RawPrinterApp.getAppContext()).getString(R.string.btn_yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
webView.loadUrl(url);
}
}).create();
alertdialog.setButton(AlertDialog.BUTTON_NEUTRAL,Objects.requireNonNull(RawPrinterApp.getAppContext()).getString(R.string.reSelectTxt), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PackageManager packageManager = activity.getPackageManager();
Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri);
// Create intent to show chooser
Intent chooser = Intent.createChooser(browseIntent, Objects.requireNonNull(RawPrinterApp.getAppContext()).getString(R.string.open_url));
if (browseIntent.resolveActivity(packageManager) != null) {
activity.startActivity(chooser);
}
}
});
alertdialog.show();
return true; // говорим что стандартное поведение было переопределено и сама вьюшка не дергается
}
}