As @simon-ninon said, this is the way I implented in my app.
In the onCreate of the activity that inflates Webview in the UI, you
can have a try-catch to save yourself from the errors producing in the
Crashlytics.
/**
* This element touches the UI elements
* of the application and set them up.
*/
try {
setContentView(R.layout.activity_main);
// ... further setup
} catch (Exception ex) {
transferToNoPackageFoundActivity(ex.getMessage());
}
private void transferToNoPackageFoundActivity(String errorMessage) {
Intent intent = new Intent(this, NoPackageFoundActivity.class);
intent.putExtra(Intent.EXTRA_INTENT, errorMessage);
startActivity(intent);
finish();
}
In the NoPackageFoundActivity, you can take the user to the Playstore for downloading the webview package.
/**
* This field is used for presenting the user
* with an error image for no connectivity.
*/
private lateinit var mErrorImage: ImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_no_network)
// get the intent for the error message, if any.
val intent: Intent = intent
if (intent.hasExtra(Intent.EXTRA_INTENT)) {
println(intent.getStringExtra(Intent.EXTRA_INTENT))
}
mErrorImage = findViewById(R.id.error_image)
mErrorImage.contentDescription = resources.getString(R.string.no_network_image_desc)
Glide.with(this)
.load(R.drawable.ic_no_web_view_illustration)
.into(mErrorImage)
val enableButton = findViewById