Android WebView Resim İnput Hatası - Son Aşamada Tıkandım.
Merhabalar, öncelikle sorunum Android WebViewde resim dosyalarının yükleme buton çalışmamasıydı. Chrome tarayıcıda çalışan buton webviewde çalışmıyor. manifest dosyamdan gerekli izinleri vermiştim.
Manifest dosyamdaki izinler;
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
Çalıştırmayı bir türlü başaramadım. Birkaç gün önce aynı dertten açılan bir soruyu buldum ancak tam çözülebilmiş değil -----------> https://gelecegiyazanlar.turkcell.com.tr/soru/android-webview-dosya-secme-ve-yukleme
Açılan bu soruda Sayın Ali Karakoç' un bir yorumunu gördüm kendisi webview yapımı hakkında dersinin videosunu atmıştı.
Videoyu açtım adım adım gittim, ancak bir noktadan sonra tıkandım. Kendim bu konulara acemiyim (Yazılım okumadım, Tıp fakültesi öğrencisiyim) pekte işi kıvıramadım. Ancak sizden yardım istiyorum. Video Linki bu kısımdan sonrasında kendi web sitemin mobil görünümünde; resim butonunda ayarlama yapmam gerekiyordu. Sitemin mobile/function.php dosyasından resim butonu ile ilgili kodları buldum onlarda aşağıdalar:
<?php if(ae_get_option('ae_upload_images')){ ?>
<div class="form-post container_upload">
<div class="upload_image" id="mobile_images_upload_container">
<a href="javascript:void(0)" id="mobile_images_upload_browse_button"><i class="fa fa-image"></i><?php _e("Resim Yükle", ET_DOMAIN); ?></a>
<span class="et_ajaxnonce" id="<?php echo wp_create_nonce( 'et_upload_images' ); ?>></span>
<span id="mobile_images_upload_text">
<?php
global $max_file_size;
printf(__(" 64 MB den düşük dosya yükleyin.", ET_DOMAIN),$max_file_size);
?>
</span>
</div>
</div>
En Son Olarak da, MainActivity.java dosyamda aşağıda
package com.melihve.eksitus;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.DownloadListener;
import android.webkit.HttpAuthHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import static android.app.Activity.RESULT_OK;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.File;
import android.app.Activity;
import android.app.DownloadManager;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.webkit.ConsoleMessage;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.PluginState;
import android.widget.Toast;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.JsResult;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.content.Intent;
import android.net.Uri;
import android.webkit.DownloadListener;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
import java.io.File;
import java.net.URL;
import java.util.Date;
@SuppressLint({"SetJavaScriptEnabled","addJavascriptInterface","JavascriptInterface"})
public class MainActivity extends Activity {
private WebView tarayici;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
if(InternetConnectivity.isConnected(getApplicationContext())){
}else {
new AlertDialog.Builder(MainActivity.this)
.setTitle("Uyarı")
.setMessage("Bağlantı hatası, lütfen internet bağlantınızı kontrol ediniz.")
.setPositiveButton("Tamam", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
finish();
}
}) .setCancelable(false).show();
}
tarayici = (WebView) findViewById(R.id.lcd);
tarayici.getSettings().setJavaScriptEnabled(true);
tarayici.setWebViewClient(new WebViewClient());
class JsObject {
@JavascriptInterface
public String toString() { return "injectedObject"; }
}
tarayici.addJavascriptInterface(new tarayiciAppInterface(this), "Android");
tarayici.setWebChromeClient(new WebChromeClient());
tarayici.loadUrl("http://www.eksitus.net/");
tarayici.setWebViewClient(new WebViewClient());
tarayici.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
tarayici.getSettings().setJavaScriptEnabled(true);
tarayici.addJavascriptInterface(new WebViewInterface(), "AndroidErrorReporter");
final ProgressDialog progress = ProgressDialog.show(this, "EksiTUS - Geleceğe Yön Verenler", "Yükleniyor....", true);
progress.show();
tarayici.setWebViewClient(new WebViewClient() {
@SuppressLint({"SetJavaScriptEnabled","addJavascriptInterface","JavascriptInterface"})
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Toast.makeText(getApplicationContext(), "Sayfa yüklendi", Toast.LENGTH_SHORT).show();
progress.dismiss();
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "İnternet Bağlantısında Bir hata oluştu", Toast.LENGTH_SHORT).show();
progress.dismiss();
}
});
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
tarayici.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
if (!v.hasFocus()) {
v.requestFocus();
}
break;
}
return false;
}
});
}
@Override
public void onBackPressed() {
if (tarayici.canGoBack()) {
tarayici.goBack();
} else
super.onBackPressed();
}
private void callJavaScript(String methodName, Object... params) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("javascript:try{");
stringBuilder.append(methodName);
stringBuilder.append("(");
for (int i = 0; i < params.length; i++) {
Object param = params[i];
if (param instanceof String) {
stringBuilder.append("'");
stringBuilder.append(param);
stringBuilder.append("'");
}
if (i < params.length - 1) {
stringBuilder.append(",");
}
}
stringBuilder.append(")}catch(error){Android.onError(error.message);}");
tarayici.loadUrl(stringBuilder.toString());
}
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("Main Page") // TODO: Define a title for the content shown.
// TODO: Make sure this auto-generated URL is correct.
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}
private class WebViewInterface {
@JavascriptInterface
public void onError(String error) {
throw new Error(error);
}
}
class tarayiciClient extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
tarayici.loadUrl(url);
return true;
}
}
public class tarayiciAppInterface {
Context mContext;
/**
* Instantiate the interface and set the context
*/
tarayiciAppInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void ac() {
}
}
}