Skip to content

Commit

Permalink
chore: Remove camera plugin (#3611)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikeith authored Sep 23, 2020
1 parent 415f972 commit 4e629c4
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 1,638 deletions.
2 changes: 0 additions & 2 deletions android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.getcapacitor.plugin.App;
import com.getcapacitor.plugin.Camera;
import com.getcapacitor.plugin.Geolocation;
import com.getcapacitor.plugin.Keyboard;
import com.getcapacitor.plugin.LocalNotifications;
Expand Down Expand Up @@ -379,7 +378,6 @@ private void initWebView() {
private void registerAllPlugins() {
this.registerPlugin(App.class);
this.registerPlugin(BackgroundTask.class);
this.registerPlugin(Camera.class);
this.registerPlugin(LocalNotifications.class);
this.registerPlugin(Geolocation.class);
this.registerPlugin(Keyboard.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.webkit.ConsoleMessage;
Expand All @@ -17,9 +18,14 @@
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import com.getcapacitor.plugin.camera.CameraUtils;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONException;
Expand Down Expand Up @@ -284,7 +290,7 @@ private boolean showImageCapturePicker(final ValueCallback<Uri[]> filePathCallba

final Uri imageFileUri;
try {
imageFileUri = CameraUtils.createImageFileUri(bridge.getActivity(), bridge.getContext().getPackageName());
imageFileUri = createImageFileUri();
} catch (Exception ex) {
Logger.error("Unable to create temporary media capture file: " + ex.getMessage());
return false;
Expand Down Expand Up @@ -421,4 +427,21 @@ public boolean isValidMsg(String msg) {
msg.equalsIgnoreCase("console.groupEnd")
);
}

private Uri createImageFileUri() throws IOException {
Activity activity = bridge.getActivity();
File photoFile = createImageFile(activity);
return FileProvider.getUriForFile(activity, bridge.getContext().getPackageName() + ".fileprovider", photoFile);
}

private File createImageFile(Activity activity) throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES);

File image = File.createTempFile(imageFileName, ".jpg", storageDir);

return image;
}
}
Loading

0 comments on commit 4e629c4

Please sign in to comment.