" name="description" /> " />
14140

Camera allow doesn't work android webview

Question:

I am trying to create a webview app. I tried to add the access to manifest but it didn't change anything. On the chrome browser the camera works, I can't understand what should I do.

<strong>1. This is the manifest:</strong>

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="i.astiapp.astiappadmindev"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" android:required="true" /> <uses-feature android:name="android.hardware.camera.front" android:required="true" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" /> <!-- My Location --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:screenOrientation="portrait" android:name=".MainActivity"> </activity> <activity android:hardwareAccelerated="true" android:name=".SplashActivity" android:screenOrientation="portrait" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /></intent-filter> </activity> </application> </manifest>

<strong>2. Main Activity</strong>

import android.graphics.Bitmap; import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.webkit.PermissionRequest; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ProgressBar; public class MainActivity extends AppCompatActivity implements MyWebChromeClient.ProgressListener{ private ProgressBar chromeProgressBar; WebView myWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myWebView = (WebView) findViewById(R.id.webview); //chromeProgressBar = (ProgressBar) findViewById(R.id.progressBarChrome); //Settings WebSettings webSettings = myWebView.getSettings(); myWebView.getSettings().setTextSize(WebSettings.TextSize.NORMAL); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { webSettings.setAllowUniversalAccessFromFileURLs(true); webSettings.setAllowFileAccessFromFileURLs(true); } webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setAllowFileAccess(true); //webSettings.setLoadsImagesAutomatically(true); //inizialize client //load website by URL myWebView.loadUrl("https://www.voyage-app.eu/asti-app/admin/index.php"); //register token for notification // this.onStart(); chromeProgressBar = (ProgressBar) findViewById(R.id.progressBar); myWebView.setWebChromeClient(new WebChromeClient() { // Grant permissions for cam @Override public void onPermissionRequest(final PermissionRequest request) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { request.grant(request.getResources()); } } }); myWebView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); chromeProgressBar.setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); chromeProgressBar.setVisibility(View.GONE); } }); } @Override public void onUpdateProgress(int progressValue) { chromeProgressBar.setProgress(progressValue); if (progressValue == 100) { chromeProgressBar.setVisibility(View.INVISIBLE); } } public class WebViewController extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } @Override public void onBackPressed() { if(myWebView.canGoBack()) myWebView.goBack(); else super.onBackPressed(); } }

I don't think I should post the PHP file since on the chrome browser the page works. It happens like this:

<ul><li>You enter the page</li> <li>Chrome browers asks you to give you the permission to the camera</li> <li>The camera starts working</li> </ul>

Answer1:

Fixed it. I had to add the permession to the code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int hasCameraPermission = checkSelfPermission(Manifest.permission.CAMERA); List<String> permissions = new ArrayList<String>(); if (hasCameraPermission != PackageManager.PERMISSION_GRANTED) { permissions.add(Manifest.permission.CAMERA); } if (!permissions.isEmpty()) { requestPermissions(permissions.toArray(new String[permissions.size()]), 111); } }

But for this to work I had to add the manifest file too:

import android.Manifest;

Recommend

  • APK 0 (zero) Device compatibility
  • MapView: Could not find class A referenced from method B
  • Linux java wrapper and installer
  • draw a B+ tree in latex
  • Load image without autoscaling in Android
  • Scrolling News Ticker Jquery - Issues
  • Using extern @class in order to add a category?
  • “A GKScore must specify a leaderboard.”
  • Winforms: Add a close “x” button in a UserControl
  • c# winform DrawToBitmap offscreen
  • How to discover Font Type?
  • How can go in last activity with resume button?
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • Python ImageIO Gif Set Delay Between Frames
  • Enabling DTD support in Sql Server
  • Center align outputs in ipython notebook
  • Implementing “partial void” in VB
  • python script hangs on input method when running spark
  • Sending HTML Form Data to Spring REST Web Service
  • How to generate and display a QR Code in ionic 2
  • pyodbc doesn't report sql server error
  • Android application: how to use the camera and grab the image bytes?
  • Using a canvas object in a thread to do simple animations - Java
  • Python urlparse: small issue
  • Dialing with Intent.ACTION_CALL stopps at # in phone number
  • output of program is not same as passed argument
  • Check if a string to interpolate provides expected placeholders
  • what is the difference between the asp.net mvc application and asp.net web application
  • Matplotlib draw Spline from multiple points
  • Why winpcap requires both .lib and .dll to run?
  • Akka Routing: Reply's send to router ends up as dead letters
  • Return words with double consecutive letters
  • retrieve vertices with no linked edge in arangodb
  • Python: how to group similar lists together in a list of lists?
  • KeystoneJS: Relationships in Admin UI not updating
  • Linking SubReports Without LinkChild/LinkMaster
  • unknown Exception android
  • Checking variable from a different class in C#
  • Busy indicator not showing up in wpf window [duplicate]
  • Python/Django TangoWithDjango Models and Databases