Nivel de la API de Android <19 y "prueba puede utilizar la administración de recursos automática" warning

Tengo este pedazo de código

private void copyFile(File src, File dst) throws IOException { FileChannel inChannel = new FileInputStream(src).getChannel(); FileChannel outChannel = new FileOutputStream(dst).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); }finally { if(inChannel != null) { inChannel.close(); } outChannel.close(); } } 

Que genera la advertencia molesta "intentar utilizar la gestión automática de recursos". El prolem es que no puedo usar Java 7 try-with-resources causa que mi aplicación apunte al nivel 14 (tengo un error si lo uso). ¿Hay una manera de suprimir esa advertencia molesta?

@SuppressWarnings ("TryFinallyCanBeTryWithResources") hizo el truco 🙂

@SuppressLint("NewApi") también funcionará =)

Y por ejemplo:

  @SuppressLint("NewApi") public static File saveImage(Bitmap bitmap) { File file = null; if (isExternalStorageWritable()) { file = new File(getFolderStorageDirectory(), getFileNameImage()); try (FileOutputStream out = new FileOutputStream(file)) { bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); } catch (Exception e) { e.getMessage(); } } return file; } 

¡Espero eso ayude!

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.