limit publications Parse

Asked

Viewed 37 times

0

Personal following to making an app where one posts photos

would like to limit the publication to 10 posts per person and when the person tries to post more images give an error message

someone knows how I could do that

here is the action to publish and save in parse

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    //testar o processo de retorno dos dados
    if (requestCode == 1 && resultCode == RESULT_OK && data != null) {


        //Recuperar local do recurso
        Uri localImagemSelecionada = data.getData();



        //Recupera a imagem do local que foi selecionada
        try {
            Bitmap imagem = MediaStore.Images.Media.getBitmap(getContentResolver(), localImagemSelecionada);

            /*
            Comprimir imagem no formato PNG
             */
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            imagem.compress(Bitmap.CompressFormat.PNG, 75, stream);



            /*Cria  Arrays de Bytes da imagem formato PNG 
            */
            byte[] byteArray = stream.toByteArray();


            /*Cria arquivos com formato proprio do Parse para PNG              */
            SimpleDateFormat dateFormat = new SimpleDateFormat("ddmmaaaahhmmss");
            String nomeImagem = dateFormat.format(new Date());
            ParseFile arquivoParse = new ParseFile(nomeImagem + "imagem.png", byteArray);

            /*Monta um objeto para salvar no Parse
             */
            final ParseObject parseObject = new ParseObject("Imagem");
            parseObject.put("username", ParseUser.getCurrentUser().getUsername());

            /*Atribui 2 entradas de dados no objeto "imagem", para PNG */

            parseObject.put("imagem", arquivoParse);




            //Salvar os dados
            parseObject.saveInBackground(new SaveCallback() {
                @Override
                public void done(ParseException e) {

                    if (e == null) {//Sucesso



                        String idObjeto = parseObject.getObjectId();

                        Intent intent = new Intent(PublicarImagemActivity.this, descricaoActivity.class);
                        intent.putExtra("idObjeto", idObjeto);
                        startActivity(intent);
                        finish();
                        Toast.makeText(getApplicationContext(), "Sua imagem foi publicada!", Toast.LENGTH_LONG).show();


                    } else {//Erro
                        Toast.makeText(getApplicationContext(), "Erro ao postar sua imagem, tente novamente!",
                                Toast.LENGTH_LONG).show();
                    }


                }
  • There are some ways that it is possible to do, both the side where receives the image, as the side of Android. If you want you can leave it specified in your question, otherwise it will end up being a little wide.

  • Could you tell me what shapes they would be?

1 answer

0


Da para fazer dos dois lados, tanto no Android como no seu Server.If you have a relatively small collection of keys to save, which is an option for this situation, use the Apis Sharedpreferences.

SharedPreferences are used in situations where there is no need to create a database, or even when there is little number of data to be stored. In general, this storage can consist of several types of data, including integers.

As SharedPreferences consists of an interface that allows accessing and modifying user preference data. The stored value is presented in key-value format or key-value, that is, each stored preference has an identification or key and associated with it is a value. It allows storage of various types of value, such as int, float, Strings, booleans and sets of Strings. See an example of how it is used:

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("qndFotosEnviadas", 0);
editor.commit();

When you add a photo, you change the value of the key qndFotosEnviadas increasing +1.

To redeem the value before incrementing, you can do so:

int qndFotos = sharedPref.getInt("qndFotosEnviadas", 0);
if(qndFotos<=10){

    qndFotos++;
    editor.putInt("qndFotosEnviadas", qndFotos);
    editor.commit();
    // chama função para tirar foto

} else {
    // exibe mensagem você não pode enviar mais que 10
}

Note: Never, under any circumstances, save user passwords to Sharedpreferences, it is even recommended that no personal user data, such as credit card, phone, and passwords be stored in any way on the device.

  • getActivity command turns red, could you give me an example where I would put the code line? thanks

  • In place of getActivity, put this.

  • without success, the code does not appear nor an error but continues publishing normal

  • Brother, your question doesn’t have all the code necessary to make a more complete answer. I’m just showing you how you can do it using Sharedpreferences, although there are other ways. I’m already in bed, but tomorrow if you complete your question, I’ll explain better how you can do it. If you are in a hurry, you can do some more data persistence research using Sharedpreference. Abs

  • thanks for the help friend, tbm I’m already going to bed.... Could you tell me what you need to help me? abs

  • thanks again, I redid the code and it went all right, abs buddy

  • Nice guy! Success there for you!

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.