I want to create a messaging application for Android, so I've been reading up about XMPP and Asmack.
Asmack sounds pretty much exactly what I want, especially after reading this other question - Android and XMPP: Currently available solutions.
However, I'm fairly new to Android programming and also Github.
I have found the src for Asmack at https://github.com/Flowdalic/asmack, and also downloaded the jar from http://asmack.freakempire.de/4.0.4/, which I have included in my project. However I am unsure how the folders in the github asmack folder are supposed to be used. After hours trawling google trying to find some sort of step by step guide on how to set aSmack up, and not finding anything useful, I'm losing the will to live!
I'm using the following example code I found on the Smack github page, and I dont get any errors:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
XMPPTCPConnection connection = new XMPPTCPConnection("jabber.org");
try {
connection.connect();
connection.login("mtucker", "password");
} catch (SmackException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Chat chat = ChatManager.getInstanceFor(connection)
.createChat("jsmith#jivesoftware.com", new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message);
}
});
try {
chat.sendMessage("Howdy!");
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
However I haven't used the 'build environment' from aSmack github repository - how is this meant to be included/used?
Thanks for any help!
You need to add single Jar file (last version now is 4.0.6) to your library and also don't forget to set proper permissions in manifest file.
Related
I am creating java files from json Objects using a library called jsonschema2pojo-core.jar. It successfully creates the required files for me. Now I need to access the newly(dynamically) created file and creates its instance to use it further.
But as the newly created class is still not in the classpath I am unable to do this. Tried to do my part of research and figured out that Eclipse jars allows such refresh only in plugin projects. Can anyone suggest some thing for this?
public static void main(String[] args){
String fileName = "MyJavaFile";
POJOBuilder pojo = new POJOBuilder();
pojo.buildPOJO("file:///C:/mypath/myJSON.json", fileName); //generates the java file MyJavaFile.java
Object obj = null;
try {
obj = Class.forName("com.mypackage."+fileName).newInstance(); // Java file not available yet
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Can this be done through threads? I mean wait until the creation of the POJO is done and then start with the rest after that?
Whenever I run the below code on a Windows 7 machine, I get odd artifacts above one of the buttons.
Typically it's a straight line above whatever button is highlighted by default and as tab over the other buttons I get a straight line above the other buttons as well.
It also looks like I get a line at the very top of the Window. When I've witnessed these same artifacts before in different java UI's I've worked on I've had to do object.setBorder(BorderFactory.createLineBorder(Color.someMatchingColor)). This obviously isn't an option if I'm doing the JOptionPane method.
Is there some known issue with java?
public class TestProj {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JOptionPane.showConfirmDialog(null, "Test");
}
}
I developed a Java ServerSocket that is always running and it executes many modules . My server start by execution a BatchScript file (start.bat). I want to test if the module is successfully executed and give the user w feedback on the cmd console(when i launch the server from eclipse i can see the long on eclipse console only) . I want to check my server statut after a periode of time knowing that it is always running .
Here is the implementation of my server :
public Server() throws InterruptedException
{
//this.es = e;
try {
sockserv= new ServerSocket(6020) ;
System.out.println("Server Started");
myModule mod= new myModule();
mod.displayLogOnCmd();
mod.checkServerEveryPeriodOfTime();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
#Override
public void run()
{
while(SERVER_STATUT)
{
try {
Socket socket = sockserv.accept();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
My Question :
How to display log info of eclipse in the Cmd ? and how to see if the server launched the module or not ??
Thank You :)
I'm trying to develop one java function to retrieve the id of one specific folder over Google Docs, but the documentation over this language is poor and have problems to develop it. Until now I've can make this, but don't work, it never show my the document id of my folder
public void findfolder(String folderName) throws MalformedURLException,IOException,ServiceException{
URL feedUrla=new URL("https://docs.google.com/feeds/default/private/full/-/folder");
DocumentQuery query = new DocumentQuery(feedUrl);
query.setTitleQuery(folderName);
query.setTitleExact(true);
DocumentListFeed feed=null;
try {
feed = client.getFeed(query, DocumentListFeed.class);
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
for (DocumentListEntry entry : feed.getEntries()) {
System.out.println(entry.getDocId());
}
}`
I am trying to get the Message-Id of the sent message by using listeners.
I am implementing
javax.mail.event.TransportListener with concrete methods given in code sample.
It listens to javax.mail.event.TransportEvent which gets generated when void javax.mail.Transport.sendMessage(.....) is called.
To my surprise I get none of the method gets called when I actually send the mail..??? When does it actually get called ? Do I need to add any wait time after calling sendMessage(..)??
Doesn't it happen in real time ?
#Override
public void messageDelivered(TransportEvent e)
{
try {
System.out.println(e.getMessage().getHeader("Message-Id")[0]);
} catch (MessagingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
#Override
public void messageNotDelivered(TransportEvent e)
{
try {
System.out.println(e.getMessage().getHeader("Message-Id")[0]);
} catch (MessagingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
#Override
public void messagePartiallyDelivered(TransportEvent e)
{
try {
System.out.println(e.getMessage().getHeader("Message-Id")[0]);
} catch (MessagingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Did you register your listener with the Transport instance that's being used to send the message? Remember that the static Transport.send() method creates its own Transport instance that you never see.