我该如何通过webView应用程序android上传图片。这是我的应用程序

时间:2018-11-10 02:30:16

标签: android android-studio

我想通过网络视图应用程序上传图像。

这是我的清单文件

 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CAMERA"/>

    <uses-feature android:name="android.hardware.camera" android:required="true" />

这是我的家庭代码

package com.zoorne.zoorne;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class homeActivity extends AppCompatActivity {
    static final int REQUEST_LOCATIION=1;
    LocationManager locationManager;
    private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        locationManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
        getLocation();

        double latti=0.0;
        double longi=0.0;

        if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION)
                != PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATIION);
        }else {
            Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

            if(location != null){
                 latti=location.getLatitude();
                 longi=location.getLongitude();
            }

        }

        webView=(WebView) findViewById(R.id.webview);
        webView.setWebViewClient(new WebViewClient());
        WebSettings webSettings=webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        webSettings.setDomStorageEnabled(true);//added to day
        webSettings.getAllowFileAccess();//added to day
        webSettings.getAllowFileAccessFromFileURLs();//added to day
        webSettings.getAllowUniversalAccessFromFileURLs();//added to day
        webSettings.getLoadsImagesAutomatically();//added to day

        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webView.loadUrl("http://something`enter code here`.com?type=android&tp=app&lat="+latti+"&long="+longi);
    }

    @Override
    public void onBackPressed() {
        if(webView.canGoBack()){
            webView.goBack();
        }else {
            super.onBackPressed();
        }

    }

    public void getLocation(){

    }

}

这是我的html

<input type="file" id="inputfilecar" name="inputfile" accept="image/*" capture="capture">

0 个答案:

没有答案