Hello. I've implemented the bulletin board through webview using gnuboard as Android Studio. The file attachment function is not working.<Help me.>

Asked 2 years ago, Updated 2 years ago, 43 views

Hello, I'm making an app with Android Studio. (Beginner) It works well on mobile by bringing the Nuboard 5 bulletin board to the fragment as a web view. However, if you click the Attach File button to create a post, it will not work on your mobile. The file attachment function works well when you enter the bulletin board address on the computer. Is there anything I need to add in the Android studio file regarding java? The permission has added a camera and external memory. This is Android sdk version 23.

Or should I modify the php file related to the bulletin board? If I have to fix it, I don't know what to do.I'd appreciate it if you could help me in detail.

android html java

2022-09-22 21:42

1 Answers

In order to activate the file attachment function in Android webview, you must override the openFileChooser and implement it separately. The processing method is different for each Android version. Based on the latest version, you can do it as below.

 private ValueCallback<Uri> mUploadMessage;
private static final int FILECHOOSER_RESULTCODE   = 1000;

webView.setWebChromeClient(new WebChromeClient() {
// In order to work with ICS, you need to put in the method below. 
public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType) {
openFileChooser(uploadFile);
}

public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(Intent.createChooser(intent, "File Chooser"), RC_FILE_CHOOSE );
});

  // If you select a file from the SD card, the onActivityResult below will be called.
    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 
     if(requestCode==FILECHOOSER_RESULTCODE) {  
            if (null == this.mUploadMessage) {
                return;
            }

           Uri result=null;
           try{
                if (resultCode != RESULT_OK) {
                    result = null;
                } } else {

                    result = intent.getData(); 
                } 
            }
            catch(Exception e)
            {
                Toast.makeText(getApplicationContext(), "activity :"+e,
                 Toast.LENGTH_LONG).show();
            }

            mUploadMessage.onReceiveValue(result);
            mUploadMessage = null;

     }
    }


2022-09-22 21:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.