Reputation: 1494
Is there a way to give my android app camera access permission with AdvancedWebView?
It is possible with native webview, but the native do not allow file upload through < input type="file" >, so now I have the file upload working, but no camera.
Main code:
public class MainActivity extends ActionBarActivity implements AdvancedWebView.Listener {
private AdvancedWebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (AdvancedWebView) findViewById(R.id.webview);
mWebView.setListener(this, this);
mWebView.setGeolocationEnabled(true);
mWebView.loadUrl(url);
}
}
The
mWebView.setGeolocationEnabled(true);
line gives the location permission just fine, is there something like that for the video?
Upvotes: 3
Views: 6232
Reputation: 1494
Manage to make it work! Once you have your camera capture working in webbrowser, to grant the camera permission:
public void iniciaWebView(){
mWebView = (AdvancedWebView) findViewById(R.id.webview);
mWebView.setListener(this, this);
mWebView.setGeolocationEnabled(true);
mWebView.addHttpHeader("X-Requested-With", appNomeLogs);
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onPermissionRequest(final PermissionRequest request) {
Log.i(appNomeLogs, "|> onPermissionRequest");
MainActivity.this.runOnUiThread(new Runnable(){
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void run() {
Log.i(appNomeLogs, "|> onPermissionRequest run");
request.grant(request.getResources());
}// run
});// MainActivity
}// onPermissionRequest
});// setWebChromeClient
mWebView.loadUrl(url);
}// iniciaWebView
Manifest:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
Only tested in android 5 so far.
Upvotes: 5