I am trying to connect an Android chat app in Eclipse to my own Openfire server. The code I am using is from the Samsung developers site (http://developer.samsung.com/android/technical-docs/Building-a-Chat-Application) and I am having difficulty in connecting the app to my server.
The problem comes from declaring the connections:
public static final String HOST = "talk.google.com";
public static final int PORT = 5222;
public static final String SERVICE = "gmail.com";
public static final String USERNAME = "userid#gmail.com";
public static final String PASSWORD = "password";
This is the example provided by the site, but I am unsure of what the fields should contain if I am using my own openfire server, as opposed to the example above. If someone could give an example of what I should do to connect to my own server, I would really appreciate it.
Thank you for your time.
Related
I am building an app based on the mobile hub sample app. The sample-app has the API keys stored in a class file AWSconfiguration:
public class AWSConfiguration {
// AWS MobileHub user agent string
public static final String AWS_MOBILEHUB_USER_AGENT =
"MobileHub ********* aws-my-sample-app-android-v0.16";
// AMAZON COGNITO
public static final Regions AMAZON_COGNITO_REGION =
Regions.fromName("us-east-1");
public static String AMAZON_COGNITO_IDENTITY_POOL_ID = "us-east-************6";
// Google Client ID for Web application
public static String GOOGLE_CLIENT_ID ="";//"*********************.apps.googleusercontent.com";
public static final Regions AMAZON_DYNAMODB_REGION =
Regions.fromName("us-east-1");
public static String AMAZON_COGNITO_USER_POOL_ID = "************";
public static String AMAZON_COGNITO_USER_POOL_CLIENT_ID = "*************";
public static String AMAZON_COGNITO_USER_POOL_CLIENT_SECRET = "*************";
private static final AWSMobileHelperConfiguration helperConfiguration = new AWSMobileHelperConfiguration.Builder()
.withCognitoRegion(AMAZON_COGNITO_REGION)
.withCognitoIdentityPoolId(AMAZON_COGNITO_IDENTITY_POOL_ID)
.withCognitoUserPool(AMAZON_COGNITO_USER_POOL_ID,
AMAZON_COGNITO_USER_POOL_CLIENT_ID, AMAZON_COGNITO_USER_POOL_CLIENT_SECRET)
.build();
/**
* #return the configuration for AWSKit.
*/
public static AWSMobileHelperConfiguration getAWSMobileHelperConfiguration() {
return helperConfiguration;
}
}
It seems unsafe to store the client secret key this way. What are the risks?
I experiemnted with hiding the keys in JNI files but could not find the proper entry point in the activity to set the keys before they are called from the mobile helper.
Storing in clear text is generally a bad idea, as you guessed. You could use the android keystore, store it encrypted (the stronger the key, the better), obfuscate it with some unique identifier of your device, or access it via some API you control and secure. It's possible to use some other solution, or a combination of the above possibilities. The final decision comes down to you and what your app needs/abilities are, but there's a few ways to hide it.
SharedPreferences.Editor can be a solution.
Password or something like this are stored in SharedPreferences.
I want to setup spring-integration-xmpp on my spring app to make it receive upstream messages from android devices. I can already send messages to the android device using http but I cannot set up the xmpp-connection bean so it gives me:
failed to connect to gcm-preprod.googleapis.com; nested exception is Connection failed. No response from server.:
This is my spring integration configuration:
<int:channel id="gcmOutboundNotificationChannel"/>
<int-xmpp:xmpp-connection
id="xmppConnection"
user="${tracker.server.app.id}#gcm.googleapis.com"
password="${tracker.auth.key}"
host="gcm-preprod.googleapis.com"
port="5236"
subscription-mode="accept_all"/>
<int-xmpp:outbound-channel-adapter
id="gcmOutboundAdapter"
xmpp-connection="xmppConnection"
channel="gcmOutboundNotificationChannel"/>
tracker.server.app.id is a 12 digit number
and tracker.auth.key is like AIzaSyBdfZ4oBaVuu07sjW5e9DnogeUF6NV**** (I put in the asterisks).
What am I missing?
I have configured the xmpp connection as a bean like this:
#Configuration
public class GcmXmppConnection {
#Value("${gcm.senderID}")
private String username;
#Value("${gcm.apiKey}")
private String password;
#Value("${gcm.host}")
private String host;
#Value("${gcm.port}")
private int port;
#Bean(name="gcmConnection")
public XmppConnectionFactoryBean xmppConnectionFactoryBean(){
ConnectionConfiguration configuration = new ConnectionConfiguration(host, port);
configuration.setSecurityMode(SecurityMode.enabled);
configuration.setReconnectionAllowed(true);
configuration.setRosterLoadedAtLogin(false);
configuration.setSendPresence(false);
configuration.setSocketFactory(SSLSocketFactory.getDefault());
// configuration.setDebuggerEnabled(true);
XmppConnectionFactoryBean connectionFactoryBean = new XmppConnectionFactoryBean(configuration);
connectionFactoryBean.setUser(username);
connectionFactoryBean.setPassword(password);
return connectionFactoryBean;
}
}
The configuration is autowired in the xml configuration like this:
<!-- Outbound messages to gcm -->
<int:chain input-channel="androidNotificationOutputChannel">
<int:transformer ref="androidMessageTransformer"></int:transformer>
<int-xmpp:outbound-channel-adapter xmpp-connection="gcmConnection"/>
</int:chain>
<!-- Inbound messages from gcm -->
<int:channel id="gcmInboundNotificationChannel"/>
<int-xmpp:inbound-channel-adapter id="gcmInboundAdapter"
channel="gcmInboundNotificationChannel" xmpp-connection="gcmConnection"
extract-payload="true" auto-startup="true" />
The last piece is androidMessageTransformer, it's pretty simple, like the gcmXmppConnection bean it was coded along the example in google documentation.
#MessageEndpoint
public class AndroidMessageTransformer extends AbstractTransformer {
public final static String DESTINATION_HEADER_KEY="push.destinationID";
private final static String MESSAGE_ID_FORMAT = "%s-%s";
#Value("${gcm.senderID}")
private String senderId;
#Autowired
ObjectMapper om;
#SuppressWarnings("unchecked")
#Override
protected Object doTransform(Message<?> msgIn) throws Exception {
Map<String,String> data = (Map<String, String>) msgIn.getPayload();
String registrationID = msgIn.getHeaders().get(DESTINATION_HEADER_KEY,String.class);
Map<String, Object> gcmPayload = new HashMap<>();
gcmPayload.put("to", registrationID);
gcmPayload.put("message_id", String.format(Locale.ENGLISH, MESSAGE_ID_FORMAT, senderId, UUID.randomUUID().toString()));
gcmPayload.put("data", data);
String gcmJsonPayload = om.writeValueAsString(gcmPayload);
org.jivesoftware.smack.packet.Message xmppMessage = new org.jivesoftware.smack.packet.Message();
xmppMessage.addExtension(new GcmPacketExtension(gcmJsonPayload));
return xmppMessage;
}
}
This works reliably for me, although I have mostly worked with the outbound direction, and never checked much about the inbound side.
I think you are missing auto-startup="true" in the <int-xmpp:outbound-channel-adapter tag. Refer to the following answer might work for you.
I download the chat sample from quickblox and follow all the steps at http://quickblox.com/developers/5_Mins_Guide iam geting unauthorized error
i spending days for it for simple open groupchat feature in my app
please could some one help me.
splashActivity.java is
private static final String APP_ID = <my id>;
private static final String AUTH_KEY = <auth key>;
private static final String AUTH_SECRET = <secret key>;
//
private static final String USER_LOGIN = "vamsi";
private static final String USER_PASSWORD = "******";
You need to go to the QuickBlox Admin Panel, go to the users section and add a new user with the credentials that you will be using first.
After I followed all the steps for the push notification sample app. I wasn't able to send a notifaction to myself. I could send a pushmessage from my PC to my phone, but when I use the button Send myself a Notification nothing happens.
I am using Android sdk
After starting the app I do see that my Device is Registerd
Here is my settings.java
package com.ganyo.pushtest;
/** Change these values to match your setup! */
public class Settings {
static final String UNASSIGNED_ORG_VALUE = "";
// Google Client Id from Google API Console
static final String GCM_SENDER_ID = "xxxxxxxxxxxxx";
// Notifier Name in App Services
static final String NOTIFIER = "androidDev";
static final String API_URL = "https://api.usergrid.com";
static final String ORG = "xxxxxxx";
static final String APP = "sandbox";
// set these if you want to use a user login
static final String USER = null;
static final String PASSWORD = null;
}
I'm not sure what the UNASSIGNED_ORG_VALUE should be.
Thx in advance.
No need to assign any value to UNASSIGNED_ORG_VALUE. It's only used to check that you've entered the other values.
Please check your Android logs as well as the Apigee Console to see what error messages might have been generated during your push attempt. This will help you debug the issue.
Finally, you could try providing your notifier name here in all lowercase. (Note: This shouldn't generally be necessary, but I've heard there may be a issue that affects notifier name resolution.)
I have made a working web server with jetty on an android device, but it only displays a static website, does any one know how to display a folder content of the android device? can it be done with a web page or there is a simpler way to do it? I want it similar to when you connect to a tcp server
Serving static content with Jetty can be done using a ResourceHandler.
A simple example
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ResourceHandler;
public class FolderContents {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
ContextHandler requestContext = new ContextHandler("/filelist");
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase("/path/to/directory/");
resourceHandler.setDirectoriesListed(true);
requestContext.setHandler(resourceHandler);
server.setHandler(requestContext);
server.start();
server.join();
}
}
So, on a request to /filelist/, the directory contents will be printed.