我尝试了很多方法在android webview中上传文件,但我无法做到。 我也试过了爱情链接。
HTML file input in android webview (android 4.4, kitkat)
http://www.apexkomenerji.com/m/teklifal.aspx 是我的链接。
有人可以为我提供所有Android版本的基本示例。 (棒棒糖,kitkat等)
这是我的MainActivity:
package com.hemoliz;
import java.util.Timer;
import java.util.TimerTask;
import com.hemoliz.R;
import android.app.AlertDialog.Builder;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;
public class MainActivity extends Activity {
private WebView wv;
private ProgressDialog mProgressDialog;
ImageButton news,forum,msg,acc;
public void onBackPressed (){
if (wv.isFocused() && wv.canGoBack()) {
wv.goBack();
}
else {
openMyDialog(null);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Uygulamamızı tam ekran yapmak için alttaki kodları ekliyoruz
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
if(internetAccess()){
{
//İNTERNET ERİŞİMİ VARSA YAPILACAK İŞLEMLER
wv = (WebView) findViewById(R.id.tarayici);
wv.setVerticalScrollBarEnabled(false);
wv.setHorizontalScrollBarEnabled(false);
wv.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return (event.getAction() == MotionEvent.ACTION_MOVE);
}
});
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
mProgressDialog = ProgressDialog.show(this, "Yükleniyor",
"İçerik Yüklenirken Lütfen Bekleyiniz.");
wv.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url); //
return true;
}
public void onPageFinished(WebView view, String url) {
if (mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
}
}); // linkleri uygulama içinde açar.
try {
// load the url
wv.loadUrl("http://www.apexkomenerji.com/m/teklifal.aspx");
} catch (Exception e) {
e.printStackTrace();
} // uygulamanın açmasını istediğimiz sayfa.
}
}else{
{
//İNTERNET ERİŞİMİ YOKSA YAPILACAK İŞLEMLER
Toast.makeText(getApplicationContext(), "Internet Bağlantınızı Kontrol Ediniz, Uygulama Kapanacaktır.",
Toast.LENGTH_LONG).show();
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
android.os.Process.killProcess(android.os.Process.myPid());
// This will kill your app after 5 seconds...
}
}, 5000);
}
}
}
public boolean internetAccess(){
ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {
return true;
} else {
return false;
}
}
public void openMyDialog(View view) {
showDialog(10);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 10:
// Create our AlertDialog
Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Çıkmak İstediğinizden Emin Misiniz ?")
.setCancelable(true)
.setPositiveButton("Evet",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// Ends the activity
MainActivity.this.finish();
}
})
.setNegativeButton("Hayır",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
}
});
return builder.create();
}
return super.onCreateDialog(id);
}
}