1) Скрыть меню приложения
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.show();
};
2) Скрыть таскбар (сделать приложение в полный экран)
public void hideall(){
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
};
};
};
3) Запретить кнопку «Назад»
@Override
public void onBackPressed() {
super.onResume();
}
4) Проверка наличия интернет на устройстве
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting();
}
5) Вывод в webView картинки и сообщения «офлайн»
String htmlString ="<html><body><table border=0><tr><td><img src='oi.png'></td><td>Интернет кончился..</td></tr></table></body></html>";
mbrowser.loadDataWithBaseURL("file:///android_res/drawable/", htmlString, "text/html", "UTF-8", null);
6) Обработка «самоподписанного» сертификата SSL в webView
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
final AlertDialog.Builder builder = new AlertDialog.Builder(Form1.this);
builder.setMessage(R.string.notification_error_ssl_cert_invalid);
builder.setPositiveButton("Доверяем ему", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();
}
});
builder.setNegativeButton("Уходим", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
hideall();
}
7) Обработка выбора сертификата p12 в webView
@Override
public void onReceivedClientCertRequest(WebView view, final ClientCertRequest request) {
Log.v(getClass().getSimpleName(), "===> certificate required!");
KeyChain.choosePrivateKeyAlias(Form1.this, new KeyChainAliasCallback(){
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void alias(String alias) {
Log.v(getClass().getSimpleName(), "===>Key alias is: " + alias);
try {
PrivateKey changPrivateKey = KeyChain.getPrivateKey(Form1.this, alias);
X509Certificate[] certificates = KeyChain.getCertificateChain(Form1.this, alias);
Log.v(getClass().getSimpleName(), "===>Getting Private Key Success!" );
request.proceed(changPrivateKey, certificates);
} catch (KeyChainException e) {
Log.e(getClass().getSimpleName(), Util.printException(e));
} catch (InterruptedException e) {
Log.e(getClass().getSimpleName(), Util.printException(e));
}
}
},new String[]{"RSA"}, null, null, -1, null);
}