i developing group chat app using android-xmpp, in that i don't know how to send and recive pics-image or location (using map).
So any one one can please give me way to do these.
currently , i got text message and add to list view , like following ,
Message msg = new Message(to, Message.Type.groupchat);
msg.setBody(text);
if (Constants.connection != null) {
try {
Constants.connection.sendPacket(msg);
Log.d("Send to room : Name : ", to);
Log.d("store", "store data to db");
//DBAdapter.addUserData(new UserData(text, "", "1" ,beam_id));
} catch (Exception e) {
Log.d("ooo", "msg exception" + e.getMessage());
}
messages.add(text);
runOnUiThread(new Runnable() {
public void run() {
// set to listview
setMyChatAdapter();
}
});
}
and receive using StanzaTypeFilter. So how for image and location sharing ?
I try following code for image using FileTransferManager , using smack-extensions-4.1.3-sources.jar .
private void sendImage()
{
FileTransferManager mg=new FileTransferManager(Constants.connection);
OutgoingFileTransfer transfer = mg.createOutgoingFileTransfer(beam_id+"@"+Constants.conference_name + "/" + Constants.resources);
File file = new File(selectedImagePath);
try {
transfer.sendFile(file, "test_file");
} catch (Exception e) {
e.printStackTrace();
}
while(!transfer.isDone()) {
if(transfer.getStatus().equals(FileTransfer.Status.error)) {
System.out.println("ERROR!!! " + transfer.getError());
} else if (transfer.getStatus().equals(FileTransfer.Status.cancelled)
|| transfer.getStatus().equals(FileTransfer.Status.refused)) {
System.out.println("Cancelled!!! "+ transfer.getError());
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(transfer.getStatus().equals(FileTransfer.Status.refused) || transfer.getStatus().equals(FileTransfer.Status.error)
|| transfer.getStatus().equals(FileTransfer.Status.cancelled)){
System.out.println("refused cancelled error"+ transfer.getError());
} else {
System.out.println("Success");
}
}
But when i access that file using following ,
FileTransferManager mg=new FileTransferManager(Constants.connection);
it give me error ... has a private access of ... So , i find constructor of that file is private , this is jar file so i can not change it to public .
So, how can i access that file-class into my class ?
So, how can i share(send-receive) image and location message in chat ?
Please help me as soon as possible.
Thanks in advance.
try this link: reference
For File send
FileTransferManager manager = new FileTransferManager(connection);
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer('usre2@myHost/Smack');
File file = new File(filenameWithPath);
try {
transfer.sendFile(file, 'test_file');
} catch (XMPPException e) {
e.printStackTrace();
}
while(!transfer.isDone()) {
if(transfer.getStatus().equals(Status.error)) {
System.out.println('ERROR!!! ' + transfer.getError());
} else if (transfer.getStatus().equals(Status.cancelled)
|| transfer.getStatus().equals(Status.refused)) {
System.out.println('Cancelled!!! ' + transfer.getError());
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(transfer.getStatus().equals(Status.refused) || transfer.getStatus().equals(Status.error)
|| transfer.getStatus().equals(Status.cancelled)){
System.out.println('refused cancelled error ' + transfer.getError());
} else {
System.out.println('Success');
}
File Receive:
FileTransferManager manager = new FileTransferManager(connection);
manager.addFileTransferListener(new FileTransferListener() {
public void fileTransferRequest(final FileTransferRequest request) {
new Thread(){
@Override
public void run() {
IncomingFileTransfer transfer = request.accept();
File mf = Environment.getExternalStorageDirectory();
File file = new File(mf.getAbsoluteFile()+'/DCIM/Camera/' + transfer.getFileName());
try{
transfer.recieveFile(file);
while(!transfer.isDone()) {
try{
Thread.sleep(1000L);
}catch (Exception e) {
Log.e('', e.getMessage());
}
if(transfer.getStatus().equals(Status.error)) {
Log.e('ERROR!!! ', transfer.getError() + '');
}
if(transfer.getException() != null) {
transfer.getException().printStackTrace();
}
}
}catch (Exception e) {
Log.e('', e.getMessage());
}
};
}.start();
}
});
The FileTransferManager
class have getInstanceFor(XMPPConnection connection)
to get the instance of the FileTransferManager
. Just provide a valid XMPPConnecton. e.g.
FileTransferManager ftm = FileTransferManager.getInstanceFor(connection)
See this link FileTransferManager too.
Hope this helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With