I wanna display the message sent from wma console in LWUIT form...
The sms are stored in record ... and I need to get the sms from the record ..
I have stored the sms in record but having problem in retrieving it and displaying
if (ae.getSource()==inboxlist){
iform = new Form("Message");
try {
record = RecordStore.openRecordStore("Sms", true );
s = new String(record.getRecord(smsindex));
inb = new Label();
inb.setText(s);
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
iform.addComponent(inb);
iform.addCommand(exit);
iform.setCommandListener(this);
iform.show();
}
see my answer at
How to sort recordstore records based on a certain field in it?
use preferance class as it used to save sms
Related
I am trying to read the data from an NFC card I have for a project. It is using Mifare classic 1k and has 16 sectors.
I am able to connect to the card and I'm trying to read the data (I know the data that I want is in the 2nd sector - 2nd Block). I can scan the card fine and it shows me the size of the card so this ensures me that the card is being scanned properly but the data I get when I Log the "data.readBlock(2)" is just the same as the key I use to authenticate it.
What I understand from the code:
Card connects
Auth == true
I can get overall details of the card such as sector count / block count
protected void onNewIntent(Intent intent){
super.onNewIntent(intent);
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
MifareClassic tag = MifareClassic.get(tagFromIntent) ;
try {
//Variables
int sectorCount = tag.getSectorCount();
int tagSize = tag.getSize();
boolean auth;
//Keys
byte[] defaultKeys = new byte[]{};
defaultKeys = MifareClassic.KEY_DEFAULT;
//Connecting to tag
tag.connect();
//auth = true
auth = tag.authenticateSectorWithKeyA(2, defaultKeys);
byte[] data = tag.readBlock(2);
Log.i("OnNewIntent", "Data in sector 2: " + Arrays.toString(data));
} catch (IOException e) {
e.printStackTrace();
}
Expected = "Data in sector 2: The data in sector 2 block 2"
Actual = "Data in sector 2: [B#4df9e32"
The above Actual result changes each time the card is scanned.
What you are getting is the object reference Java uses to keep it in memory. To get a readable version of the data instead use:
Arrays.toString(data);
By the way, you may want to change your code to check if the authentication was successful:
authSuccessful = mfc.authenticateSectorWithKeyA(sector, key);
if(authSuccessful){
// Read the block
creditBlock = mfc.readBlock(block);
String bytesString = Arrays.toString(creditBlock);
Log.i(TAG, bytesString);
} else {
Log.e(TAG, "Auth Failed");
}
Finally, I'm pretty sure what you are trying to do is just the standard Mifare card read so avoid jumping to conclusions. As they say in medicine:
Think horses, not zebras
I have fixed this problem eventually by converting the memory location to a string and then converting that string to a UTF-8 format. Cheers for the help
I am trying to implement a java smack client interacting with Openfire server. I have added the plugin for Monitoring service, also enabled archiving. Now I can see the chat history in the openFire Admin Console. I would like to do the same using Smack. This is the code I have written.
XMPPTCPConnection connection = connectToXMPP(Constants.XMPPADMINUSERNAME, Constants.XMPPADMINPWD ,Constants.XMPPDOMAIN);
MamManager mamManager = MamManager.getInstanceFor(connection);
try {
DataForm form = new DataForm(DataForm.Type.submit);
FormField field = new FormField(FormField.FORM_TYPE);
field.setType(FormField.Type.hidden);
field.addValue(MamElements.NAMESPACE);
form.addField(field);
FormField formField = new FormField("with");
formField.addValue("userlocal1#125.99.44.122");
form.addField(formField);
boolean isSupported = mamManager.isSupported();
// "" empty string for before
RSMSet rsmSet = new RSMSet(maxResults, "", RSMSet.PageDirection.before);
MamManager.MamQueryResult mamQueryResult = mamManager.page(form, rsmSet);
// MamManager.MamQueryResult mamQueryResult1 = mamManager.queryArchive(JidCreate.from("userlocal1#125.99.44.122"));
return mamQueryResult;
} catch (Exception e) {
e.printStackTrace();
}
return null;
Now the problem is the forwardedMessages ArrayList is always null. What am I doing wrong?? isSupported is true and I can see the chathistory on admin console… Please guide…
I notice that you're trying to get the last few archived messages, which makes sense. I'm not sure if your 'before' value should be empty though. For testing purposes, try reversing the page direction, and see if you can get the first/oldest few archived messages.
I have a bot with inline keyboards.
The bot has a text with a button to make an order. After pressing the bot asks the name of the person and below there is a button to cancel the operation.
If I enter the name of the person, I rightly load the new text with the new buttons, but the old cancel button is not deleted and remains visible.
I would like to be able to remove the button after writing the text.
this code is for insert the name:
String answer = "Insert the Name";
EditMessageText new_message = new EditMessageText()
.setChatId(chat_id)
.setMessageId(message_id)
.setText(answer).setParseMode("HTML");
markupInline = new InlineKeyboardMarkup();
List<List<InlineKeyboardButton>> bottoni_totali = new ArrayList<>();
List<InlineKeyboardButton> riga1 = new ArrayList<>();
riga1.add(createButton("annulla", emoji_annulla+" Annulla"));
bottoni_totali.add(riga1);
// Add it to the message
markupInline.setKeyboard(bottoni_totali);
new_message.setReplyMarkup(markupInline);
try {
execute(new_message);
} catch (TelegramApiException e) {
e.printStackTrace();
}
When I insert the name, I show the surname but the old button CANCEL is visible.
String answer = "Now insert the surname";
sendMessage = new SendMessage().setChatId(update.getMessage().getChatId());
sendMessage.setText(answer).setParseMode("HTML");
markupInline = new InlineKeyboardMarkup();
List<List<InlineKeyboardButton>> bottoni_totali = new ArrayList<>();
List<InlineKeyboardButton> riga1 = new ArrayList<>();
riga1.add(createButton("annulla", emoji_annulla+" Annulla"));
bottoni_totali.add(riga1);
// Add it to the message
markupInline.setKeyboard(bottoni_totali);
sendMessage.setReplyMarkup(markupInline);
try {
execute(sendMessage);
} catch (TelegramApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Firstly I would say about this link:
How to hide ReplyKeyboardMarkup after user click in Telegram Bot API
Question above is about InlineKeyboardMarkup and question by link is about ReplyKeyboardMarkup. These two are different things, don't mix them.
Secondly, you have to clarify your question.
but the old cancel button is not deleted and remains visible
What do you mean by that? (screenshots is the best way to explain)
In second snippet of code you use SendMessage instead of EditMessageText (as in first snippet). It means that message with text Now insert the surname will not replace message with text Insert the Name. Now insert the surname will appear as new message.
Seems like you should use EditMessageText in second case too.
I have been trying to scan QR code using zxing and primefaces
filename = getRandomImageName();
byte[] data = captureEvent.getData();
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
.getContext();
String filePathToImage = servletContext.getRealPath("") + filename + ".jpeg";
FileImageOutputStream imageOutput;
try {
imageOutput = new FileImageOutputStream(new File(filePathToImage));
imageOutput.write(data, 0, data.length);
imageOutput.close();
String filePath = filePathToImage;
String charset = "UTF-8"; // or "ISO-8859-1"
Map hintMap = new HashMap();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
String scannedDetails = readQRCode(filePath, charset, hintMap);
System.out.println("Data read from QR Code: " + scannedDetails);
RequestContext.getCurrentInstance().execute("PF('QRcodeDialog').hide();");
RequestContext.getCurrentInstance().update("baseTemplateForm:receiver");
} catch (IOException e) {
showMessage(Constants.SUCCESS_MESSAGE_ID, FacesMessage.SEVERITY_ERROR,
"QR code not scanned properly. Please scan again.", null);
throw new FacesException("Error in writing captured image.", e);
} catch (NotFoundException e) {
showMessage(Constants.MESSAGE_ID_FOR_QR, FacesMessage.SEVERITY_ERROR,
"QR code not scanned properly. Please scan again.", null);
} catch (CommandCenterException e) {
logger.error("Error in fetching receiver details");
}
What I want here is to continuously scan the image and detect QR code by itself instead of calling this function on click of a button.
p:photoCam
To continuously scan is not possible and not something you would like to do, keeping bandwidth and server load in mind. What you could do is use a p:poll to capture a photo once every few seconds. To save bandwidth play with the photoWidth, photoHeight and jpegQuality. Reduce them as far back as you can. Also, don't start the poll immediately, but at the start of a button click, and stop it as soon as you've received a QR code.
pe:codeScanner
From PrimeFaces Extension 10 and up you can use pe:codeScanner to scan QR codes. It's "live" and you can register an Ajax listener to send the scanned codes to a bean.
See:
Scan a QR code and decode it using p:photoCam
I'm working on a server/client project in Java where, at any point during the running of the program, the client can request a set of details related to a unique ID, and the server returns the relevant set of details. This is done through PrintWriter objects accessing the socket.getOutputStream, and works fine.
I am trying to also include the sending/receiving of an image from the server to the client, and have met some very strange behaviour from the program.
The methods that send and receive the images are shown below:
SERVER-SIDE:
//send image associated with item
//through ObjectOutputStream to client
private void sendItemImage(BidItem item)
{
try
{
//wrap object output stream around
//output stream to client at this socket
ObjectOutputStream imageOutput =
new ObjectOutputStream(client.getOutputStream());
//send image object to client
imageOutput.writeObject(item.getItemImage());
}
catch (IOException ioEx)
{
//alert server console
System.out.println("\nUnable to send image for item "
+ item.getItemCode() + " to "
+ bidderName + "!");
//no exit from system
//bidding can still continue
}
}
CLIENT-SIDE:
//to be displayed on GUI
private static void receiveItemImage()
{
try
{
//wrap ObjectInputStream around socket
//to receive objects sent from server
ObjectInputStream imageInput =
new ObjectInputStream(socket.getInputStream());
//read in image and store in ImageIcon instance
image = (ImageIcon) imageInput.readObject();
//re-create label object to be blank
imageLabel = new JLabel();
//remove label containing last image
imagePanel.remove(imageLabel);
//just ignores command if it does not already contain image
//apply image to label
imageLabel.setIcon(image);
//apply image to CENTER of panel
imagePanel.add(imageLabel, BorderLayout.CENTER);
}
//problem in input stream
catch (IOException ioEx)
{
//alert user
JOptionPane.showMessageDialog(
null, "Error receiving image!");
//allow system to continue
//no exit
}
//problem casting to ImageIcon type
catch (ClassNotFoundException cnfEx)
{
//alert user
JOptionPane.showMessageDialog(
null, "Error converting Object to ImageIcon!");
//allow system to continue
//no exit
}
}
So, each time there is a request, an ObjectOutpuStream and ObjectInputStream are created to handle the passing of the image, using the socket.getOutputStream/socket.getInputStream.
These methods are first called when a client connects to the server, and the first image and set of details are sent automatically. This works fine, but any subsequent attempts at requesting the image throughout the program result in the catch (IOException) clause being met, and the error messages shown above being displayed.
I cannot for the life of me work out why it would work the first time but not again after this. If anyone could point me in the right direction, that would be great!
Thanks,
Mark
You should only wrap a stream once. In this case, you can't wrap it again as this will not work for an Object Stream.
Once you are wrapping the stream only once, call ObjectOutputStream.reset() after sending an image. If you don't do this it will just pass the reference to the object again (and use a lot of memory)