Detectar Geolocalización en un WebView

Realicé una página web con PHP y Laravel, la misma detecta la ubicación actual de la persona cuando se toca el ícono “Detectar ubicación”.

introducir la descripción de la imagen aquí

Ahora lo que hice fue generar la .apk en Android Studio desde un Web View, la página se ve y funciona perfecto pero lo único que no me funciona es la detección de la ubicación actual. Cuando lo toco desde el celular me debería preguntar si le doy permisos de ubicación, pero no lo hace.

Dejo una captura de la app que saque con mi celular:

introducir la descripción de la imagen aquí

Este es el código de Android con el que intenté que esto funcione pero sin éxito:

Android Manifest

<?xml version="1.0" encoding="utf-8"?> <manifest package="com.example.app" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>  <application     android:allowBackup="true"     android:fullBackupContent="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:theme="@style/AppTheme"     tools:ignore="GoogleAppIndexingWarning">     <activity         android:name="com.example.app.MainActivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.MAIN" />             <category android:name="android.intent.category.LAUNCHER" />         </intent-filter>     </activity> </application> </manifest> 

Main Activity

import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.webkit.GeolocationPermissions; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient;  public class MainActivity extends Activity {  WebView mWebView;  public class GeoWebViewClient extends WebViewClient {     @Override     public boolean shouldOverrideUrlLoading(WebView view, String url) {         view.loadUrl(url);         return true;     } }  public class GeoWebChromeClient extends WebChromeClient {     @Override     public void onGeolocationPermissionsShowPrompt(String origin,                                                    GeolocationPermissions.Callback callback) {         callback.invoke(origin, true, false);     } }  @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);      mWebView = findViewById(R.id.activity_main_webview);      mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);     mWebView.getSettings().setBuiltInZoomControls(true);     mWebView.setWebViewClient(new GeoWebViewClient());      mWebView.getSettings().setJavaScriptEnabled(true);     mWebView.getSettings().setGeolocationEnabled(true);     mWebView.setWebChromeClient(new GeoWebChromeClient());     mWebView.setWebViewClient(new WebViewClient());      mWebView.loadUrl("https://salefulbito.ml");      @Override public void onBackPressed() {     if(mWebView.canGoBack()) {         mWebView.goBack();     } else {         super.onBackPressed();     } }  } 

WebView.java

import android.content.Intent; import android.net.Uri; import android.webkit.WebView; import android.webkit.WebViewClient;  class MyWebViewClient extends WebViewClient {  @SuppressWarnings("deprecation") @Override public boolean shouldOverrideUrlLoading(WebView view, String url) {     Uri uri = Uri.parse(url);     if (uri.getHost() != null && uri.getHost().contains("salefulbito.ml")) {         return false;     }      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));     view.getContext().startActivity(intent);     return true; } } 

Android System WebView

I am trying to run an app called Fully Kiosk Browser, to lock down to a single specific web page. This is on an Android TV Box, running Android 7.1.2 However, when my web page does not load in the app.

I contacted the support staff, but the best they could do is suggest updating to Amazon System WebView 73. I have now installed this from the app store, but this has not updated the ASWV already in System app – sat on Version 52. Instead, it has installed an additional version of ASWV (version 73) in my downloaded apps. So now I have 2. (whilst I was at it, I also updated chrome to v73 just incase – and the web page loads in this just fine).

My trouble now is that the fully kiosk is only seeing the original 52 version in the system apps, and not the new additional one. It appears I can not delete it the original, and disabling it has not worked.

I’m confused why the update has not written over the original pre-installed version, and I’ve ended up with 2 copies and can’t choose which one I want to use!

Let ‘web-view’ mobile iOS/Android app talk consume/feed a Drupal 8 site

I have a Drupal 8 site with below installed modules:

  • HAL
  • HTTP Basic Authentication
  • REST UI
  • RESTful Web Services
  • Serialization

Using the REST UI module, I have configured the below:

Settings for resource User

Granularity – Resource

Methods – GET – POST – PATCH

Accepted request formats – json

Authentication providers – basic_auth – cookie

I have also created an IOS & Android web-view app.

Also, I am using the Firebase module to send ‘Push Notifications’ to registered users on the website on specific events (such as: Send a push notification to the ‘node author’ whenever his node is updated)

I know that I have to pass a unique token of the mobile device used by the logged in user and store it on my Drupal site.

for that, I have created the text field field_user_push_token on the user profile page (/admin/config/people/accounts/fields) in order to store the token received from the mobile device of the user.

The big question:

How to transfer the token from the mobile device to my Drupal site (specifically to the field_user_push_token field) ?

I believe the using of the method: PATCH will do the trick… but how ?

am I on the right track by using the RESTful Web Services or there is a better method ?

Webview and the problem of opening/downloading PDF files [on hold]

I am new to Android programming. My question may be very basic (or may be stupid for the experienced programmers). However, I am really having problem to solve this issue. Your help will be a great for new Android programmer.

I am making an app which runs website in it (Hybrid App). Webview shows the website perfectly. Everything is working fine, except that the PDF files are not opening or downloading. On website these PDF files open and download perfectly. But in app clicking the link does nothing, PDF does not open neither downloads. Can anyone provide me a solution so that I may able to complete this app.

(Android Studio) WebView fica carrega a página e não abre

Estou fazendo uma aplicação que reúne alguns site, porem alguns deles fica carregando no WebView e não abre. Como exemplo vou usar o site da UrPay. Já vi esse site sendo aberto por outro aplicativo, por sinal abre normalmente como se você no Google Chrome.

Arquivo .xml

android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Mibank_Activity">   <WebView     android:id="@+id/webview_Urpay"     android:layout_width="match_parent"     android:layout_height="match_parent" /> 

Arquivo .java

private WebView webView;  @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_urpay_);      setTitle("URPAY");      webView = (WebView) findViewById(R.id.webview_Urpay);     WebSettings webSettings = webView.getSettings();     webSettings.setJavaScriptEnabled(true);     webView.setWebViewClient(new WebViewClient());     webView.loadUrl("https://conta.urpay.com.br/entrar"); } 

O site fica carregando e nunca abre. Isso seria configuração do meu WebView?

Amazing travel affiliated App From Sdk Or Webview for $100

travel-payout is an affiliated website from which you can earn moneyi will create app for you from which you can earn money more people install your app and use it…more you Earni will create flight sdk app for you simple onecustomize onei will create Unique app for you with travel-payout api also… so what are you waiting for.. Note: Discuss your application idea before submitting an order.

by: alyabbasi93
Created: —
Category: Programming
Viewed: 192


Android Webview: Smaller Display Size Breaks Layout

I have an app that’s basically just displaying mobile website in an Android Webview, with some native bits for handling notification & navigation headers.

The issue is, when I change the Display Size setting (under Display) in an Android phone to anything smaller than Default, the content will be squeezed to the right side and left a blank space. I did a check with dev tool, and somehow the CSS’s width is set to 66.67% of parent’s by Android (in default it’s 100%) & a minor left padding is also added. However, if the Display Size setting is larger than default, there is none / very minor style degradation.

The interesting part is when similar app is made in iOS (just display mobile site), there’s no issue at all after changing the Display Size. So I’m pretty certain that the fix is limited to Android.

Is there any guidance to add code to anticipate these changes, or at least, completely disable the Display Size setting’s effects?

Permitir abrir popups dentro da webview no Android Studio

Olá! Estou criando uma webview e estou com um problema para abrir popups dentro da webview. Se eu abrir o site que estou usando no navegador google chrome, e clicar nesses links, o navegador me pede para permitir popups. Gostaria de reproduzir essa permissão dentro da webview. Esta é minha main activity:

import android.Manifest; import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.net.Uri; import android.os.Build; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.webkit.DownloadListener; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast;   public class MainActivity extends AppCompatActivity {      WebView printpagew;     //Classes do Upload da Imagem     private ValueCallback<Uri> mUploadMessage;     public ValueCallback<Uri[]> uploadMessage;     public static final int REQUEST_SELECT_FILE = 100;     private final static int FILECHOOSER_RESULTCODE = 1;     //Fim Classes do Upload da Imagem          //Classes de Refresh da Pagina     private SwipeRefreshLayout layoutRefresh;     //Fim Classes de Refresh da Pagina      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          printpagew = findViewById(R.id.myWebView);         layoutRefresh = this.findViewById(R.id.swipeLayout);  //refresh da webview         printpagew.loadUrl("https://gip.portolink.com/login/print"); // link de acesso         printpagew.loadUrl( "javascript:window.location.reload( true )" );         printpagew.getSettings().setAllowFileAccess(true);         WebSettings webSettings = printpagew.getSettings();         webSettings.setSaveFormData(true);         printpagew.getSettings().setCacheMode (WebSettings.LOAD_NO_CACHE); //nao carrega cache na apl         printpagew.getSettings().setAppCacheEnabled(true);         printpagew.getSettings().setPluginState(WebSettings.PluginState.ON);// libera o acesso aos plugins na webview         printpagew.getSettings().setLoadWithOverviewMode(true);  //ajusta a largura da pagina.         printpagew.getSettings().setSupportZoom(true);        // suporte a zoom         printpagew.getSettings().setBuiltInZoomControls(true); // permitir aplicar ao zooom         printpagew.getSettings().setDisplayZoomControls(false); // desativar os controles de zoom padrão na página         printpagew.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);  // barra de rolagem         printpagew.getSettings().setDomStorageEnabled(true);  // API de armazenamento DOM         printpagew.getSettings().setUseWideViewPort(true);   // Habilita layout responsivo         printpagew.getSettings().setLoadWithOverviewMode(true);  // Diminuir o zoom se a largura do conteúdo for maior que a viewport           // Habilita JavaScript         printpagew.getSettings().setJavaScriptEnabled(true);         // Fim Habilita JavaScript           // Executa navegador dentro da WebView         printpagew.setWebViewClient(new WebViewClient());         printpagew.setWebChromeClient(new WebChromeClient());         // Fim Executa navegador dentro da WebView           // Refresh da Pagina         layoutRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {             @Override             public void onRefresh() {                 if (printpagew.getUrl() != null) {                     printpagew.reload(); // write what happens after swipe refreshing                 }                 layoutRefresh.setRefreshing(false); //this line hides the refresh button after completing             }         });         // Fim Refresh da Pagina           // Download no app         printpagew.setDownloadListener(new DownloadListener() {             @Override             public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {                 Uri myUri = Uri.parse(url);                 Intent superIntent = new Intent(Intent.ACTION_VIEW);                 superIntent.setData(myUri);                 startActivity(superIntent);             }         });         // Fim Download no app           //Upload da imagem dentro da Web View         String permission = Manifest.permission.CAMERA;         int grant = ContextCompat.checkSelfPermission(this, permission);         if (grant != PackageManager.PERMISSION_GRANTED) {             String[] permission_list = new String[1];             permission_list[0] = permission;             ActivityCompat.requestPermissions(this, permission_list, 1);         }         printpagew.setWebChromeClient(new WebChromeClient()         {             // Para Android 3.0+ Devices             protected void openFileChooser(ValueCallback uploadMsg, String acceptType)             {                 mUploadMessage = uploadMsg;                 Intent i = new Intent(Intent.ACTION_GET_CONTENT);                 i.addCategory(Intent.CATEGORY_OPENABLE);                 i.setType("image/*");                 startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE);             }             // Para Android Lollipop 5.0+ Devices             @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)             public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)             {                 if (uploadMessage != null) {                     uploadMessage.onReceiveValue(null);                     uploadMessage = null;                 }                  uploadMessage = filePathCallback;                  Intent intent = fileChooserParams.createIntent();                 try                 {                     startActivityForResult(intent, REQUEST_SELECT_FILE);                 } catch (ActivityNotFoundException e)                 {                     uploadMessage = null;                     Toast.makeText(MainActivity.this.getApplicationContext(), "Cannot Open File Chooser", Toast.LENGTH_LONG).show();                     return false;                 }                 return true;             }             //Para Android 4.1 only             protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)             {                 mUploadMessage = uploadMsg;                 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);                 intent.addCategory(Intent.CATEGORY_OPENABLE);                 intent.setType("image/*");                 startActivityForResult(Intent.createChooser(intent, "File Browser"), FILECHOOSER_RESULTCODE);             }              protected void openFileChooser(ValueCallback<Uri> uploadMsg)             {                 mUploadMessage = uploadMsg;                 Intent i = new Intent(Intent.ACTION_GET_CONTENT);                 i.addCategory(Intent.CATEGORY_OPENABLE);                 i.setType("image/*");                 startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);             }         });      }      @Override     public void onActivityResult(int requestCode, int resultCode, Intent intent)     {         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)         {             if (requestCode == REQUEST_SELECT_FILE)             {                 if (uploadMessage == null)                     return;                 uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));                 uploadMessage = null;             }         }         else if (requestCode == FILECHOOSER_RESULTCODE)         {             if (null == mUploadMessage)                 return;             Uri result = intent == null || resultCode != MainActivity.RESULT_OK ? null : intent.getData();             mUploadMessage.onReceiveValue(result);             mUploadMessage = null;         }         else             Toast.makeText(MainActivity.this.getApplicationContext(), "Failed to Upload Image", Toast.LENGTH_LONG).show();     }     //Fim Upload dentro da WebView        // Classe shouldOverrideUrlLoading / onPage / onkey     private class HelloWebViewClient extends WebViewClient{           @Override         public void onPageStarted(WebView view, String url, Bitmap favicon) {             // TODO Auto-generated method stub             super.onPageStarted(view, url, favicon);         }          @Override         public boolean shouldOverrideUrlLoading(WebView webView, String url)         {             webView.loadUrl(url);             return false;         }          @Override         public void onPageFinished(WebView view, String url) {             // TODO Auto-generated method stub             super.onPageFinished(view, url);          }      }      @Override     public boolean onKeyDown(int keyCode, KeyEvent event)     { //if back key is pressed         if((keyCode == KeyEvent.KEYCODE_BACK)&& printpagew.canGoBack())         {             printpagew.goBack();             return true;          }          return super.onKeyDown(keyCode, event);      }     // Fim Classe shouldOverrideUrlLoading / onPage / onkey      }