package com.example.myapp.webviewbasedsocialapps.Activities; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlarmManager; import android.app.AlertDialog; import android.app.DownloadManager; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.media.MediaPlayer; import android.net.Uri; import android.os.Build; import android.os.Environment; import android.preference.PreferenceManager; import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.ContextMenu; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.WindowManager; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.FrameLayout; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.example.myapp.webviewbasedsocialapps.Others.DownloadManagerResolver; import com.example.myapp.webviewbasedsocialapps.R; import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks; import com.github.ksoichiro.android.observablescrollview.ObservableWebView; import com.google.android.gms.ads.AdView; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import com.github.ksoichiro.android.observablescrollview.ScrollState; public class WebActivity extends AppCompatActivity implements ObservableScrollViewCallbacks { private static final String TAG = WebActivity.class.getSimpleName(); private SharedPreferences preferences; private static final int REQUEST_STORAGE = 1; private static final int REQUEST_LOCATION = 2; public ValueCallback mUploadMessage; public static final int FILECHOOSER_RESULTCODE = 5173; public static final String FB_URL = "https://m.fblite.com"; public static final int AlarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP; private ProgressBar loadingProgressBar; ObservableWebView wv; AdView mAdView; private MediaPlayer mp; private String mCM; private ValueCallback mUM; private ValueCallback mUMA; private final static int FCR = 1; private static final int ID_CONTEXT_MENU_SAVE_IMAGE = 2562617; private static final int ID_CONTEXT_MENU_SHARE_IMAGE = 2562618; private String mPendingImageUrlToSave; private static String appDirectoryName; ObservableWebView webl; RelativeLayout rlayt; String UA = "Mozilla/5.0 (Linux; Android 6.0; Lenovo A7010a48 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 Mobile Safari/537.36"; public String ia = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web); getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); // rlayt = (RelativeLayout)findViewById(R.id.adspace); // checkApplication(); webl=(ObservableWebView) findViewById(R.id.web1); // StartAppSDK.init(this, "206799167", false); // StartAppAd.disableSplash(); // StartAppAd.disableSplash(); // StartAppAd.AdMode.values() //InMobiSdk.setLogLevel(InMobiSdk.LogLevel.DEBUG); // InMobiBanner bannerAd = (InMobiBanner)findViewById(R.id.banner); // // bannerAd.load(); // banner = (Banner) findViewById(R.id.banner); // // Banner.setLoc(true); // final Activity self = this; // banner.setListener(new BannerListener() { // @Override // public void onBannerError(View banner, Exception e) { // Toast.makeText(self, e.getMessage(), Toast.LENGTH_SHORT).show(); // } // // @Override // public void onBannerLoaded(View banner) { // Toast.makeText(self, "loaded", Toast.LENGTH_SHORT).show(); // } // // @Override // public void onBannerClosed(View banner) { // Toast.makeText(self, "closed", Toast.LENGTH_SHORT).show(); // } // // @Override // public void onBannerFinished() { // Toast.makeText(self, "finished", Toast.LENGTH_SHORT).show(); // } // // @Override // public void onBannerClicked(View banner) { // Toast.makeText(self, "clicked", Toast.LENGTH_SHORT).show(); // } // // @Override // public void onNoFill(View banner) { // Toast.makeText(self, "no fill", Toast.LENGTH_SHORT).show(); // } // }); // banner.setInventoryHash("fe96717d9875b9da4339ea5367eff1ec"); this is test id // banner.setInventoryHash("3223dbc95104c44f0a98867b67f6083c"); // banner.load(); // // // if (BuildConfig.FLAVOR.equals("free")) { //do sth only for free version // } //permission dialog for marshmello and above // } //add this so video ads will work properly // @Override // protected void onPause() { // super.onPause(); // banner.onPause(); // } // // @Override // protected void onResume() { // super.onResume(); // banner.onResume(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar1); setSupportActionBar(toolbar); Drawable drawable = ContextCompat.getDrawable(getApplicationContext(), R.drawable.list_36dp); toolbar.setOverflowIcon(drawable); // get shared preferences and TrayPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); appDirectoryName = getString(R.string.app_name).replace(" ", ""); final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); mp = MediaPlayer.create(this, R.raw.refresh); swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { webl .loadUrl("javascript:window.location.reload(true)"); swipeView.setRefreshing(false); mp.start(); Toast.makeText(WebActivity.this, "Reloading...", Toast.LENGTH_SHORT).show(); } }); webl = (ObservableWebView) findViewById(R.id.web1); WebSettings webSettings = webl.getSettings(); webl.getSettings().setLoadsImagesAutomatically(true); webl.getSettings().setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webl.getSettings().setLoadWithOverviewMode(true); webl.getSettings().setUseWideViewPort(true); webl.getSettings().setSupportZoom(true); webl.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webl.getSettings().setDomStorageEnabled(true); // webl.getSettings().setUserAgentString(ia); webl.getSettings().getBlockNetworkImage(); webSettings.setJavaScriptEnabled(true); webSettings.setAllowFileAccess(true); webl.canGoForward(); webl.getHitTestResult(); webl.setScrollViewCallbacks(this); String Mainurl = getIntent().getStringExtra("Address"); String notifyurl = getIntent().getStringExtra("Address2"); String currenturl = getIntent().getStringExtra("currenturl"); webl.loadUrl(notifyurl); webl.loadUrl(Mainurl); webl.loadUrl(currenturl); // location if (preferences.getBoolean("location", false)) { webl.getSettings().setGeolocationEnabled(true); if (Build.VERSION.SDK_INT < 24) { //noinspection deprecation webl.getSettings().setGeolocationDatabasePath(getFilesDir().getPath()); } } // since API 18 cache quota is managed automatically if (Build.VERSION.SDK_INT < 18) { //noinspection deprecation webl.getSettings().setAppCacheMaxSize(9 * 1024 * 1024); // 5 MB } webl.getSettings().setAppCachePath(getApplicationContext().getCacheDir().getAbsolutePath()); webl.getSettings().setAppCacheEnabled(true); webl.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); webl.setWebViewClient(new WebViewClient() { String currentUrl; @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { currentUrl = url; if (url.startsWith("http") || url.startsWith("https")) { return false; } if (url.startsWith("intent")) { try { Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); String fallbackUrl = intent.getStringExtra("browser_fallback_url"); if (fallbackUrl != null) { webl.loadUrl(fallbackUrl); return true; }} catch (URISyntaxException e) { //not an intent uri } return true;//do nothing in other cases } else if (url.startsWith("whatsapp:")) { // webl.loadUrl("http://touch.facebook.com/messages"); view.getContext().startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } else { return false; } } public void onPageFinished(WebView view, String url) { // view.getContext().startActivity( // new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } }); if (Build.VERSION.SDK_INT < 18) { //speed webview webl.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); } loadingProgressBar = (ProgressBar) findViewById(R.id.prog); registerForContextMenu(webl); webl.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); final FrameLayout flayout2 = (FrameLayout) findViewById(R.id.info); TextView txtinfo = (TextView) findViewById(R.id.infotext); String currurl = webl.getUrl(); String currtitle=webl.getTitle(); loadingProgressBar.setProgress(newProgress); if (newProgress==20){ txtinfo.setText("Please wait.."); } if (newProgress==40){ txtinfo.setText(currurl); } if (newProgress==50){ txtinfo.setText(currtitle); } if (newProgress==70){ txtinfo.setText("Loading Data.."); } if (newProgress==80){ txtinfo.setText(currtitle); } //loadingTitle.setProgres s(newProgress); // hide the progress bar if the loading is complete if (newProgress == 100) { flayout2.setVisibility(View.GONE); loadingProgressBar.setVisibility(View.INVISIBLE); } else { flayout2.setVisibility(View.VISIBLE); loadingProgressBar.setVisibility(View.VISIBLE); } } public void openFileChooser(ValueCallback uploadMsg) { this.openFileChooser(uploadMsg, "*/*"); } public void openFileChooser(ValueCallback uploadMsg, String acceptType) { this.openFileChooser(uploadMsg, acceptType, null); } public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); WebActivity.this.startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE); } public boolean onShowFileChooser( WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) { if (mUMA != null) { mUMA.onReceiveValue(null); } mUMA = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(WebActivity.this.getPackageManager()) != null) { File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCM); } catch (IOException ex) { Log.e(TAG, "Image file creation failed", ex); } if (photoFile != null) { mCM = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("*/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[]{takePictureIntent}; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, FCR); return true; } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (Build.VERSION.SDK_INT >= 21) { Uri[] results = null; //Check if response is positive if (resultCode == Activity.RESULT_OK) { if (requestCode == FCR) { if (null == mUMA) { return; } if (intent == null) { //Capture Photo if no image available if (mCM != null) { results = new Uri[]{Uri.parse(mCM)}; } } else { String dataString = intent.getDataString(); if (dataString != null) { results = new Uri[]{Uri.parse(dataString)}; } } } } mUMA.onReceiveValue(results); mUMA = null; } else { if (requestCode == FCR) { if (null == mUM) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUM.onReceiveValue(result); mUM = null; } } } private class Callback extends WebViewClient { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Toast.makeText(getApplicationContext(), "Failed loading! try reloading", Toast.LENGTH_SHORT).show(); webl.loadUrl("file:///android_asset/help.html"); } } // Create an image file private File createImageFile() throws IOException { @SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "img_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); return File.createTempFile(imageFileName, ".jpg", storageDir); } @Override public void onBackPressed() { if (webl.canGoBack()) { webl.goBack(); } else { webl.clearCache(true); finish(); } } @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); MenuItem item = menu.findItem(R.id.daymode); item.setVisible(false); 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.msgact) { // // webl.loadUrl("https://mbasic.facebook.com/messages"); // setTheme(R.style.zthemeDark); // // return true; if (id == R.id.about) { Intent i = new Intent(WebActivity.this, About.class); startActivity(i); return true; } else if (id == R.id.exit) { //try this, probably exits whole app // finishAffinity(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { finishAffinity(); } else finish(); return true; // } else if (id == R.id.groups) { // // webl.loadUrl("https://mbasic.facebook.com/groups"); // // return false; } else if (id == R.id.goforward) { if (webl.canGoForward()) { webl.goForward(); } else { Toast.makeText(getApplicationContext(), "No forward page available..", Toast.LENGTH_LONG).show(); } } else if (id == R.id.hidetbar) { try { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); return false; } catch (Exception e){ e.printStackTrace(); } } else if (id == R.id.removeads) { // RelativeLayout rlayout =(RelativeLayout) findViewById(R.id.adspace); // rlayout.setVisibility(View.GONE); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.ztronnsc")); startActivity(browserIntent); return false; } else if (id == R.id.close) { //try this, probably exits whole app // finishAffinity(); webl.clearCache(true); finish(); return true; } else if (id == R.id.shareapp) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "Check out this app, It has all popular social networks in one light weight simple app, It is fast,lite and uses less ram and memory that loaded with useful features such as Night Mode (use your favourite social sites at night in dark theme, protect your eyes), google instant search etc : http://play.google.com/store/apps/details?id=com.gaff.socloud"); sendIntent.setType("text/plain"); startActivity(sendIntent); return true; // } else if (id == R.id.pages) { // // webl.loadUrl("https://mbasic.facebook.com/pages"); // // return true; // } else if (id == R.id.trending) { // // // webl.loadUrl("https://mbasic.facebook.com/search/trending-news"); // return true; // } else if (id == R.id.) { // webl.loadUrl("https://mbasic.facebook.com/buddylist.php"); } else if (id == R.id.moreapps) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/search?q=zidsapps")); startActivity(browserIntent); return true; } else if (id == R.id.reload) { webl.loadUrl("javascript:window.location.reload(true)"); return true; // } else if (id == R.id.uploadpic) { // AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyAlertDialogTheme); // builder.setTitle("Photo Upload Helper"); // builder.setMessage("If you can't upload photo or unable to see the upload menu, you can try this UA-Switcher, this temporary will switch the user-agent, so you may able to see the upload option. you can also try the normal-mode, that should support photo upload"); // builder.setPositiveButton("Switch-UA", new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // Snackbar.make(getWindow().getDecorView(), getString(R.string.ualert), Snackbar.LENGTH_LONG) // .show(); // String url = "http://touch.facebook.com"; // webl.loadUrl(url); // webl.getSettings().setUserAgentString(uanormal); // } // }); // builder.setNegativeButton("Cancel", null); // builder.setNeutralButton("Normal-Mode", new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // String uploadurl = "https://touch.facebook.com"; // Intent i = new Intent(Webactivity.this, Normalmode.class); // i.putExtra("currenturl", uploadurl); // startActivity(i); // } // }); // // builder.show(); } else if (id == R.id.gsearch) { // RelativeLayout rlayout =(RelativeLayout) findViewById(R.id.adspace); // rlayout.setVisibility(View.GONE); webl.loadUrl("http://google.com/"); return false; } else if (id == R.id.home1) { webl.clearCache(true); finish(); Intent intent = new Intent(WebActivity.this, MainActivity.class); startActivity(intent); // } else if (id == R.id.settings) { // // Intent i = new Intent(Webactivity.this, SettingsActivity.class); // startActivity(i); } else if (id == R.id.nightmodemn) { webl.clearCache(true); Intent i = new Intent(WebActivity.this, DarkMode.class); startActivity(i); finish(); } else if (id == R.id.ztronnfb) { webl.loadUrl("http://mbasic.facebook.com/ztronndev"); Toast.makeText(getApplicationContext(), "Please like our page to get updated..", Toast.LENGTH_LONG).show(); return true; // return true; //} else if (id == R.id.setting) { // Intent i = new Intent(Webactivity.this, PrefsActivity.class); // startActivity(i); // return true; } else if (id == R.id.copylink) { try { String url = webl.getUrl(); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("label", url); clipboard.setPrimaryClip(clip); Toast.makeText(getApplicationContext(), "Link Copied!", Toast.LENGTH_SHORT).show(); return true; }catch (Exception e){ e.printStackTrace(); } } return super.onOptionsItemSelected(item); } private void onCoachMark() { final Toast toast = Toast.makeText(getApplicationContext(), "You can enable notifications in settings", Toast.LENGTH_SHORT); toast.show(); } private void requestStoragePermission() { String[] permissions = new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}; if (!hasStoragePermission()) { Log.e(TAG, "No storage permission at the moment. Requesting..."); ActivityCompat.requestPermissions(this, permissions, REQUEST_STORAGE); } else { Log.e(TAG, "We already have storage permission. Yay!"); // new image is about to be saved if (mPendingImageUrlToSave != null) saveImageToDisk(mPendingImageUrlToSave); } } // check is storage permission granted private boolean hasStoragePermission() { String storagePermission = android.Manifest.permission.WRITE_EXTERNAL_STORAGE; int hasPermission = ContextCompat.checkSelfPermission(this, storagePermission); return (hasPermission == PackageManager.PERMISSION_GRANTED); } // request location permission private void requestLocationPermission() { String[] permissions = new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}; if (!hasLocationPermission()) { Log.e(TAG, "No location permission at the moment. Requesting..."); ActivityCompat.requestPermissions(this, permissions, REQUEST_LOCATION); } else { Log.e(TAG, "We already have location permission. Yay!"); } } // check is location permission granted private boolean hasLocationPermission() { String locationPermission = android.Manifest.permission.ACCESS_FINE_LOCATION; int hasPermission = ContextCompat.checkSelfPermission(this, locationPermission); return (hasPermission == PackageManager.PERMISSION_GRANTED); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case REQUEST_STORAGE: if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.e(TAG, "Storage permission granted"); // new image is about to be saved if (mPendingImageUrlToSave != null) saveImageToDisk(mPendingImageUrlToSave); } else { Log.e(TAG, "Storage permission denied"); Toast.makeText(getApplicationContext(), getString(R.string.no_storage_permission), Toast.LENGTH_SHORT).show(); } break; case REQUEST_LOCATION: if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.e(TAG, "Location permission granted"); webl.reload(); } else { Log.e(TAG, "Location permission denied"); Toast.makeText(getApplicationContext(), getString(R.string.no_location_permission), Toast.LENGTH_SHORT).show(); } break; } super.onRequestPermissionsResult(requestCode, permissions, grantResults); } @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { WebView.HitTestResult result = webl.getHitTestResult(); if (result != null) { int type = result.getType(); if (type == WebView.HitTestResult.IMAGE_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { showLongPressedImageMenu(menu, result.getExtra()); } } } @Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case ID_CONTEXT_MENU_SAVE_IMAGE: //In order to save anything we need storage permission. // onRequestPermissionsResult will save an image. requestStoragePermission(); break; case ID_CONTEXT_MENU_SHARE_IMAGE: Intent share = new Intent(Intent.ACTION_SEND); share.setType("text/plain"); share.putExtra(Intent.EXTRA_TEXT, mPendingImageUrlToSave); startActivity(Intent.createChooser(share, getString(R.string.share_link))); break; } return super.onContextItemSelected(item); } private void showLongPressedImageMenu(ContextMenu menu, String imageUrl) { mPendingImageUrlToSave = imageUrl; menu.add(0, ID_CONTEXT_MENU_SAVE_IMAGE, 0, getString(R.string.save_img)); menu.add(0, ID_CONTEXT_MENU_SHARE_IMAGE, 1, getString(R.string.share_link)); } private void saveImageToDisk(String imageUrl) { if (!DownloadManagerResolver.resolve(this)) { mPendingImageUrlToSave = null; return; } try { File imageStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appDirectoryName); if (!imageStorageDir.exists()) { //noinspection ResultOfMethodCallIgnored imageStorageDir.mkdirs(); } // default image extension String imgExtension = ".jpg"; if (imageUrl.contains(".gif")) imgExtension = ".gif"; else if (imageUrl.contains(".png")) imgExtension = ".png"; else if (imageUrl.contains(".3gp")) imgExtension = ".3gp"; String date = DateFormat.getDateTimeInstance().format(new Date()); String file = "fastlite-saved-image-" + date.replace(" ", "").replace(":", "").replace(".", "") + imgExtension; DownloadManager dm = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE); Uri downloadUri = Uri.parse(imageUrl); DownloadManager.Request request = new DownloadManager.Request(downloadUri); request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE) .setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + File.separator + appDirectoryName, file) .setTitle(file).setDescription(getString(R.string.save_img)) .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); dm.enqueue(request); Toast.makeText(this, getString(R.string.downloading_img), Toast.LENGTH_LONG).show(); } catch (IllegalStateException ex) { Toast.makeText(this, getString(R.string.cannot_access_storage), Toast.LENGTH_LONG).show(); } catch (Exception ex) { // just in case, it should never be called anyway Toast.makeText(this, getString(R.string.file_cannot_be_saved), Toast.LENGTH_LONG).show(); } finally { mPendingImageUrlToSave = null; } } public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { } public void onDownMotionEvent() { } public void onUpOrCancelMotionEvent(ScrollState scrollState) { ActionBar ab = getSupportActionBar(); if (ab == null) { return; } if (scrollState == ScrollState.UP) { if (ab.isShowing()) { ab.hide(); //hide(); } } else if (scrollState == ScrollState.DOWN) { if (!ab.isShowing()) { ab.show(); // show() } } } String packagename = "com.ztronnfbkey"; public boolean checkApplication() { PackageManager packageManager = getPackageManager(); ApplicationInfo applicationInfo = null; try { applicationInfo = packageManager.getApplicationInfo(packagename, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } if (applicationInfo == null) { // not installed return false; } else { rlayt.setVisibility(View.GONE); } return true; }}