Autore Topic: Salvare foto e audio in DB SQLITE  (Letto 390 volte)

Offline Cava997

  • Nuovo arrivato
  • *
  • Post: 2
  • Respect: 0
    • Mostra profilo
  • Sistema operativo:
    Windows 8
Salvare foto e audio in DB SQLITE
« il: 13 Giugno 2016, 12:48:49 CEST »
0
Salva a tutti, per un progetto di esame di maturità sto realizzando un app che permetta di salvare su database sqlite vari campi per creare "gite"... ho creato un'activity per scattare le foto (che vengono salvate in memoria) e una per registrare audio. Qual è il modo più semplice di salvare nel database questi dati? ( anche un massimo di 4/5 per ogni nuova gita).

Offline tonno16

  • Utente storico
  • *****
  • Post: 1228
  • Respect: +59
    • Mostra profilo
  • Dispositivo Android:
    moto g
  • Play Store ID:
    Diego Tonini
  • Sistema operativo:
    OpenSuse
Re:Salvare foto e audio in DB SQLITE
« Risposta #1 il: 13 Giugno 2016, 14:24:38 CEST »
0
Non puoi salvare sto dati in SQL. Al massimo salvi la path dei file sottoforma di stringa.

Offline Cava997

  • Nuovo arrivato
  • *
  • Post: 2
  • Respect: 0
    • Mostra profilo
  • Sistema operativo:
    Windows 8
Re:Salvare foto e audio in DB SQLITE
« Risposta #2 il: 13 Giugno 2016, 14:28:02 CEST »
0
public class ScattaFoto extends AppCompatActivity {

    private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
    private Uri fileUri;


    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
private GoogleApiClient client;

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                // Image captured and saved to fileUri specified in the Intent
Toast.makeText(this, "Image saved to:\n" +
                        data.getData(), Toast.LENGTH_LONG).show();
            } else if (resultCode == RESULT_CANCELED) {
                // User cancelled the image capture
} else {
                // Image capture failed, advise user
}
        }


    }

    @Override
public void onStart() {
        super.onStart();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android-app://com.example.francesco.myapplication/http/host/path")
        );
        AppIndex.AppIndexApi.start(client, viewAction);
    }

    @Override
public void onStop() {
        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android-app://com.example.francesco.myapplication/http/host/path")
        );
        AppIndex.AppIndexApi.end(client, viewAction);
        client.disconnect();
    }

    public static final int MEDIA_TYPE_IMAGE = 1;
    //public static final int MEDIA_TYPE_VIDEO = 2;
private static Uri getOutputMediaFileUri(int type) {
        return Uri.fromFile(getOutputMediaFile(type));
    }


    /**
     * Create a File for saving an image or video
     */
private static File getOutputMediaFile(int type) {
        // To be safe, you should check that the SDCard is mounted
        // using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES), "MyCameraApp");
        // This location works best if you want the created images to be shared
        // between applications and persist after your app has been uninstalled.
        // Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.d("MyCameraApp", "failed to create directory");
                return null;
            }
        }

        // Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        File mediaFile;
        if (type == MEDIA_TYPE_IMAGE) {
            mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                    "IMG_" + timeStamp + ".jpg");
        }
        /*else if(type == MEDIA_TYPE_VIDEO) {
            mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                    "VID_"+ timeStamp + ".mp4");
        } */
else {
            return null;
        }

        return mediaFile;
    }

    @Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);


// create Intent to take a picture and return control to the calling application
       /* Button btnFoto = (Button)findViewById(R.id.btnFoto);
        assert btnFoto != null;
        btnFoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {*/
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
        // start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
          /*
            }
        });
*/
finish();

    }


in tutto ciò qual è la path da salvare e come la richiamo nel db ??