Fiz um aplicativo para abrir meu site responsivo utilizando o WebView do Android Studio. Roda ok, mas quando preciso enviar algum arquivo pelo site, tirar uma foto e salvar, não abre a câmera! Alguém já passou por isso?
TelaPrincipal.java
package strikebrasil.sistemastkbr;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class TelaPrincipal extends ActionBarActivity{
private WebView view;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.telaprincipal);
view = (WebView) this.findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new MyBrowser());
view.loadUrl("https://strikebrasil.gmpe.com.br/login"); //try js alert
view.setWebChromeClient(new WebChromeClient()); // adding js alert support
/*view.getSettings().setJavaScriptEnabled(true);*/
view.getSettings().setSaveFormData(true);
view.getSettings().setBuiltInZoomControls(true);
view.setWebViewClient(new WebViewClient());
class MyWebViewClient extends WebViewClient
{
@Override
//show the web page in webview but not in web browser
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl (url);
return true;
}
}
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
//ketika disentuh tombol back
if ((keyCode == KeyEvent.KEYCODE_BACK) && view.canGoBack()) {
view.goBack(); //method goback() dieksekusi untuk kembali pada halaman sebelumnya
return true;
}
// Jika tidak ada history (Halaman yang sebelumnya dibuka)
// maka akan keluar dari activity
return super.onKeyDown(keyCode, event);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TelaPrincipal">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
telaprincipal.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/webView"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />