Amakesh Napisano Styczeń 30, 2016 Zgłoś Udostępnij Napisano Styczeń 30, 2016 Mam następujące dwie metody. Potrzebuję ustawić zdjęcie/film jako załącznik do wpisu(przypomnienia) w aplikacji ToDo - Lsita zadań(projekt na zaliczenie). Podkreśla mi na czerwono onActivityResult w super.onActivityResult(requestCode, resultCode, data); i pokazuje błąd "Cannot resolve method 'onActivityResult(int, int, android.content.Intent)' " AddActivity.java Button button_z = (Button) findViewById(R.id.button_z); button_z.setonclickListener(new View.onclickListener() { @Override public void onclick(View view2) { selectImage(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == REQUEST_CAMERA) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes); File destination = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis() + ".jpg"); FileOutputStream fo; try { destination.createNewFile(); fo = new FileOutputStream(destination); fo.write(bytes.toByteArray()); fo.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } imageView.setImageBitmap(thumbnail); } else if (requestCode == SELECT_FILE) { Uri selectedImageUri = data.getData(); String[] projection = {MediaStore.MediaColumns.DATA}; CursorLoader cursorLoader = new CursorLoader(AddActivity.this, selectedImageUri, projection, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); cursor.moveToFirst(); String selectedImagePath = cursor.getString(column_index); Bitmap bm; BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(selectedImagePath, options); final int REQUIRED_SIZE = 200; int scale = 1; while (options.outWidth / scale / 2 >= REQUIRED_SIZE && options.outHeight / scale / 2 >= REQUIRED_SIZE) scale *= 2; options.inSampleSize = scale; options.inJustDecodeBounds = false; bm = BitmapFactory.decodeFile(selectedImagePath, options); imageView.setImageBitmap(bm); } } private void selectImage() { final CharSequence[] items = { "Zrób zdjęcie lub nagranie", "Wybierz istniejące", "Anuluj" }; AlertDialog.Builder builder = new AlertDialog.Builder(AddActivity.this); builder.setTitle("Dodaj załącznik"); builder.setItems(items, new DialogInterface.onclickListener() { @Override public void onclick(DialogInterface dialog, int item) { if (items[item].equals("Zrób zdjęcie lub nagranie")) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, REQUEST_CAMERA); } else if (items[item].equals("Wybierz istniejące")) { Intent intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult( Intent.createChooser(intent, "Wybierz plik"), SELECT_FILE); } else if (items[item].equals("Anuluj")) { dialog.dismiss(); } } }); builder.show(); } } Cytuj Link do komentarza Udostępnij na innych stronach More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.