基本上我有一个运行整个项目的Main类.代码工作正常但是一旦App没有聚焦它变得不活跃.我想知道如何将它作为一项服务.一个会在启动时启动.
该应用程序将是用于通知的单向消息系统. I.E.
桌面客户端 – > Openfire Server – > Android XMPP服务 – >存储(DB) – >用于显示的Android GUI
我可以使用BEEM源,但它太功能和隔行扫描.我是一个轻量级的服务.
代码:
public class MainActivity extends Activity {
public static final String HOST = "fire.example.com";
public static final int PORT = 5222;
public static final String SERVICE = "example.com";
public static final String USERNAME = "metest@fire.example.com";
public static final String PASSWORD = "mepass";
private XMPPConnection connection;
private ArrayListFailed to connect to "+ connection.getHost());
Log.e("XMPPChatActivity",ex.toString());
setConnection(null);
}
try {
connection.login(USERNAME,PASSWORD);
Log.i("XMPPChatActivity","Logged in as" + connection.getUser());
// Set the status to available
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
setConnection(connection);
Roster roster = connection.getRoster();
CollectionFailed to log in as "+ USERNAME);
Log.e("XMPPChatActivity",ex.toString());
setConnection(null);
}
dialog.dismiss();
}
});
t.start();
dialog.show();
}
}
所以基本上,我如何使这项服务
最佳答案
我想这个给定链接的例子可以让你想到它是一个服务. http://android.codeandmagic.org/small-test-of-asmack-xmpp-client-library/
原文链接:https://www.f2er.com/android/430804.html