package="com.stoutner.privacybrowser" >
<uses-permission android:name="android.permission.INTERNET" />
- <!-- READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE are required to download files. -->
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="false"
android:label="@string/privacy_browser"
android:theme="@style/AppTheme" >
- <!-- configChanges orientation and screenSize makes the app not reload when the orientation changes. -->
- <!-- windowSoftInputMode stateAlwaysHidden hides the keyboard when the app starts. -->
+ <!-- android:configChanges="orientation|screenSize" makes the app not reload when the orientation changes. -->
+ <!-- android:windowSoftInputMode="stateAlwaysHidden" hides the keyboard when the app starts. -->
<activity
android:name=".Webview"
android:configChanges="orientation|screenSize"
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
- <!-- android.intent.action.VIEW with the schemes enables processing of web intents. -->
+ <!-- android.intent.action.VIEW with the two schemes enables processing of web intents. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
package com.stoutner.privacybrowser;
+import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
+import android.app.DownloadManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
+import android.os.Environment;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.Patterns;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
+import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.widget.ProgressBar;
import android.widget.Toast;
+import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
}
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
- Toast.makeText(mainWebViewActivity, "Error loading " + request + " Error: " + error, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mainWebViewActivity, "Error loading " + request + " Error: " + error, Toast.LENGTH_LONG).show();
}
// Update the URL in urlTextBox when the page starts to load.
}
});
+ mainWebView.setDownloadListener(new DownloadListener() {
+ // Launch the Android download manager when a link leads to a download.
+ @Override
+ public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
+ DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
+ DownloadManager.Request requestUri = new DownloadManager.Request(Uri.parse(url));
+
+ // Add the URL as the description for the download.
+ requestUri.setDescription(url);
+
+ // Show the download notification after the download is completed if the API is 11 or greater.
+ if (Build.VERSION.SDK_INT >= 11) {
+ requestUri.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
+ }
+
+ downloadManager.enqueue(requestUri);
+ Toast.makeText(mainWebViewActivity, "Download started", Toast.LENGTH_SHORT).show();
+ }
+ });
+
// Allow pinch to zoom.
mainWebView.getSettings().setBuiltInZoomControls(true);
startActivity(Intent.createChooser(shareIntent, "Share URL"));
}
break;
+
+ case R.id.downloads:
+ // Launch the system Download Manager.
+ Intent downloadManangerIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
+
+ // Launch as a new task so that Download Manager and Privacy Browser show as separate windows in the recent tasks list.
+ downloadManangerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ startActivity(downloadManangerIntent);
}
return super.onOptionsItemSelected(menuItem);
<item
android:id="@+id/home"
android:title="@string/home"
- android:orderInCategory="100"
+ android:orderInCategory="10"
android:icon="@drawable/ic_home_black_24dp"
app:showAsAction="never" />
<item
android:id="@+id/refresh"
android:title="@string/refresh"
- android:orderInCategory="200"
+ android:orderInCategory="20"
app:showAsAction="never" />
<item
android:id="@+id/back"
android:title="@string/back"
- android:orderInCategory="200"
+ android:orderInCategory="30"
android:icon="@drawable/ic_back"
app:showAsAction="never" />
<item
android:id="@+id/forward"
android:title="@string/forward"
- android:orderInCategory="300"
+ android:orderInCategory="40"
android:icon="@drawable/ic_forward"
app:showAsAction="never" />
<item
android:id="@+id/copyURL"
android:title="@string/copyURL"
- android:orderInCategory="400"
+ android:orderInCategory="50"
tools:targetApi="11"
app:showAsAction="never" />
<item
android:id="@+id/pasteURL"
android:title="@string/pasteURL"
- android:orderInCategory="500"
+ android:orderInCategory="60"
tools:targetApi="11"
app:showAsAction="never" />
<item
android:id="@+id/shareURL"
android:title="@string/shareURL"
- android:orderInCategory="600"
+ android:orderInCategory="70"
+ app:showAsAction="never" />
+
+ <item
+ android:id="@+id/downloads"
+ android:title="@string/downloads"
+ android:orderInCategory="80"
app:showAsAction="never" />
</menu>