Skip to content

Commit 6bab2c7

Browse files
committed
first commit
0 parents  commit 6bab2c7

23 files changed

Lines changed: 1478 additions & 0 deletions

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.iml
2+
*.jks
3+
.gradle
4+
/local.properties
5+
/.idea
6+
.DS_Store
7+
/build
8+
/captures
9+
/app/release
10+
.externalNativeBuild
11+
.cxx
12+
local.properties

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
defaultConfig {
7+
applicationId "net.webdrop"
8+
minSdkVersion 21
9+
compileSdk 34
10+
targetSdkVersion 34
11+
versionCode 12
12+
versionName "v1.2"
13+
14+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled true
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
debug {
23+
minifyEnabled false
24+
applicationIdSuffix ".debug"
25+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
26+
}
27+
}
28+
compileOptions {
29+
sourceCompatibility JavaVersion.VERSION_17
30+
targetCompatibility JavaVersion.VERSION_17
31+
}
32+
namespace 'net.webdrop'
33+
}
34+
35+
dependencies {
36+
}

app/proguard-rules.pro

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
22+
23+
-keep class * extends android.webkit.WebChromeClient { *; }
24+
-dontwarn im.delight.android.webview.**

app/src/main/AndroidManifest.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
<uses-permission
7+
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
8+
android:maxSdkVersion="32" />
9+
10+
<application
11+
android:allowBackup="true"
12+
android:icon="@drawable/ic_webdrop"
13+
android:label="@string/app_name"
14+
android:roundIcon="@drawable/ic_webdrop"
15+
android:supportsRtl="true"
16+
android:theme="@android:style/Theme.Material.Light.NoActionBar">
17+
<activity
18+
android:name=".MainActivity"
19+
android:configChanges="orientation|screenSize"
20+
android:exported="true"
21+
android:launchMode="singleTask"
22+
android:windowSoftInputMode="stateAlwaysHidden">
23+
<intent-filter>
24+
<action android:name="android.intent.action.MAIN" />
25+
26+
<category android:name="android.intent.category.LAUNCHER" />
27+
</intent-filter>
28+
<intent-filter>
29+
<action android:name="android.intent.action.SEND" />
30+
31+
<category android:name="android.intent.category.DEFAULT" />
32+
33+
<data android:mimeType="*/*" />
34+
</intent-filter>
35+
<intent-filter>
36+
<action android:name="android.intent.action.SEND_MULTIPLE" />
37+
38+
<category android:name="android.intent.category.DEFAULT" />
39+
40+
<data android:mimeType="*/*" />
41+
</intent-filter>
42+
</activity>
43+
</application>
44+
45+
</manifest>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package net.webdrop;
2+
3+
import android.content.ContentResolver;
4+
import android.content.ContentValues;
5+
import android.content.Context;
6+
import android.net.Uri;
7+
import android.os.Build;
8+
import android.os.Environment;
9+
import android.provider.MediaStore;
10+
import android.util.Base64;
11+
import android.webkit.JavascriptInterface;
12+
import android.widget.Toast;
13+
14+
import java.io.File;
15+
import java.io.FileOutputStream;
16+
import java.io.IOException;
17+
import java.io.OutputStream;
18+
import java.text.DateFormat;
19+
import java.util.Date;
20+
21+
public class JavaScriptInterface {
22+
private final Context context;
23+
24+
public JavaScriptInterface(Context context) {
25+
this.context = context;
26+
}
27+
28+
@JavascriptInterface
29+
public void getBase64FromBlobData(String base64Data, String mimeType, String extension) throws IOException {
30+
convertBase64StringToFileAndSaveIt(base64Data, mimeType, extension);
31+
}
32+
33+
public static String getBase64StringFromBlobUrl(String blobUrl, String mimeType, String extension) {
34+
if (blobUrl.startsWith("blob")) {
35+
return "javascript: var xhr = new XMLHttpRequest();" +
36+
"xhr.open('GET', '" + blobUrl + "', true);" +
37+
"xhr.setRequestHeader('Content-type','" + mimeType + "');" +
38+
"xhr.responseType = 'blob';" +
39+
"xhr.onload = function(e) {" +
40+
" if (this.status == 200) {" +
41+
" var blobPdf = this.response;" +
42+
" var reader = new FileReader();" +
43+
" reader.readAsDataURL(blobPdf);" +
44+
" reader.onloadend = function() {" +
45+
" base64data = reader.result;" +
46+
" Android.getBase64FromBlobData(base64data,'" + mimeType + "','" + extension + "');" +
47+
" }" +
48+
" }" +
49+
"};" +
50+
"xhr.send();";
51+
}
52+
return "javascript: console.log('It is not a Blob URL');";
53+
}
54+
55+
private void convertBase64StringToFileAndSaveIt(String base64Data, String mimeType, String extension) throws IOException {
56+
String currentDateTime = DateFormat.getDateTimeInstance().format(new Date());
57+
String fileName = "File_" + currentDateTime;
58+
if (!extension.isEmpty()) fileName = fileName + "_." + extension;
59+
byte[] fileAsBytes = Base64.decode(base64Data.replaceFirst("^data:" + mimeType + ";base64,", ""), 0);
60+
61+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
62+
ContentResolver resolver = context.getContentResolver();
63+
ContentValues contentValues = new ContentValues();
64+
contentValues.put(MediaStore.Downloads.DISPLAY_NAME, fileName);
65+
contentValues.put(MediaStore.Downloads.MIME_TYPE, mimeType);
66+
contentValues.put(MediaStore.Downloads.DATE_ADDED, System.currentTimeMillis());
67+
contentValues.put(MediaStore.Downloads.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS);
68+
69+
Uri uri = resolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues);
70+
OutputStream outputStream = resolver.openOutputStream(uri);
71+
outputStream.write(fileAsBytes);
72+
outputStream.close();
73+
74+
} else {
75+
final File file = new File(Environment.getExternalStoragePublicDirectory(
76+
Environment.DIRECTORY_DOWNLOADS) + "/" + fileName);
77+
FileOutputStream fileOutputStream = new FileOutputStream(file, false);
78+
fileOutputStream.write(fileAsBytes);
79+
fileOutputStream.flush();
80+
}
81+
Toast.makeText(context, "Check downloads folder ✅", Toast.LENGTH_SHORT).show();
82+
}
83+
}

0 commit comments

Comments
 (0)