Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.
/ os-fileup Public archive

Commit aa11842

Browse files
committed
fix: camera, API 30 support
- Camera Fix - Added Camcorder Demo - Support for Android 11 (API 30) - Build/Gradle Update - Other minor fixes
1 parent c5bc23a commit aa11842

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

app/src/main/java/mgks/os/fileup/MainActivity.java

+18-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import android.content.Intent;
1717
import android.content.pm.PackageManager;
1818
import android.content.res.Configuration;
19+
import android.graphics.Bitmap;
1920
import android.net.Uri;
2021
import android.os.Build;
2122
import android.os.Bundle;
@@ -36,19 +37,18 @@
3637
import android.webkit.WebViewClient;
3738
import android.widget.Toast;
3839

40+
import java.io.ByteArrayOutputStream;
3941
import java.io.File;
4042
import java.io.IOException;
4143
import java.text.SimpleDateFormat;
4244
import java.util.Date;
43-
import java.util.Iterator;
44-
import java.util.Set;
4545

4646
public class MainActivity extends AppCompatActivity{
4747

4848
/*-- CUSTOMIZE --*/
4949
/*-- you can customize these options for your convenience --*/
5050
private static String webview_url = "file:///android_res/raw/index.html"; // web address or local file location you want to open in webview
51-
private static String file_type = "image/*"; // file types to be allowed for upload
51+
private static String file_type = "*/*"; // file types to be allowed for upload
5252
private boolean multiple_files = true; // allowing multiple file upload
5353

5454
/*-- MAIN VARIABLES --*/
@@ -70,29 +70,25 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent){
7070

7171
/*-- if file request cancelled; exited camera. we need to send null value to make future attempts workable --*/
7272
if (resultCode == Activity.RESULT_CANCELED) {
73-
if (requestCode == file_req_code) {
7473
file_path.onReceiveValue(null);
7574
return;
76-
}
7775
}
7876

7977
/*-- continue if response is positive --*/
8078
if(resultCode== Activity.RESULT_OK){
81-
if(requestCode == file_req_code){
8279
if(null == file_path){
8380
return;
8481
}
85-
8682
ClipData clipData;
8783
String stringData;
84+
8885
try {
8986
clipData = intent.getClipData();
9087
stringData = intent.getDataString();
9188
}catch (Exception e){
9289
clipData = null;
9390
stringData = null;
9491
}
95-
9692
if (clipData == null && stringData == null && cam_file_data != null) {
9793
results = new Uri[]{Uri.parse(cam_file_data)};
9894
}else{
@@ -103,11 +99,24 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent){
10399
results[i] = clipData.getItemAt(i).getUri();
104100
}
105101
} else {
102+
try {
103+
Bitmap cam_photo = (Bitmap) intent.getExtras().get("data");
104+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
105+
cam_photo.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
106+
stringData = MediaStore.Images.Media.insertImage(this.getContentResolver(), cam_photo, null, null);
107+
}catch (Exception ignored){}
108+
/* checking extra data
109+
Bundle bundle = intent.getExtras();
110+
if (bundle != null) {
111+
for (String key : bundle.keySet()) {
112+
Log.w("ExtraData", key + " : " + (bundle.get(key) != null ? bundle.get(key) : "NULL"));
113+
}
114+
}*/
106115
results = new Uri[]{Uri.parse(stringData)};
107116
}
108117
}
109118
}
110-
}
119+
111120
file_path.onReceiveValue(results);
112121
file_path = null;
113122
}else{

0 commit comments

Comments
 (0)