Created
February 18, 2021 08:58
-
-
Save doyle-flutter/0939e5085ce04a5c2468c598b7361064 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ... import 생략 | |
| // 기존 카메라 내용과 합쳐있습니다 | |
| public class MainActivity extends FlutterActivity { | |
| private static final String CHANNEL = "app.james.cam/cam"; | |
| private static final String SEND_CHANNEL = "app.james.cam/cam2"; | |
| MethodChannel sendChannel; | |
| private static final String BACK_CHANNEL2 = "app.james.cam/intentservice"; | |
| private static final String BACK_METHOD_NAME = "intentservicestart"; | |
| ResultReceiver mRecevier; | |
| @Override | |
| public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { | |
| super.configureFlutterEngine(flutterEngine); | |
| new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL) | |
| .setMethodCallHandler( | |
| ((call, result) -> { | |
| if(call.method.equals("cam")){ | |
| dispatchTakePictureIntent(); | |
| } | |
| })); | |
| sendChannel = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), SEND_CHANNEL); | |
| new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), BACK_CHANNEL2) | |
| .setMethodCallHandler( | |
| ((call, result) -> { | |
| if(call.method.equals(BACK_METHOD_NAME)){ | |
| this.intentServiceStart(); | |
| } | |
| })); | |
| final String SEND_CHANNEL2 = "app.james.cam/backdata"; | |
| final String SEND_METHOD2 = "data"; | |
| MethodChannel m2 = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), SEND_CHANNEL2); | |
| mRecevier = new ResultReceiver(new Handler()){ | |
| @Override | |
| protected void onReceiveResult(int resultCode, Bundle resultData) { | |
| super.onReceiveResult(resultCode, resultData); | |
| Log.d("DOY", resultData.getString("key")); | |
| m2.invokeMethod(SEND_METHOD2, resultData.getString("key").toString()); | |
| } | |
| }; | |
| } | |
| // 04 영상 | |
| // static final int REQUEST_IMAGE_CAPTURE = 1; | |
| // @SuppressLint("QueryPermissionsNeeded") | |
| // private void dispatchTakePictureIntent() { | |
| // Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
| // if (takePictureIntent.resolveActivity(getPackageManager()) != null) { | |
| // startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); | |
| // } | |
| // } | |
| // 05 영상 | |
| static final int REQUEST_IMAGE_CAPTURE = 1; | |
| private void dispatchTakePictureIntent() { | |
| // [ UI 및 제어는 플러터에서 만들기 때문에 주석 | |
| // if(this.imageBitmap != null){ | |
| // this.clear(); | |
| // button.setText("촬영"); ] | |
| // return; | |
| // } | |
| Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
| if (takePictureIntent.resolveActivity(getPackageManager()) != null) { | |
| startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); | |
| } | |
| } | |
| @Override | |
| protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| super.onActivityResult(requestCode, resultCode, data); | |
| if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { | |
| Bundle extras = data.getExtras(); | |
| Bitmap imageBitmap = (Bitmap) extras.get("data"); | |
| ByteArrayOutputStream stream = new ByteArrayOutputStream() ; | |
| imageBitmap.compress( Bitmap.CompressFormat.PNG, 100, stream) ; | |
| byte[] byteArray = stream.toByteArray() ; | |
| // [ UI 및 제어는 플러터에서 만들기 때문에 주석 | |
| // iv.setImageBitmap(imageBitmap); | |
| // button.setText("지우기"); ] | |
| sendChannel.invokeMethod("sendImg", byteArray); | |
| } | |
| } | |
| // void clear(){ | |
| // [ UI 및 제어는 플러터에서 만들기 때문에 주석 | |
| // iv.setImageBitmap(null); ] | |
| // this.imageBitmap = null; | |
| // } | |
| void intentServiceStart(){ | |
| final Intent intent = new Intent(this, MyIntentService.class); | |
| intent.putExtra("INTENT_KEY_RECEIVER",mRecevier); | |
| Log.d("DOY", "CLICK?"); | |
| startService(intent); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment