在webview中上传角度站点文件不起作用

时间:2018-10-31 10:28:21

标签: android angular webview

Android Webview中的角度站点文件上传不起作用 该网站托管在Angular中,并通过android的webview访问,但选择文件选项不起作用,请提出任何解决方案。我提供了android的Mainactivity类和Angular代码作为文件上传选项。请提出任何解决方案

MainActivity类

 public class MainActivity extends AppCompatActivity {
//Globals
private UIManager uiManager;
private WebViewHelper webViewHelper;
private boolean intentHandled = false;

private final static int FCR = 1;
WebView webView;
private String mCM;
private ValueCallback<Uri> mUM;
private ValueCallback<Uri[]> mUMA;

@SuppressLint({"SetJavaScriptEnabled", "WrongViewCast"})


@Override
protected void onCreate(Bundle savedInstanceState) {
    // Setup Theme
    setTheme(R.style.AppTheme_NoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    webView = findViewById(R.id.webView);
    if (Build.VERSION.SDK_INT >= 23 && (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)) {
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 1);
    }
    assert webView != null;

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccess(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setBuiltInZoomControls(true);
    if (Build.VERSION.SDK_INT >= 21) {
        webSettings.setMixedContentMode(0);
        webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } else if (Build.VERSION.SDK_INT >= 19) {
        webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } else if (Build.VERSION.SDK_INT < 19) {
        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    webView.setWebChromeClient(new WebChromeClient() {
        public boolean onShowFileChooser(
                WebView webView, ValueCallback<Uri[]> filePathCallback,
                WebChromeClient.FileChooserParams fileChooserParams) {

            if (mUMA != null) {
                mUMA.onReceiveValue(null);
            }

            mUMA = filePathCallback;
            // Intent takePictureIntent = new 
          Intent(MediaStore.ACTION_IMAGE_CAPTURE);


              Intent contentSelectionIntent = new 
              Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("*/*");
            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, FCR);

            return true;
        }
    });




    // Setup Helpers
    uiManager = new UIManager(this);
    webViewHelper = new WebViewHelper(this, uiManager);

    // Setup App
    webViewHelper.setupWebView();
    uiManager.changeRecentAppsIcon();







    // Check for Intents
    try {
        Intent i = getIntent();
        String intentAction = i.getAction();
        // Handle URLs opened in Browser
         if (!intentHandled && intentAction != null && intentAction.equals(Intent.ACTION_VIEW)){
                Uri intentUri = i.getData();
                String intentText = "";
                if (intentUri != null){
                    intentText = intentUri.toString();
                }
                // Load up the URL specified in the Intent
                if (!intentText.equals("")) {
                    intentHandled = true;
                    webViewHelper.loadIntentUrl(intentText);
                }
         } else {
             // Load up the Web App
             webViewHelper.loadHome();
    }
    } catch (Exception e) {
        // Load up the Web App
        webViewHelper.loadHome();
    }
}

@Override
protected void onPause() {
    webViewHelper.onPause();
    super.onPause();
}

@Override
protected void onResume() {
    webViewHelper.onResume();
    // retrieve content from cache primarily if not connected
    webViewHelper.forceCacheIfOffline();
    super.onResume();
}

// Handle back-press in browser
@Override
public void onBackPressed() {
    if (!webViewHelper.goBack()) {
        super.onBackPressed();
    }
}

}

角度代码

                                                
                   <div class="col-xl-2 col-lg-2 col-md-2 col-sm-2 col-12" *ngIf = "toggle">
                     <button [disabled]="!selectedFilesTwo"
                     (click)="uploadTwo()" type="submit" >
                       <strong>Upload</strong>
                     </button>
                   </div>

....

0 个答案:

没有答案