kandi background
Explore Kits

chromeview | concept Android WebView implementation based on Chromium | Android library

 by   pwnall Java Version: Current License: No License

 by   pwnall Java Version: Current License: No License

Download this library from

kandi X-RAY | chromeview Summary

chromeview is a Java library typically used in Mobile, Android applications. chromeview has no bugs, it has no vulnerabilities and it has medium support. However chromeview build file is not available. You can download it from GitHub.
ChormeView works like Android's WebView, but is backed by the latest Chromium code.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • chromeview has a medium active ecosystem.
  • It has 1658 star(s) with 447 fork(s). There are 151 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 40 open issues and 16 have been closed. On average issues are closed in 49 days. There are 5 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of chromeview is current.
chromeview Support
Best in #Android
Average in #Android
chromeview Support
Best in #Android
Average in #Android

quality kandi Quality

  • chromeview has 0 bugs and 0 code smells.
chromeview Quality
Best in #Android
Average in #Android
chromeview Quality
Best in #Android
Average in #Android

securitySecurity

  • chromeview has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • chromeview code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
chromeview Security
Best in #Android
Average in #Android
chromeview Security
Best in #Android
Average in #Android

license License

  • chromeview does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.
chromeview License
Best in #Android
Average in #Android
chromeview License
Best in #Android
Average in #Android

buildReuse

  • chromeview releases are not available. You will need to build from source code and install.
  • chromeview has no build file. You will be need to create the build yourself to build the component from source.
  • Installation instructions, examples and code snippets are available.
  • chromeview saves you 10310 person hours of effort in developing the same functionality from scratch.
  • It has 20964 lines of code, 2777 functions and 195 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
chromeview Reuse
Best in #Android
Average in #Android
chromeview Reuse
Best in #Android
Average in #Android
Top functions reviewed by kandi - BETA

kandi has reviewed chromeview and discovered the below as its top functions. This is intended to give you an instant insight into chromeview implemented functionality, and help decide if they suit your requirements.

  • Initialize the listeners .
    • Process a touch event .
      • Decodes a media file .
        • Allocates camera parameters .
          • Converts the given netty code to an error code .
            • Computes and initializes the bounds of the view .
              • Gets the OpenSSLRSHandle for a private key .
                • Initializes the switcher .
                  • Prepare the connection .
                    • Extracts media metadata .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      chromeview Key Features

                      Proof of concept Android WebView implementation based on Chromium code

                      Initialize Chromium

                      copy iconCopydownload iconDownload
                      import us.costan.chrome.ChromeView;
                      import android.app.Application;
                      
                      public class MyApplication extends Application {
                          @Override
                          public void onCreate() {
                              super.onCreate();
                              ChromeView.initialize(this);
                          }
                      }
                      

                      Usage

                      copy iconCopydownload iconDownload
                      ChromeView chromeView = (ChromeView)findViewById(R.id.gameUiView);
                      chromeView.getSettings().setJavaScriptEnabled(true);
                      chromeView.loadUrl("http://www.google.com");
                      

                      JavaScript

                      copy iconCopydownload iconDownload
                      import us.costan.chrome.ChromeJavascriptInterface;
                      
                      public class JsBindings {
                          @ChromeJavascriptInterface
                          public String getHello() {
                              return "Hello world";
                          }
                      }
                      
                      chromeView.addJavascriptInterface(new JsBindings(), "AndroidBindings");
                      

                      Cookies

                      copy iconCopydownload iconDownload
                      ChromeCookieManager.getInstance().getCookie("https://www.google.com");
                      

                      Android Studio App keeps crashing inside Emulator

                      copy iconCopydownload iconDownload
                      setContentView(R.layout.activity_main);
                      
                       webView = (WebView) findViewById(R.id.webView);
                      
                      NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings android.webkit.WebView.getSettings()' on a null object reference
                      
                      setContentView(R.layout.activity_main);
                      
                       webView = (WebView) findViewById(R.id.webView);
                      
                      NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings android.webkit.WebView.getSettings()' on a null object reference
                      
                      setContentView(R.layout.activity_main);
                      
                       webView = (WebView) findViewById(R.id.webView);
                      
                      NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings android.webkit.WebView.getSettings()' on a null object reference
                      

                      Community Discussions

                      Trending Discussions on chromeview
                      • Android Studio App keeps crashing inside Emulator
                      • Android equivalent of iOS' SFSafariViewController
                      Trending Discussions on chromeview

                      QUESTION

                      Android Studio App keeps crashing inside Emulator

                      Asked 2021-Mar-24 at 13:20

                      I am working on an Android app, and one day it just kept crashing inside the emulator. Luckily I had everything on github and worked on a seperate branch. So I thought I just go back one month where I new it worked a 100% but that didn't help. My App still crashes on startup inside the emulator.

                      Debug:

                      E/AndroidRuntime: FATAL EXCEPTION: main
                      Process: ch.xxx.xxx, PID: 8013
                      java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.xxx.xxx/ch.xxx.xxx.SecondActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings android.webkit.WebView.getSettings()' on a null object reference
                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
                          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
                          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
                          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
                          at android.os.Handler.dispatchMessage(Handler.java:106)
                          at android.os.Looper.loop(Looper.java:223)
                          at android.app.ActivityThread.main(ActivityThread.java:7656)
                          at java.lang.reflect.Method.invoke(Native Method)
                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
                       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings android.webkit.WebView.getSettings()' on a null object reference
                          at ch.xxx.xxx.SecondActivity.StartWebView(SecondActivity.java:88)
                          at ch.xxx.xxx.SecondActivity.CheckInternetState(SecondActivity.java:81)
                          at ch.xxx.xxx.SecondActivity.onCreate(SecondActivity.java:51)
                          at android.app.Activity.performCreate(Activity.java:8000)
                          at android.app.Activity.performCreate(Activity.java:7984)
                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
                          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
                          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
                          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
                          at android.os.Handler.dispatchMessage(Handler.java:106) 
                          at android.os.Looper.loop(Looper.java:223) 
                          at android.app.ActivityThread.main(ActivityThread.java:7656) 
                          at java.lang.reflect.Method.invoke(Native Method) 
                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
                      

                      I did some research but didn't find anything. If it's too little information please write a comment what you need.

                      Edit:

                      XML:

                      <?xml version="1.0" encoding="utf-8"?>
                      

                      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
                      <uses-permission android:name="android.permission.INTERNET" />
                      <uses-permission android:name="android.permission.CAMERA" />
                      <uses-permission android:name="android.permission.CAMERA2" />
                      <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
                      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
                      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
                      <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
                      <uses-feature android:name="android.hardware.camera"
                          android:required="false" />
                      <application
                          android:allowBackup="true"
                          android:hardwareAccelerated="true"
                          android:icon="@mipmap/ic_launcher"
                          android:label="@string/app_name"
                          android:roundIcon="@mipmap/ic_launcher_round"
                          android:supportsRtl="true"
                          android:theme="@style/Theme.DOCDevices"
                          android:usesCleartextTraffic="true">
                          <activity android:name=".MainActivity">
                              <intent-filter>
                                  <action android:name="android.intent.action.MAIN" />
                                  <category android:name="android.intent.category.LAUNCHER" />
                              </intent-filter>
                          </activity>
                          <activity android:name=".noconnectionActivity" />
                          <activity android:name=".SecondActivity" />
                      </application>
                      

                      activity_main.xml

                      <?xml version="1.0" encoding="utf-8"?>
                      <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      xmlns:app="http://schemas.android.com/apk/res-auto"
                      xmlns:tools="http://schemas.android.com/tools"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      tools:context=".MainActivity"
                      android:background="#000000">
                      
                      <RelativeLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:background="#000000"
                          android:visibility="visible">
                      
                          <ImageView
                              android:id="@+id/imageView1"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_centerInParent="true"
                              android:layout_marginStart="150dp"
                              android:layout_marginLeft="150dp"
                              android:alpha="1"
                              android:scaleType="centerInside"
                              android:src="@drawable/blue_1"
                              android:visibility="visible"></ImageView>
                      </RelativeLayout>
                      
                      </androidx.constraintlayout.widget.ConstraintLayout>
                      

                      mainview.xml

                      <?xml version="1.0" encoding="utf-8"?>
                      <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      xmlns:app="http://schemas.android.com/apk/res-auto"
                      xmlns:tools="http://schemas.android.com/tools"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:background="#000000"
                      tools:context=".SecondActivity">
                      
                      <WebView
                          android:id="@+id/webView"
                          style="@android:style/Widget.DeviceDefault.WebView"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:background="#000000"
                          android:visibility="visible"></WebView>
                      
                      </androidx.constraintlayout.widget.ConstraintLayout>
                      

                      mainactivity:

                      package ch.xxx.xxx;
                      
                      import android.content.Intent;
                      import android.os.Bundle;
                      import android.os.Handler;
                      import android.view.WindowManager;
                      import androidx.appcompat.app.AppCompatActivity;
                      
                      public class MainActivity extends AppCompatActivity {
                      
                      private static int SPLASH_SCREEN_TIME_OUT=2000;
                      
                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                      
                          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
                          //This method is used so that your splash activity
                          //can cover the entire screen.
                      
                          setContentView(R.layout.activity_main);
                          //this will bind your MainActivity.class file with activity_main.
                      
                          new Handler().postDelayed(new Runnable() {
                              @Override
                              public void run() {
                                  Intent i=new Intent(MainActivity.this,
                                          SecondActivity.class);
                                  //Intent is used to switch from one activity to another.
                      
                                  startActivity(i);
                                  //invoke the SecondActivity.
                      
                                  finish();
                                  //the current activity will get finished.
                              }
                          }, SPLASH_SCREEN_TIME_OUT);
                      
                      }
                      
                      }
                      

                      secondActivity:

                      package ch.xxx.xxx;
                      
                      import android.app.Activity;
                      import android.app.ProgressDialog;
                      import android.content.ActivityNotFoundException;
                      import android.content.Context;
                      import android.content.Intent;
                      import android.graphics.Bitmap;
                      import android.net.ConnectivityManager;
                      import android.net.Uri;
                      import android.os.Build;
                      import android.os.Bundle;
                      import android.os.Environment;
                      import android.os.Parcelable;
                      import android.provider.MediaStore;
                      import android.util.Log;
                      import android.webkit.ValueCallback;
                      import android.webkit.WebChromeClient;
                      import android.webkit.WebResourceError;
                      import android.webkit.WebResourceRequest;
                      import android.webkit.WebView;
                      import android.widget.ImageView;
                      import android.widget.Toast;
                      
                      import androidx.appcompat.app.AppCompatActivity;
                      
                      import java.io.File;
                      import java.io.IOException;
                      import java.text.SimpleDateFormat;
                      import java.util.Date;
                      import java.util.Timer;
                      import java.util.TimerTask;
                      
                      public class SecondActivity extends AppCompatActivity {
                      public WebView webView;
                      ImageView iv;
                      ProgressDialog progressDialog;
                      private ValueCallback<Uri> mUploadMessage;
                      private Uri mCapturedImageURI = null;
                      private ValueCallback<Uri[]> mFilePathCallback;
                      private String mCameraPhotoPath;
                      private static final int INPUT_FILE_REQUEST_CODE = 1;
                      private static final int FILECHOOSER_RESULTCODE = 1;
                      Timer t = new Timer();
                      
                      
                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          setContentView(R.layout.activity_main);
                          CheckInternetState();
                          TimerTask tt = new TimerTask() {
                              @Override
                              public void run() {
                                  switchView();
                              }
                          };
                          t.scheduleAtFixedRate(tt, 1, 1000);
                      }
                      
                      public void switchView() {
                          Intent obj = new Intent(SecondActivity.this, noconnectionActivity.class);
                          if (!DetectConnection.checkInternetConnection(this)) {
                              t.cancel();
                              startActivity(obj);
                              webView = null;
                          }
                      }
                      
                      public void CheckInternetState() {
                          if (!DetectConnection.checkInternetConnection(this)) {
                              setContentView(R.layout.activity_no_connection);
                          } else {
                              //        Show Spinner when app is loading
                              progressDialog = new ProgressDialog(this);
                              progressDialog.setCancelable(true);
                              progressDialog.setMessage("Loading...");
                              progressDialog.show();
                      
                      //             Start WebView
                              StartWebView();
                          }
                      }
                      
                      public void StartWebView() {
                          //        WebView to View xxx Website
                          webView = (WebView) findViewById(R.id.webView);
                          webView.getSettings().setJavaScriptEnabled(true);
                          webView.clearCache(true);
                          webView.loadUrl("http://www.doccardiacdevice.com/scan_Mobile"); // website on app launch
                          webView.setWebViewClient(new xWebViewClient()); //we would be overriding WebViewClient() with custom methods
                          webView.setWebChromeClient(new chromeView()); //we would be overriding WebChromeClient() with custom methods.
                      }
                      
                      class xWebViewClient extends android.webkit.WebViewClient {
                          @Override
                          public boolean shouldOverrideUrlLoading(WebView view, String url) {
                              view.loadUrl(url);
                              return true;
                          }
                      
                          @Override
                          public void onPageStarted(WebView view, String url, Bitmap favicon) {
                              super.onPageStarted(view, url, favicon);
                              progressDialog.show(); //showing the progress bar once the page has started loading
                          }
                      
                          @Override
                          public void onPageFinished(WebView view, String url) {
                              super.onPageFinished(view, url);
                              progressDialog.dismiss(); // hide the progress bar once the page has loaded
                          }
                      
                          @Override
                          public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                              super.onReceivedError(view, request, error);
                              webView.loadData("", "text/html", "utf-8"); // replace the default error page with plan content
                              progressDialog.dismiss(); // hide the progress bar on error in loading
                              Toast.makeText(getApplicationContext(), "Internet issue", Toast.LENGTH_SHORT).show();
                              setContentView(R.layout.activity_no_connection);
                          }
                      }
                      
                      public class chromeView extends WebChromeClient {
                          // For Android 5.0+
                          public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {
                              // Double check that we don't have any existing callbacks
                              if (mFilePathCallback != null) {
                                  mFilePathCallback.onReceiveValue(null);
                              }
                              mFilePathCallback = filePath;
                      
                              Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                              if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                                  // Create the File where the photo should go
                      
                                  File photoFile = null;
                                  try {
                                      photoFile = createImageFile();
                                      takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                                      Log.d("test", "Test1");
                      
                                  } catch (IOException ex) {
                                      // Error occurred while creating the File
                                      Toast.makeText(getApplicationContext(), "\"Unable to create Image File", Toast.LENGTH_SHORT).show();
                      
                                  }
                      
                                  // Continue only if the File was successfully created
                                  if (photoFile != null) {
                                      mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
                                      takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                              Uri.fromFile(photoFile));
                                  } else {
                                      takePictureIntent = null;
                                  }
                              }
                      
                              Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
                              contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
                              contentSelectionIntent.setType("image/*");
                      
                              Intent[] intentArray;
                              if (takePictureIntent != null) {
                                  intentArray = new Intent[]{takePictureIntent};
                              } else {
                                  intentArray = new Intent[0];
                              }
                      
                              Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
                              chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
                              chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
                              chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
                      
                              startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);
                      
                              return true;
                      
                          }
                      
                          // openFileChooser for Android 3.0+
                          public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
                              Log.d("test", "Test2");
                      
                              mUploadMessage = uploadMsg;
                      
                              try {
                                  // Create AndroidExampleFolder at sdcard
                                  File imageStorageDir = new File(
                                          Environment.getExternalStoragePublicDirectory(
                                                  Environment.DIRECTORY_PICTURES)
                                          , "AndroidExampleFolder");
                      
                                  if (!imageStorageDir.exists()) {
                                      // Create AndroidExampleFolder at sdcard
                                      imageStorageDir.mkdirs();
                                  }
                      
                                  // Create camera captured image file path and name
                                  File file = new File(
                                          imageStorageDir + File.separator + "IMG_"
                                                  + String.valueOf(System.currentTimeMillis())
                                                  + ".jpg");
                      
                                  mCapturedImageURI = Uri.fromFile(file);
                      
                                  // Camera capture image intent
                                  final Intent captureIntent = new Intent(
                                          android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                      
                                  captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
                      
                                  Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                                  i.addCategory(Intent.CATEGORY_OPENABLE);
                                  i.setType("image/*");
                      
                                  // Create file chooser intent
                                  Intent chooserIntent = Intent.createChooser(i, "Image Chooser");
                      
                                  // Set camera intent to file chooser
                                  chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
                                          , new Parcelable[]{captureIntent});
                      
                                  // On select image call onActivityResult method of activity
                                  startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
                              } catch (Exception e) {
                                  Log.d("test", e.getMessage());
                              }
                      
                          }
                      
                          // openFileChooser for Android < 3.0
                          public void openFileChooser(ValueCallback<Uri> uploadMsg) {
                              openFileChooser(uploadMsg, "");
                          }
                      
                          //openFileChooser for other Android versions
                          public void openFileChooser(ValueCallback<Uri> uploadMsg,
                                                      String acceptType,
                                                      String capture) {
                      
                              openFileChooser(uploadMsg, acceptType);
                          }
                      
                      }
                      
                      @Override
                      public void onActivityResult(int requestCode, int resultCode, Intent data) {
                      
                          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                      
                              if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
                                  super.onActivityResult(requestCode, resultCode, data);
                                  return;
                              }
                      
                              Uri[] results = null;
                      
                              // Check that the response is a good one
                              if (resultCode == Activity.RESULT_OK) {
                                  if (data == null || data.getDataString() == null) {
                                      // If there is not data, then we may have taken a photo
                                      if (mCameraPhotoPath != null) {
                                          results = new Uri[]{Uri.parse(mCameraPhotoPath)};
                                      }
                                  } else {
                                      String dataString = data.getDataString();
                                      if (dataString != null) {
                                          results = new Uri[]{Uri.parse(dataString)};
                                      }
                                  }
                              }
                      
                              mFilePathCallback.onReceiveValue(results);
                              mFilePathCallback = null;
                      
                          } else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
                              if (requestCode != FILECHOOSER_RESULTCODE || mUploadMessage == null) {
                                  super.onActivityResult(requestCode, resultCode, data);
                                  return;
                              }
                      
                              if (requestCode == FILECHOOSER_RESULTCODE) {
                      
                                  if (null == this.mUploadMessage) {
                                      return;
                      
                                  }
                      
                                  Uri result = null;
                      
                                  try {
                                      if (resultCode != RESULT_OK) {
                      
                                          result = null;
                      
                                      } else {
                      
                                          // retrieve from the private variable if the intent is null
                                          result = data == null ? mCapturedImageURI : data.getData();
                                      }
                                  } catch (Exception e) {
                                      Toast.makeText(getApplicationContext(), "activity :" + e,
                                              Toast.LENGTH_LONG).show();
                                  }
                      
                                  mUploadMessage.onReceiveValue(result);
                                  mUploadMessage = null;
                      
                              }
                          }
                      
                          return;
                      }
                      
                      @Override
                      public void onBackPressed() {
                          if (webView.canGoBack()) {
                              webView.goBack();
                          } else {
                              finish();
                          }
                      }
                      
                      private File createImageFile() throws IOException {
                          try {
                              // Create an image file name
                              String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
                              String imageFileName = "JPEG_" + timeStamp + "_";
                              File storageDir = Environment.getExternalStoragePublicDirectory(
                                      Environment.DIRECTORY_PICTURES);
                              File imageFile = File.createTempFile(
                                      imageFileName,  /* prefix */
                                      ".jpg",         /* suffix */
                                      storageDir      /* directory */
                              );
                              return imageFile;
                          } catch (Exception e) {
                              Log.d("test", e.getMessage());
                              return null;
                          }
                      }
                      
                      public static class DetectConnection {
                          public static boolean checkInternetConnection(Context context) {
                              ConnectivityManager con_manager = (ConnectivityManager)
                                      context.getSystemService(Context.CONNECTIVITY_SERVICE);
                      
                              return (con_manager.getActiveNetworkInfo() != null
                                      && con_manager.getActiveNetworkInfo().isAvailable()
                                      && con_manager.getActiveNetworkInfo().isConnected());
                          }
                      }
                      
                      }
                      

                      ANSWER

                      Answered 2021-Mar-24 at 13:20

                      In your SecondActivity you are doing:

                      setContentView(R.layout.activity_main);
                      

                      and inside activity_main there is no WebView.

                      In CheckInternetState you call setContentView(R.layout.activity_no_connection); if there is no internet connection. I would say this is wrong. Instead of trying to setContentView again, just add those views inside your main layout for that Activity and based on the check show/hide those views.

                      And to your main problem which leads to the crash. In CheckInternetState if there is no issue with connection you call StartWebView(); which tries to find your WebView:

                       webView = (WebView) findViewById(R.id.webView);
                      

                      but since you never actually call setContentView(R.layout.mainview); (where your WebView is actually placed) your app is crashing with an error:

                      NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings android.webkit.WebView.getSettings()' on a null object reference
                      

                      because your WebView is null.

                      Source https://stackoverflow.com/questions/66781288

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install chromeview

                      This section explains how to set up your Android project to use ChromeView.

                      Support

                      If you use this project and want to help move it along, please star the following bugs.

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Explore Related Topics

                      Share this Page

                      share link
                      Consider Popular Android Libraries
                      Try Top Libraries by pwnall
                      Compare Android Libraries with Highest Support
                      Compare Android Libraries with Highest Quality
                      Compare Android Libraries with Highest Security
                      Compare Android Libraries with Permissive License
                      Compare Android Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.