SMACK 4.1 Account manager: Private Access Error in account registration - android

I am getting a strange error while working with account manager in Smack 4.1 for android.
Below is the code snippet:
am = new AccountManager(connection);
Map<String, String> mp = new HashMap<String, String>();
// adding or set elements in Map by put method key and value
// pair
mp.put("username", "user3");
mp.put("password", "ps3");
mp.put("name", "user3");
mp.put("email", "user3#user.com");
try {
am.createAccount("user3", "user3", mp);
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
The code I've used to connect to Openfire Server is:
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
configBuilder.setServiceName("host_name");
configBuilder.setHost("host_name");
configBuilder.setPort(5222);
configBuilder.setCompressionEnabled(false).build();
AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
try {
System.out.println("connecting");
connection.setPacketReplyTimeout(10000);
connection.connect();
System.out.println("connected");
SASLAuthentication.unBlacklistSASLMechanism("PLAIN");
SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
and is running perfect.
The exact error is: "Error:(66, 18) error: AccountManager(XMPPConnection) has private access in AccountManager"
I've wasted like 2-3 hours trying to find it but got no answers. I'm a noob so please forgive me if this is a basic question. Also please reply on that as I am stuck and can not move forward.
Thanks alot for the time!!

You need to get an instance from the accountManager that's relevant to your Xmpp connection.
AccountManager ac = AccountManager.getInstance(XMPPConnection connection)

Related

how to implement smack for xmpp

I'm trying to have my android app to be able to send and receive xmpp message using smack but it does not work and the connect command does not return. I have seen several code example but Smack has new versions and the syntax has changed so I might be doing something wrong :
in my build.graddle file I use :
compile "org.igniterealtime.smack:smack-android-extensions:4.3.0"
compile "org.igniterealtime.smack:smack-tcp:4.3.0"
I'm trying to send a message from myaccount321#xabber.org to myaccount456#xabber.org
I'm trying to connect using hot-chilli.net (Idon't mind using some other server))
everything seems to go well until connection.connect() after which the script does not return without triggering any exception.
Please tell me what I'm doing wrong
TIA
public void sendxmpp(){
XMPPTCPConnectionConfiguration config = null;
try {
XMPPTCPConnectionConfiguration.Builder configbuilder = XMPPTCPConnectionConfiguration.builder();
configbuilder.setUsernameAndPassword("myaccount321","myaccount321pw");
DomainBareJid serviceName = JidCreate.domainBareFrom("hot-chilli.net");
configbuilder.setServiceName(serviceName);
configbuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
configbuilder.setHost("jabber.hot-chilli.net");
configbuilder.setPort(8222);
config=configbuilder.build();
AbstractXMPPConnection connection = new XMPPTCPConnection(config);
try {
connection.connect();
}
catch (SmackException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
catch (XMPPException e) {
e.printStackTrace();
}
catch (InterruptedException e) {
e.printStackTrace();
}
connection.login();
ChatManager chatManager = ChatManager.getInstanceFor(connection);
EntityBareJid jid = JidCreate.entityBareFrom("myaccount321pw#xabber.org");
Chat chat = chatManager.createChat(jid);
chat.sendMessage("Hello");
}
catch (Exception e) {
}
}
OK I got it, the connection process has to be done in its own thread.

Openfire Android PubSub Subscription request aproval

I am new to Openfire and smack, therefore I have questions regarding pubsub feature. Actually, I have created a node with setAccessModel as authorize, shown below.
PubSubManager mgr = new PubSubManager(xmpp.getConnection());
try {
LeafNode leaf = mgr.createNode("testNode");
ConfigureForm form = new ConfigureForm(DataForm.Type.submit);
form.setAccessModel(AccessModel.authorize);
form.setDeliverPayloads(true);
form.setNotifyRetract(true);
form.setPersistentItems(true);
form.setPublishModel(PublishModel.open);
leaf.sendConfigurationForm(form);
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
My question is that when somebody wants to subscribe to above node, how the owner of this node can handle the subscription request? Subscription part is as follows:
PubSubManager mgr = new PubSubManager(xmpp.getConnection());
// Get the node
LeafNode node = null;
try {
node = mgr.getNode("testNode");
node.addItemEventListener(new ItemEventCoordinator());
node.subscribe(senderUser+"#desi.loc");
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
class ItemEventCoordinator implements ItemEventListener {
#Override
public void handlePublishedItems(ItemPublishEvent items) {
final ItemPublishEvent itemstemp=items;
runOnUiThread(new Runnable() {
#Override
public void run() {
//stuff that updates ui
dspySub.setText("Item: " + itemstemp.getItems());
}
});
}
}
When I set form.setAccessModel(AccessModel.open) every thing works fine. Users can publish and subscribe easily but when its AccessModel is authorize, owner don't listen, or might be I don't know how to handle subscription request at owner side with above piece of code. Kindly guide me.
Jawad, I've just replied another guy' question about listening subscription requests. Please take a look:
How can i listen incoming subscription request in smack openfire android
I really hope that it can help you.
Good luck!
PS.: Sorry, but I haven't enough reputation to do a comment :(

Integrating Smack 4.1 in android

I have gone through smack 4.1 documentation as given https://github.com/igniterealtime/Smack/tree/master/documentation . But I'm not getting connected when try to connect to openfire server. Can anyone give me a working code. My openfire configuration is working. I have checked it using mac IM client.
I had the same issue when I tried exactly as in documentation.
But I found some changes needed after a research. Here is the code that I've used.
public void connect() throws IOException, XMPPException, SmackException {
XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
config.setUsernameAndPassword("username","password");
config.setServiceName(Config.XMPP_DOMAIN);
config.setHost(Config.XMPP_HOST);
config.setPort(Config.XMPP_PORT);
mConnection = new XMPPTCPConnection(config.build());
try {
mConnection.connect();
mConnection.login();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
//ChatManager.getInstanceFor(mConnection).addChatListener(this);
}
check out the link working example http://developer.samsung.com/technical-doc/view.do?v=T000000119

android sip api SipProfile builder probleme

hi am working on android sip api i have a problem with creating profile.
i have tested 2 methodes :
1)
try {
SipProfile.Builder builder = new SipProfile.Builder("sip:165#40.134.279.145");
builder.setPassword("******");
builder.setPort(5060);
me = builder.build();
manager.open(me);
} catch (ParseException pe) {
Log.d("error", "connexion error");
}
catch (SipException se) {
Log.d("profile", "error");
}
2)
try {
SipProfile.Builder builder = new SipProfile.Builder(username,domaine);
builder.setPassword("******");
builder.setPort(5060);
me = builder.build();
manager.open(me);
} catch (ParseException pe) {
Log.d("error", "connexion error");
}
catch (SipException se) {
Log.d("profile", "error");
}
==> with the first methode i get a NullPointer exception in Open(me) // me is the variable of the profile
==> with the seconde one i have a parseException however the user name and the domaine are good and tested with a softphone Draytek.
notes : am testing on a device with 4.0 android version and i added permissions to manifest.
Please provide full stack traces of the exception you're catching. Also, have you tried integrating the port into the URI, I.E. "sip:165#40.134.279.145:5060"?
Valid SIP URIs are discussed here.

Android application is freezed - Socket Exception

I made android application that connects to remote server and send some data.
Remote server is Windows application.
Connection method:
private void ConnectToMonitor() {
try {
s = new Socket(SERVER_ADDRESS, TCP_SERVER_PORT);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
This works perfectly if server is online. Application is sending data and server is receiving. But if server is offline android app. is blocked. My question is how to handle this? How to continue with application and avoid error even the server is down?
Remember to call this outside the UIThread.
Follow this tutorial. In android all connections need to be managed outside the UIThread, in the tutorial I linked you will find easy ways to post your results back to the UI (handlers, asynctasks...)
Of course we don't know if the problem is about the thread with just the given code, but it is the most usual error.
First remember to set the socket timeout :
mSocket.setSoTimeout(timeout); //in milliseconds
You can however specify different timeout for connection and for all other I/O operations through the socket:
private void connectToMonitor() {
try {
socket = new Socket();
InetAddress[] iNetAddress = InetAddress.getAllByName(SERVER_ADDRESS);
SocketAddress address = new InetSocketAddress(iNetAddress[0], TCP_SERVER_PORT);
socket.setSoTimeout(10000); //timeout for all other I/O operations, 10s for example
socket.connect(address, 20000); //timeout for attempting connection, 20 s
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Second, in Android, you should perform any network I/O in separate threads!
As an example, using regular Java Threads :
String threadName = getClass().getName() + "::connect";
new Thread(new Runnable() {
#Override
public void run() {
connectToMonitor();
}
}, threadName).start();
You can set A timeout for the socket. Use Socket.setSoTimeout method
socket.setSoTimeout(timesinmilis);
by using this your socket will throw a socket timout exception. You can catch that and do what you want

Categories

Resources