Web View working in only a few versions of Lollipop - android

i am working on web view,but the web view is opening in only lollipop 5.1 version and it is not opening in other versions of lollipop and in higher versions of android.I also gave all permissions in the manifest file.any help would be appreciated.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.colorssoftware.sdfg">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<user-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<permission android:name="android.permission.FLASHLIGHT"
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="normal" />
<uses-feature android:name="android.hardware.audio.low_latency" />
<uses-feature android:name="android.hardware.audio.pro" />
<uses-feature android:name="android.hardware.microphone" android:required="true"/>
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.front" android:required="true" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.webkit.PermissionRequest" />
<uses-permission android:name="android.permission.MICROPHONE" />
<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:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
this is main activity
package com.colorssoftware.sdfg;
import android.content.Context;
import android.content.res.Resources;
import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.PermissionRequest;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.NoSuchProviderException;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView htmlWebView = (WebView) findViewById(R.id.webView);
htmlWebView.setWebViewClient(new CustomWebViewClient());
WebSettings webSetting = htmlWebView.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setAllowFileAccessFromFileURLs(true);
webSetting.setAllowUniversalAccessFromFileURLs(true);
webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
webSetting.setDomStorageEnabled(true);
webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
/*webSetting.setBuiltInZoomControls(true);*/
webSetting.setAllowFileAccess(true);
/* webSetting.setSupportZoom(true);
webSetting.setDisplayZoomControls(true);
*/ htmlWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
htmlWebView.requestFocus();
htmlWebView.loadUrl("https://www.colourssoftware.com:3443/\n");
htmlWebView.setWebChromeClient(new WebChromeClient(){
// Need to accept permissions to use the camera
#RequiresApi(api= Build.VERSION_CODES.LOLLIPOP )
#Override
public void onPermissionRequest(final PermissionRequest request) {
Log.d("hhhhhh","onPermissionRequest");
request.grant(request.getResources());
}
});
}
public static Certificate getCertificateForRawResource(int resourceId, Context context) {
CertificateFactory cf = null;
Certificate ca = null;
Resources resources = context.getResources();
InputStream caInput = resources.openRawResource(resourceId);
try {
cf = CertificateFactory.getInstance("X.509","BC");
ca = cf.generateCertificate(caInput);
} catch (java.security.cert.CertificateException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} finally {
try {
caInput.close();
} catch (IOException e) {
Log.e(TAG, "exception", e);
}
}
return ca;
}
public static Certificate convertSSLCertificateToCertificate(SslCertificate sslCertificate) {
CertificateFactory cf = null;
Certificate certificate = null;
Bundle bundle = sslCertificate.saveState(sslCertificate);
byte[] bytes = bundle.getByteArray("x509-certificate");
if (bytes != null) {
try {
CertificateFactory certFactory = CertificateFactory.getInstance("X.509","BC");
Certificate cert = certFactory.generateCertificate(new ByteArrayInputStream(bytes));
certificate = cert;
} catch (java.security.cert.CertificateException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
}
}
return certificate;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class CustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
SslCertificate sslCertificateServer = error.getCertificate();
Certificate pinnedCert = getCertificateForRawResource(R.raw.fullchain, MainActivity.this);
Certificate serverCert = convertSSLCertificateToCertificate(sslCertificateServer);
if(pinnedCert.equals(serverCert)) {
handler.proceed();
} else {
super.onReceivedSslError(view, handler, error);
}
}
}

Related

My Android TV app only works on Android TV emulator (Android Studio)

My Android TV app only works on Android TV Emulator (Android Studio).
When I install the application on my tv box, the application crashes
here is my Androidmanifest and my activity
Androidmanifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.tvonhd.uniplaytvbox">
<uses-feature
android:name="android.software.leanback"
android:required="true" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.tvonhd.uniplaytvbox.ui.activity.ErrorActivity" />
<activity android:name="com.tvonhd.uniplaytvbox.ui.activity.VideoDetailsActivity2" />
<activity android:name="com.tvonhd.uniplaytvbox.ui.activity.VideoDetailsActivity" />
<activity android:name="com.tvonhd.uniplaytvbox.ui.activity.SignUpActivity" />
<activity android:name="com.tvonhd.uniplaytvbox.ui.activity.PlayerActivity" />
<activity android:name="com.tvonhd.uniplaytvbox.ui.activity.LoginActivity" />
<activity android:name="com.tvonhd.uniplaytvbox.ui.activity.ItemGenreActivity" />
<activity android:name="com.tvonhd.uniplaytvbox.ui.activity.ItemCountryActivity" />
<activity android:name="com.tvonhd.uniplaytvbox.ui.activity.ActivationActivity" />
<activity android:name="com.tvonhd.uniplaytvbox.ui.activity.SearchActivity" />
<activity
android:name="com.tvonhd.uniplaytvbox.ui.activity.LeanbackActivity"
android:theme="#style/AppTheme" />
<activity
android:name="com.tvonhd.uniplaytvbox.ui.activity.SplashScreenActivity"
android:banner="#drawable/ic_launcher_tv"
android:icon="#drawable/ic_launcher_tv"
android:roundIcon="#drawable/ic_launcher_tv"
android:logo="#drawable/ic_launcher_tv">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.tvonhd.uniplaytvbox.ui.activity.LoginChooserActivity"
android:screenOrientation="fullSensor"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity android:name="com.tvonhd.uniplaytvbox.MainActivity" />
</application>
</manifest>
here is my activity
activity:
```
package com.tvonhd.uniplaytvbox.fragments;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Toast;
import androidx.fragment.app.FragmentManager;
import androidx.leanback.app.RowsSupportFragment;
import androidx.leanback.widget.ArrayObjectAdapter;
import androidx.leanback.widget.HeaderItem;
import androidx.leanback.widget.ListRow;
import androidx.leanback.widget.ListRowPresenter;
import androidx.leanback.widget.OnItemViewClickedListener;
import androidx.leanback.widget.OnItemViewSelectedListener;
import androidx.leanback.widget.Presenter;
import androidx.leanback.widget.Row;
import androidx.leanback.widget.RowPresenter;
import com.tvonhd.uniplaytvbox.Config;
import com.tvonhd.uniplaytvbox.NetworkInst;
import com.tvonhd.uniplaytvbox.utils.PreferenceUtils;
import com.tvonhd.uniplaytvbox.R;
import com.tvonhd.uniplaytvbox.database.DatabaseHelper;
import com.tvonhd.uniplaytvbox.model.Channel;
import com.tvonhd.uniplaytvbox.model.HomeContent;
import com.tvonhd.uniplaytvbox.model.VideoContent;
import com.tvonhd.uniplaytvbox.network.RetrofitClient;
import com.tvonhd.uniplaytvbox.network.api.HomeApi;
import com.tvonhd.uniplaytvbox.ui.BackgroundHelper;
import com.tvonhd.uniplaytvbox.ui.activity.ErrorActivity;
import com.tvonhd.uniplaytvbox.ui.activity.LeanbackActivity;
import com.tvonhd.uniplaytvbox.ui.activity.PlayerActivity;
import com.tvonhd.uniplaytvbox.ui.activity.VideoDetailsActivity;
import com.tvonhd.uniplaytvbox.ui.presenter.CardPresenter;
import com.tvonhd.uniplaytvbox.ui.presenter.SliderCardPresenter;
import com.tvonhd.uniplaytvbox.ui.presenter.TvPresenter;
import com.tvonhd.uniplaytvbox.utils.PaidDialog;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
public class HomeFragment extends RowsSupportFragment {
private BackgroundHelper bgHelper;
private ArrayObjectAdapter rowsAdapter;
private CardPresenter cardPresenter;
private View v;
private LeanbackActivity activity;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bgHelper = new BackgroundHelper(getActivity());
activity = (LeanbackActivity) getActivity();
activity.showLogo();
setOnItemViewClickedListener(getDefaultItemViewClickedListener());
setOnItemViewSelectedListener(getDefaultItemSelectedListener());
if (new NetworkInst(activity).isNetworkAvailable()) {
loadHomeContent();
} else {
Intent intent = new Intent(activity, ErrorActivity.class);
startActivity(intent);
activity.finish();
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
v = super.onCreateView(inflater, container, savedInstanceState);
return v;
}
private void loadHomeContent() {
final SpinnerFragment mSpinnerFragment = new SpinnerFragment();
final FragmentManager fm = getFragmentManager();
fm.beginTransaction().add(R.id.custom_frame_layout, mSpinnerFragment).commit();
Retrofit retrofit = RetrofitClient.getRetrofitInstance();
HomeApi api = retrofit.create(HomeApi.class);
Call<List<HomeContent>> call = api.getHomeContent(Config.API_KEY);
call.enqueue(new Callback<List<HomeContent>>() {
#Override
public void onResponse(Call<List<HomeContent>> call, Response<List<HomeContent>> response) {
if (response.isSuccessful()) {
List<HomeContent> homeContents = response.body();
//Log.d("size:", homeContents.size()+"");
if (homeContents.size() > 0) {
loadRows(homeContents);
} else {
Toast.makeText(getContext(), getResources().getString(R.string.no_data_found), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getContext(), response.errorBody().toString(), Toast.LENGTH_SHORT).show();
}
// hide the spinner
fm.beginTransaction().remove(mSpinnerFragment).commitAllowingStateLoss();
}
#Override
public void onFailure(Call<List<HomeContent>> call, Throwable t) {
t.printStackTrace();
Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
// hide the spinner
getFragmentManager().beginTransaction().remove(mSpinnerFragment).commit();
}
});
}
private void loadRows(List<HomeContent> homeContents) {
rowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
cardPresenter = new CardPresenter();
SliderCardPresenter sliderCardPresenter = new SliderCardPresenter();
TvPresenter tvPresenter = new TvPresenter();
int i;
for (i = 0; i < homeContents.size(); i++) {
ArrayObjectAdapter listRowAdapter;
HeaderItem header;
if (i == 0) {
// load slider
listRowAdapter = new ArrayObjectAdapter(sliderCardPresenter);
header = new HeaderItem(i, "");
} else if (i == 1) {
//load tv layout
listRowAdapter = new ArrayObjectAdapter(tvPresenter);
header = new HeaderItem(i, homeContents.get(i).getTitle());
} else {
listRowAdapter = new ArrayObjectAdapter(cardPresenter);
header = new HeaderItem(i, homeContents.get(i).getTitle());
}
//for (int j = 0; j < NUM_COLS; j++) {
for (int j = 0; j < homeContents.get(i).getContent().size(); j++) {
VideoContent videoContent = homeContents.get(i).getContent().get(j);
if (homeContents.get(i).getType().equalsIgnoreCase("tv")) {
videoContent.setType("tv");
} else if (homeContents.get(i).getType().equalsIgnoreCase("movie")) {
videoContent.setType("movie");
} else if (homeContents.get(i).getType().equalsIgnoreCase("tvseries")) {
videoContent.setType("tvseries");
} else if (homeContents.get(i).getType().equalsIgnoreCase("slider")) {
if (videoContent.getIsTvseries().equals("1")) {
videoContent.setType("tvseries");
} else if (videoContent.getIsTvseries().equals("0")) {
videoContent.setType("movie");
}
}
listRowAdapter.add(videoContent);
}
rowsAdapter.add(new ListRow(header, listRowAdapter));
}
setAdapter(rowsAdapter);
setCustomPadding();
}
private void setCustomPadding() {
// getView().setPadding(Utils.dpToPx(-24, getContext()), Utils.dpToPx(70, getContext()), 0, 0);
}
// click listener
private OnItemViewClickedListener getDefaultItemViewClickedListener() {
return new OnItemViewClickedListener() {
#Override
public void onItemClicked(Presenter.ViewHolder viewHolder, Object o,
RowPresenter.ViewHolder viewHolder2, Row row) {
VideoContent videoContent = (VideoContent) o;
String status = new DatabaseHelper(getContext()).getActiveStatusData().getStatus();
if (videoContent.getType().equals("tv")) {
if (videoContent.getIsPaid().equals("1")) {
if (PreferenceUtils.isValid(getActivity())) {
if (status.equals("active")) {
Intent intent = new Intent(getActivity(), PlayerActivity.class);
intent.putExtra("id", videoContent.getId());
intent.putExtra("videoType", videoContent.getStreamFrom());
intent.putExtra("streamUrl", videoContent.getStreamUrl());
startActivity(intent);
} else {
//subscription is not active
//new PaidDialog(getActivity()).showPaidContentAlertDialog();
PaidDialog dialog = new PaidDialog(getContext());
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
dialog.show();
}
} else {
//saved data is not valid, because it was saved more than 2 hours ago
PreferenceUtils.updateSubscriptionStatus(getActivity());
}
} else {
Intent intent = new Intent(getActivity(), PlayerActivity.class);
intent.putExtra("id", videoContent.getId());
intent.putExtra("videoType", videoContent.getStreamFrom());
intent.putExtra("streamUrl", videoContent.getStreamUrl());
startActivity(intent);
}
} else {
Intent intent = new Intent(getActivity(), VideoDetailsActivity.class);
intent.putExtra("id", videoContent.getId());
intent.putExtra("type", videoContent.getType());
intent.putExtra("thumbImage", videoContent.getThumbnailUrl());
startActivity(intent);
}
}
};
}
//listener for setting blur background each time when the item will select.
protected OnItemViewSelectedListener getDefaultItemSelectedListener() {
return new OnItemViewSelectedListener() {
public void onItemSelected(Presenter.ViewHolder itemViewHolder, final Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
if (item instanceof VideoContent) {
bgHelper = new BackgroundHelper(getActivity());
bgHelper.prepareBackgroundManager();
bgHelper.startBackgroundTimer(((VideoContent) item).getPosterUrl());
} else if (item instanceof Channel) {
bgHelper = new BackgroundHelper(getActivity());
bgHelper.prepareBackgroundManager();
bgHelper.startBackgroundTimer(((Channel) item).getPosterUrl());
}
}
};
}
}
My Android TV app only works on Android TV Emulator (Android Studio). When I install the application on my TV Box, the application crashes. this error is caused by leanback?
Thanks for your help
Make android.software.leanback feature required false.
<uses-feature
android:name="android.software.leanback"
android:required="false" />
If you set the required attribute value to true, your app will run only on devices that use the Leanback UI.

android studio webView location

I have an app that makes use of a webView, I need to request user permission for both location and camera as the website in the webView makes use of both, But the permission dialogs do not request permission, not sure what I'm missing. Even if I go into the app and accept app permissions on the device, it still does not allow.
Main Activity
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.webkit.GeolocationPermissions;
import android.webkit.WebSettings;
public class MainActivity extends AppCompatActivity {
private String WebAddress = "https://www.example.com";
private WebView webView;
private WebSettings webSettings;
private WebViewClient webViewClient;
private ProgressBar progressBar;
private FrameLayout frameLayout;
private WebChromeClient webChromeClient;
private GeolocationPermissions geolocationPermissions;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frameLayout = (FrameLayout) findViewById(R.id.frameLayout);
progressBar = (ProgressBar) findViewById(R.id.progressbar);
progressBar.setMax(100);
webView = findViewById(R.id.webView);
webView.setWebViewClient(new HelpClient());
webView.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress){
frameLayout.setVisibility(View.VISIBLE);
progressBar.setProgress(progress);
setTitle("Loading...");
if (progress == 100){
frameLayout.setVisibility(View.GONE);
setTitle(view.getTitle());
}
super.onProgressChanged(view, progress);
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.setVerticalScrollBarEnabled(false);
webView.getSettings().setGeolocationEnabled(true);
webView.loadUrl(WebAddress);
progressBar.setProgress(0);
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
private class HelpClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
frameLayout.setVisibility(View.VISIBLE);
return true;
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK){
if (webView.canGoBack()){
webView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}
Android Manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_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:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

File browse cannot work in android webview

I have converted a website into an android application using androidstudio 2.3.3, cannot work input type="file" option, when click to input type="file" button nothing happens.
AndroidManiFest.xml code below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.webrivers.controlmarketing">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_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:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java code below
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.GeolocationPermissions;
public class MainActivity extends ActionBarActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private WebView myWebView;
private WebSettings webSettings;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.webView);
webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setAllowFileAccess(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setGeolocationEnabled(true);
myWebView.setWebViewClient(new Client());
if (Build.VERSION.SDK_INT >= 19) {
myWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
else if(Build.VERSION.SDK_INT >=11 && Build.VERSION.SDK_INT < 19) {
myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
myWebView.loadUrl("http://webrivers.co.in/green_medic/lock_screen.html");
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
public class Client extends WebViewClient {
ProgressDialog progressDialog;
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("mailto:")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}else {
view.loadUrl(url);
return true;
}
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if (progressDialog == null) {
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
try {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
return false;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
return super.onOptionsItemSelected(item);
}
}
Anybody knows what happens?

upload pictures from gallery or take from camera in webview

I am working on android app that shows a website only,the website have a button that clicking on it makes you upload a picture.the problem is the app doesn't respond when clicking on the button of the site.
Thanks in advance
Here the main activity code
package com.eizeasta.dame;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.graphics.Bitmap;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import com.eizeasta.dame.R;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends Activity {
WebView view;
SwipeRefreshLayout mySwipeRefreshLayout;
ProgressBar progressBar;
private WebView browser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.imageLoading1).setVisibility(View.VISIBLE);
AdView adView = (AdView) findViewById(R.id.admob_id);
AdRequest adRequest = new AdRequest.Builder()
.setRequestAgent("android_studio:ad_template").build();
adView.loadAd(adRequest);
browser = (WebView) findViewById(R.id.activity_main_webview);
progressBar= (ProgressBar)findViewById(R.id.progressBar);
final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipelayout);
final WebView browser = (WebView) findViewById(R.id.activity_main_webview);
swipeRefreshLayout.setColorSchemeResources(R.color.refresh,R.color.refresh1,R.color.refresh2);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
browser.reload();
swipeRefreshLayout.setRefreshing(true);
(new Handler()).postDelayed(new Runnable() {
#Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
}
},20000);
}
});
// Force links and redirects to open in the WebView instead of in a browser
//mWebView.setWebViewClient(new WebViewClient());
// Enable Javascript
WebSettings webSettings = browser.getSettings();
webSettings.setJavaScriptEnabled(true);
browser.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
browser.getSettings().setAppCacheEnabled(true);
browser.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
browser.setWebChromeClient(new WebChromeClient());
browser.getSettings().setAllowFileAccess(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setAllowFileAccessFromFileURLs(true);
browser.getSettings().setAllowContentAccess(true);
browser.getSettings().setUseWideViewPort(true);
browser.getSettings().setLoadWithOverviewMode(true);
// Use remote resource
browser.loadUrl("https://www.sameh.com/forum/_tbdl");
// Stop local links and redirects from opening in browser instead of WebView
browser.setWebViewClient(new WebViewClient(){
#Override
public void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) {
try {
webView.stopLoading();
} catch (Exception e) {
}
if (webView.canGoBack()) {
webView.goBack();
}
webView.loadUrl("about:blank");
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Error");
alertDialog.setMessage("Check your internet connection and try again.");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Try Again", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
startActivity(getIntent());
}
});
alertDialog.show();
super.onReceivedError(webView, errorCode, description, failingUrl);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(final WebView view, String url) {
findViewById(R.id.imageLoading1).setVisibility(View.GONE);
progressBar.setVisibility(View.GONE);
swipeRefreshLayout.setRefreshing(false);
}
} );
// Use local resource
//mWebView.loadUrl("file:android_asset/web/egypt-post.html");
}
// Prevent the back-button from closing the app
#Override
public void onBackPressed() {
if(browser.canGoBack()) {
browser.goBack();
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
and the android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eizeasta.dame" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="com.eizeasta.dame.MainActivity"
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />
</application>
</manifest>

PermissionUtils cannot be resolved

I'm working on an app that will allow users to report potholes and other roadside issues easily. My specific issue is in the map I included; in the report activity that will allow users to pinpoint where the problem is by using google maps and some markers. To do this I'm basically copying code word for word from the google maps api and my problem is that the permission utils object isn't being inherited from google play services. I had put this code down for a while (out of frustration) so i dont exactly remember what the other issues were but i remember getting the code around permission utils to not give me an error was kind of a bitch. Anyway so please help ;_;. I apologize for how i space my code, it is just visually easier for me, the first block is the message activity, the second is my manifest. please let me know if I should post anything else.
package com.example.fixmytown;
import java.util.List;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.maps.SupportMapFragment;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
public class Message extends FragmentActivity implements OnMyLocationButtonClickListener,
OnMapReadyCallback,
ActivityCompat.OnRequestPermissionsResultCallback {
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
private boolean mPermissionDenied = false;
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps_frag);
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
//----------------------------[Don't Mess with the above]------------------------------------------------------------
android.app.ActionBar actionBar = getActionBar();
//-------------------------------------------------------------------------------------------------------------------
//you were trying to figure out why the action bar isnt changing title. beinga bitch
String subject = " ";
if (Black.activityType == 1){
subject = "Pothole";
}
else if (Black.activityType == 2){
subject = "Roadkill";
}
else if (Black.activityType == 3){
subject = "Pollution";
}
else if(Black.activityType == 4){
// getActionBar().setTitle("Email Public Servant ");
}
}
//-------------------------------------------------------------------------------------------------------------------
#Override
public void onMapReady(GoogleMap map) {
mMap = map;
mMap.setOnMyLocationButtonClickListener(this);
enableMyLocation();
}
private void enableMyLocation() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission to access the location is missing.
PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,
Manifest.permission.ACCESS_FINE_LOCATION, true);
} else if (mMap != null) {
// Access to the location has been granted to the app.
mMap.setMyLocationEnabled(true);
}
}
//-------------------------------------------------------------------------------------------------------------------
public void sendMessage(View view) {
EditText text = (EditText)findViewById(R.id.MessageText);
String Description = text.getText().toString();
String subject = "";
if (Black.activityType == 1){
subject = "Pothole";
}
else if (Black.activityType == 2){
subject = "Roadkill";
}
else if (Black.activityType == 3){
subject = "Pollution";
}
else if(Black.activityType == 4){
// getActionBar().setTitle("Email Public Servant ");
}
//-------------------------------------------------------------------------------------------------------------------
//email ability
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"mckippy#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT , Description);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Message.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
//-------------------------------------------------------------------------------------------------------------------
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.message, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public boolean onMyLocationButtonClick() {
// TODO Auto-generated method stub
return false;
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fixmytown"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="com.google.android.providers.gsf.permisson.READ_GSERVICES"/>
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:screenOrientation="portrait"
android:name=".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>
<activity
android:screenOrientation="portrait"
android:name=".Black"
android:label="#string/title_activity_black" >
</activity>
<activity
android:screenOrientation="portrait"
android:name=".Green"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_green"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:screenOrientation="portrait"
android:name=".Message"
android:label="#string/title_activity_message" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyA0e26vc4-YGqmvOQSA6lQfnZyt3dmmbek"/>
</application>
</manifest>

Categories

Resources