0
The app works like this: An SMS is received, so the app checks if the number that sent this SMS is registered, if the app checks the first twenty characters of the message, which I call text (example: Light 1.........-LIG , or: Light 1.........-DSL). If this text exists then the app updates the message in the database, otherwise it inserts a new message. The problem is time to Update, not the error in the execution, however it does not update. below the update:
public Long atualiza (ReceiveOne receiveOne) {
db = this.getWritableDatabase();
ContentValues valores = new ContentValues();
valores.put(RECEIVE_ONE_DATA, receiveOne.getReceiveOne());
return (long) db.update(RECEIVE_ONE_NAME, valores, RECEIVE_ONE_KEY + " =?", new String[]{String.valueOf(receiveOne.getId())});
}
and below the code that calls the method:
receiveOne.setReceiveOne(smsBody.toString());
receiveOne.setId(db.questTextReceiverOne(smsBody));
db.atualiza(receiveOne);
The smsBody
is the SMS received. the method questTextReceiverOne()
checks the existence of the text and returns the id.
I tested several update and da methods in the same.
id = 0. //retorno do atualiza = 0
db = SQLiteDatabase: /data/data/com.example.usuario.infinium8/databases/SMS.
In the database I have only one message. The existing message is: led 1.........-LIG ai chega o SMS : led 1.........-DSL, como o texto led 1 - é igual ao que está no banco a mensagem vai para o update.
the updated method is in a Sqliteopenhelper and is called in a BroadcastReceiver
.
The method
db.update()
returns the number of updated records, zero indicates that none was. To update a record you must pass aid
that exists in DB. Check whetherreceiveOne.getId()
returns aid
existing.– ramaral
Okay, so I need to make the questTextReceiverOne(); which is returning the list entry return me the id. I tried to make a list.get(data number in the list) that I don’t even do with delete.
– GBS invents
So, to make this process by a button is simple, in this case I want to occur when the SMS arrives and then that ta, I can not pull the id, nor by getId(), I can only do this in the return of the Insert.
– GBS invents
If the name (Led 1) is unique do the update using name instead of id.
– ramaral
Hmmm.. but how will I use the name in update?
– GBS invents
It would be something like that:
return (long) db.update(RECEIVE_ONE_NAME, valores, RECEIVE_ONE_NomeDoCampoNome + " =?", new String[]{receiveOne.getNome()});
– ramaral
AAAAAEE, I made a method that you enter with the String and it returns the id
– GBS invents