logo
Tags down

shadow

Android Navigation Component keeps reloading WebView


By : X Adams
Date : October 17 2020, 06:10 PM
To fix the issue you can do This is how fragments work in their basic form (which is what the Navigation Components use)
The fragments themselves are saved, but their views are destroyed.
code :


Share : facebook icon twitter icon

Android WebView: never reloading


By : Wesley
Date : March 29 2020, 07:55 AM
Hope this helps Webview content will be loaded depending on where you called your loadurl . For ex: if you written your loadurl function in onCreate() then that function will executes when orientation changes. you can restrict them in manifest file android:configChanges="orientation|keyboardHidden" . So be sure where to call your load url function and also look at Activity life cycle

android autosize webview without reloading it


By : Arindam Datta
Date : March 29 2020, 07:55 AM
help you fix your problem I have a layout with a webview and admob. I also set orientation|keyboard to main activity in order handle onConfigChanges in order to not reload page content when device rotation. When appstarts, webview is created and content loaded, then, admob appears but webview is not auto resized! When happens, I turn device to landscape and return to portrait, layout is resized and properly fitted! How could I force webview to auto resize again? I tried several options but no succes! thank you , Try to force the height of your adview. Somethink like that
code :
<com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="@dimen/adview_height" />
<resources>
    <dimen name="adview_height">30dp</dimen>
</resources>

Android reloading a webView


By : TEves2015
Date : March 29 2020, 07:55 AM
Any of those help So I finally found a simple answer to my problem called : DialogInterface.OnDismissListener.
Basically this is an interface, that has a method onDismiss(). I have created a class where my alert dialogs are created, and all the activities extend this class, and also I have implemented onDismiss() in it like this :
code :
 @Override
    public void onDismiss(DialogInterface dialog) {
        onResume();

    }

WebView is reloading when app is gone background and came back in iOS and Android?


By : Diligent
Date : March 29 2020, 07:55 AM
will help you I've a small app which holds a webview nothing more than that. I'm loading the webview with a url. but when my app is gone background and came back the webview is reloading, For me it should not happen. How to stop webview to reload when app is going to background in iOS and Android. , There are several reasons for the reloading of the App.
Android

Android Webview Camera Upload is not working on Rotation? webview reloading? Android 5 and 6+


By : rongjin
Date : March 29 2020, 07:55 AM
may help you . Use this for android 5 and 6+ versions
To Capture Image form Web-view and Upload
code :
public class MainActivity extends Activity {

    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            Log.v(TAG, "MainFragment Creation");
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new MainFragment())
                    .commit();
        }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
public class MainFragment extends Fragment {

    private static final String TAG = MainFragment.class.getSimpleName();

    public static final int INPUT_FILE_REQUEST_CODE = 1;
    public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";

    private WebView mWebView;
    private ValueCallback<Uri[]> mFilePathCallback;
    private String mCameraPhotoPath;

    public MainFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);

        // Get reference of WebView from layout/activity_main.xml
        mWebView = (WebView) rootView.findViewById(R.id.fragment_main_webview);

        setUpWebViewDefaults(mWebView);

        // Check whether we're recreating a previously destroyed instance
        if (savedInstanceState != null) {
            // Restore the previous URL and history stack
            mWebView.restoreState(savedInstanceState);
        }

        mWebView.setWebChromeClient(new WebChromeClient() {
            public boolean onShowFileChooser(
                    WebView webView, ValueCallback<Uri[]> filePathCallback,
                    WebChromeClient.FileChooserParams fileChooserParams) {
                if(mFilePathCallback != null) {
                    mFilePathCallback.onReceiveValue(null);
                }
                mFilePathCallback = filePathCallback;

                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                    // Create the File where the photo should go
                    File photoFile = null;
                    try {
                        photoFile = createImageFile();
                        takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                    } catch (IOException ex) {
                        // Error occurred while creating the File
                        Log.e(TAG, "Unable to create Image File", ex);
                    }

                    // 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;
            }
        });

        // Load the local index.html file
        if(mWebView.getUrl() == null) {
            mWebView.loadUrl("file:///android_asset/www/index.html");
        }

        return rootView;
    }
// add these two to solve orientation Issue.. as U already know...

@Override
public void onSaveInstanceState(Bundle outState){
    super.onSaveInstanceState(outState);
    webView.saveState(outState);
}

@Override
public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
}


    private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").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;
    }


    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setUpWebViewDefaults(WebView webView) {
        WebSettings settings = webView.getSettings();

        // Enable Javascript
        settings.setJavaScriptEnabled(true);

        // Use WideViewport and Zoom out if there is no viewport defined
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);

        // Enable pinch to zoom without the zoom buttons
        settings.setBuiltInZoomControls(true);

        if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
            // Hide the zoom controls for HONEYCOMB+
            settings.setDisplayZoomControls(false);
        }

        // Enable remote debugging via chrome://inspect
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WebView.setWebContentsDebuggingEnabled(true);
        }

        // We set the WebViewClient to ensure links are consumed by the WebView rather
        // than passed to a browser if it can
        mWebView.setWebViewClient(new WebViewClient());
    }

    @Override
    public void onActivityResult (int requestCode, int resultCode, Intent data) {
        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) {
                // 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;
        return;
    }
}
Related Posts Related Posts :
  • How do I add arrays to an Arraylist of Arrays (Arraylist<Integer[]>)
  • Trying to remove a tuple using a prepared statement
  • Best/recommended way to convert Java 8 OffsetDateTime to localized string on android
  • Print a String n times using recursion
  • I have a Jtable with a button in one of the columns and I want to access the value in the 1st column when I press the bu
  • Generating source code with a gradle task based on existing classes with annotations on them
  • a subclass for specifying a generic shows bound mismatch
  • Static Variable with null reference
  • painting string in the middle of a given size cell java
  • Displaying column in tableView
  • What does <+ mean in Java?
  • What cplex function I have to use to write this variable?
  • Java ConcurrentHashSet - iterating over it in a multi-threaded environment
  • Can't seem to get my Java to work in VS Code
  • I don't understand the function of "count++"
  • What are the possibilities to design an API that needs overloads depending on a generic type?
  • Can't connect to Apache Ignite Cluster on AWS EC2 - Ignite server rejects clients
  • Trying to understand garbage collection in java
  • Is there a way to associate an ArrayList with another ArrayList with a one to many relationship?
  • Generate List with Combination of Subset of List, Java
  • Getting Illegal State Exception in Regex
  • Shuffling an Array (Java)
  • Tomcat v 9.0 - Public Key Retrieval is not allowed
  • Clarification on why this code is resulting in false and not true
  • Adding a log function to the java calculator program
  • Any elegant way to parse camel-style string to upper case enum in java?
  • how to download a csv file written in local computer using java
  • JCR SQL2 query: binding of ISDESCENDANTNODE param
  • Difference between db.isopen and db != null
  • How to consume the inconsistent json structure for the same key using jackson (com.fasterxml.jackson)?
  • What is the location of file that is read?
  • Need suggestion on coding practices on the concept "Do Not Repeat Yourself"
  • Simple java ticketing system in netbeans
  • System.lineSeparator() does not work in Linux environment
  • Is it sensible to use the hash code of a class as its serialVersionUID?
  • "Heap size" is growing way faster than "Used heap"
  • Android extract array of properties of array of objects
  • How do i link a JAVA 8 backend to an Angular frontend?
  • How to get/set application name in .dxf for Groupcode 1001?
  • Constantly updating and changing text in a JLabel
  • Export csv file in browser
  • Why does hashCode() function generate an error
  • Is it possible to timeout java method?
  • How to format a number based on locale, while retaining all decimal points?
  • Camunda deploy Delegate with global visibility
  • Listing files with specific extension inside a directory: how to handle fake duplicates
  • Different look and feel of java application from the look and feel of Operating System
  • Springboot app is up but POST request always return "not found"
  • new array list created everytime function is called recursively
  • Add a header to an outgoing request by a filter in WebFlux
  • Why "FormDataMultiPart" type parameter is treated differently
  • DateTimeFormatter and SimpleDateFormat produce different strings
  • How to use ExecuteService with custom Threads that contain a AutoCloseable resource
  • If a reference variable is set to null does it still consume memory?
  • Generate title cased fields with JPA/Spring Boot on Postgres
  • RestTemplate mapping Page 'Page size must not be less than one'
  • Using RandomAccessFile along with BufferedReader to speed up file read
  • Why does my code result in a compiler error?
  • Duplicate items added in ConcurrentSkipListSet
  • Kafka's JsonDeserializer not working for java.util.Map
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk