So I had my project working. I am sending objects through a socket connection so I had to add a class to my client side (android project). Now I get this exception:
java.lang.ClassNotFoundException: [LDB.LuceneSearchEngine$LuceneSearchResults;
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2258)
at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1641)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:657)
at java.io.ObjectInputStream.readNewArray(ObjectInputStream.java:1418)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:759)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
at com.shoppiness.radu.jshoppiness.Client.run(Client.java:82)
at com.shoppiness.radu.jshoppiness.MainActivity$connectTask.doInBackground(MainActivity.java:77)
at com.shoppiness.radu.jshoppiness.MainActivity$connectTask.doInBackground(MainActivity.java:61)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "DB.LuceneSearchEngine$LuceneSearchResults" on path: DexPathList[[zip file "/data/app/com.shoppiness.radu.jshoppiness-1/base.apk"],nativeLibraryDirectories=[/data/app/com.shoppiness.radu.jshoppiness-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2258)
at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1641)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:657)
at java.io.ObjectInputStream.readNewArray(ObjectInputStream.java:1418)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:759)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
at com.shoppiness.radu.jshoppiness.Client.run(Client.java:82)
at com.shoppiness.radu.jshoppiness.MainActivity$connectTask.doInBackground(MainActivity.java:77)
at com.shoppiness.radu.jshoppiness.MainActivity$connectTask.doInBackground(MainActivity.java:61)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Suppressed: java.lang.ClassNotFoundException: DB.LuceneSearchEngine$LuceneSearchResults
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 19 more
Caused by: `java.lang.NoClassDefFoundError`: Class is not found using the boot class loader; no stack trace available
LuceneSearchEngine.java is the class I just added. There is another class declared inside LuceneSearchEngine which is LuceneSearchResults.
I tried to delete this classes and create them again with a slightly different name. When I run I get that exception even if I remove that class from the project.
The strange thing is that I created a new project and pasted old classes. Then I added LuceneSearchEngine and LuceneSearchEngineResults but named them differently. I got exactly the same exception even though those classes were never added to the new project.
I tried cleaning and rebuilding but it doesn't work.
MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
package com.shoppiness.radu.jshoppiness;
import java.io.File;
// TODO: create final strings for hardcodede stuff...
public class LuceneSearchEngine {
public static class LuceneSearchResults
{
private static String userSearch = "";
public String getUserSearch() {
return userSearch;
}
public static void setUserSearch(String userSearch1) {
userSearch = userSearch1;
}
private String product_code;
private String adv_name;
private String category;
private String manufacturer;
private String gift_included;
private String product_name;
private String product_desc;
private String product_aff_link;
private String product_pic;
private String price_no_vat;
private String price_vat;
private String free_shipping;
public LuceneSearchResults()
{
product_code = null;
adv_name = "";
category = null;
}
private static int productScore(LuceneSearchResults result)
{
int score = 0;
if(LuceneSearchResults.userSearch.contains(result.product_code))
return 666;
else
{
if(LuceneSearchResults.userSearch.contains(result.adv_name))
score+=4;
if(LuceneSearchResults.userSearch.contains(result.manufacturer))
score+=3;
if(LuceneSearchResults.userSearch.contains(result.category))
score+=2;
if(LuceneSearchResults.userSearch.contains(result.product_name))
score++;
return score;
}
}
// quicksort
private static int partition(LuceneSearchResults results[], int left, int right)
{
int i = left, j = right;
LuceneSearchResults tmp;
int pivot = productScore(results[(left + right) / 2]);
while (i <= j) {
while (productScore(results[i]) < pivot)
i++;
while (productScore(results[j]) > pivot)
j--;
if (i <= j) {
tmp = results[i];
results[i] = results[j];
results[j] = tmp;
i++;
j--;
}
};
return i;
}
public static void quickSort(LuceneSearchResults results[], int left, int right) {
int index = partition(results, left, right);
if (left < index - 1)
quickSort(results, left, index - 1);
if (index < right)
quickSort(results, index, right);
}
//
// getters and setters
public String getProduct_code() {
return product_code;
}
public void setProduct_code(String product_code) {
this.product_code = product_code;
}
public String getAdv_name() {
return adv_name;
}
public void setAdv_name(String adv_name) {
this.adv_name = adv_name;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getGift_included() {
return gift_included;
}
public void setGift_included(String string) {
this.gift_included = string;
}
public String getProduct_name() {
return product_name;
}
public void setProduct_name(String product_name) {
this.product_name = product_name;
}
public String getProduct_desc() {
return product_desc;
}
public void setProduct_desc(String product_desc) {
this.product_desc = product_desc;
}
public String getProduct_aff_link() {
return product_aff_link;
}
public void setProduct_aff_link(String product_aff_link) {
this.product_aff_link = product_aff_link;
}
public String getProduct_pic() {
return product_pic;
}
public void setProduct_pic(String product_pic) {
this.product_pic = product_pic;
}
public String getPrice_no_vat() {
return price_no_vat;
}
public void setPrice_no_vat(String string) {
this.price_no_vat = string;
}
public String getPrice_vat() {
return price_vat;
}
public void setPrice_vat(String string) {
this.price_vat = string;
}
public String getFree_shipping() {
return free_shipping;
}
public void setFree_shipping(String string) {
this.free_shipping = string;
}
}
public static final File INDEX_DIRECTORY = new File("IndexDirectory");
public int getHitsCount()
{
return -1;
}
public void createIndex() {
}
public LuceneSearchResults[] search() {
return null;
}
public static void main(String[] args) {
}
}
Client.java // here
package com.shoppiness.radu.shoppiness;
import android.util.Log;
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
public class Client {
private LuceneEngine.LuceneSearchResults[] serverMessage;
public static String SERVERIP = "5.15.110.111" ; // your computer IP
// address
public static final int SERVERPORT = 3316;
private OnMessageReceived mMessageListener = null;
private boolean mRun = false;
PrintWriter out;
ObjectInputStream in;
/**
* Constructor of the class. OnMessagedReceived listens for the messages
* received from server
*/
public Client(OnMessageReceived listener) {
mMessageListener = listener;
}
/**
* Sends the message entered by client to the server
*
* #param message
* text entered by client
*/
public void sendMessage(String message) {
if (out != null && !out.checkError()) {
out.println(message);
out.flush();
}
}
public void stopClient() {
mRun = false;
}
public void run() {
mRun = true;
try {
// here you must put your computer's IP address.
InetAddress serverAddr = InetAddress.getByName(SERVERIP);
Log.e("serverAddr", serverAddr.toString());
Log.e("TCP Client", "C: Connecting...");
// create a socket to make the connection with the server
Socket socket = new Socket(serverAddr, SERVERPORT);
Log.e("TCP Server IP", SERVERIP);
try {
// send the message to the server
out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())), true);
Log.e("TCP Client", "C: Sent.");
Log.e("TCP Client", "C: Done.");
// receive the message which the server sends back
in = new ObjectInputStream(socket.getInputStream());
// in this while the client listens for the messages sent by the
// server
while (mRun) {
serverMessage = new LuceneEngine.LuceneSearchResults[1000];
serverMessage = (LuceneEngine.LuceneSearchResults[]) in.readObject();
if (serverMessage != null && mMessageListener != null) {
// call the method messageReceived from MyActivity class
Log.d("Radu:", "Object recieved!");
mMessageListener.messageReceived(serverMessage[0].getAdv_name());
Log.d("WIN::", serverMessage[0].getAdv_name());
}
serverMessage = null;
}
Log.e("RESPONSE FROM SERVER", "S: Received Message: '"
+ serverMessage + "'");
} catch (Exception e) {
Log.e("TCP", "S: Error", e);
} finally {
// the socket must be closed. It is not possible to reconnect to
// this socket
// after it is closed, which means a new socket instance has to
// be created.
socket.close();
}
} catch (Exception e) {
Log.e("TCP", "C: Error", e);
}
}
// Declare the interface. The method messageReceived(String message) will
// must be implemented in the MyActivity
// class at on asynckTask doInBackground
public interface OnMessageReceived {
public void messageReceived(Object message);
}
}
connectTask.java
public class connectTask extends AsyncTask<String,String,Client> {
#Override
protected Client doInBackground(String... message) {
//we create a Client object and
Log.d("Radu:", "new client");
mClient = new Client(new Client.OnMessageReceived() {
#Override
//here the messageReceived method is implemented
public void messageReceived(Object message) {
//this method calls the onProgressUpdate
Log.d("Radu:", "publishProgress...");
publishProgress(message.toString());
}
});
mClient.run();
return null;
}
#Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
//in the arrayList we add the messaged received from server
arrayList.add(values[0]);
Log.e("OBJECT_RECIEVED:", values[0].toString());
// notify the adapter that the data set has changed. This means that new message received
// from server was added to the list
}
}
The log is very clear about it:
java.lang.ClassNotFoundException: DB.LuceneSearchEngine$LuceneSearchResults
You are trying to load the class LuceneSearchEngine$LuceneSearchResults from package DB.
In the code posted the package for that class is com.shoppiness.radu.jshoppiness.
Also from the log the error start at com.shoppiness.radu.jshoppiness.MainActivity$connectTask.doInBackground(MainActivity.java:61) so it's better to look there for the error.
Update
You send the "wrong" object and when you read it in the following line you get the class cast exception:
serverMessage = (LuceneEngine.LuceneSearchResults[]) in.readObject();
The problem is the package of the class.
Related
I'm new in Android programming and there is this project I'm working on to be able to turn on my computer using my phone. I have written my codes where by when an item in a list-view is clicked, it will fetch mac address and use it to turn on computer. The problem is that, the packet is never sent, I'm using Emulator. I have tried to search solutions in Google but couldn't find enough break through. Really need your help.
Here are my codes:
package black.cheetah.blackcheetah;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
public class ComputerTurnOnList extends Activity {
public static final int PORT = 9;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_computer_turn_on_list);
if (android.os.Build.VERSION.SDK_INT > 8) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll()
.build();
StrictMode.setThreadPolicy(policy);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void buttonClick(View view) {
String broadcastIP = "192-168-43-171";
String mac = "3C-97-0E-82-3D-BD";
Log.d("Read mac= ", mac);
Log.d("Read ip=", broadcastIP);
ComputerTurnOnList.wakeup(broadcastIP, mac);
}
private static byte[] getMacBytes(String mac) throws IllegalArgumentException {
Log.d("GetMacBytes", "method started");
// TODO Auto-generated method stub
byte[] bytes = new byte[6];
String[] hex = mac.split("(\\:|\\-)");
if (hex.length != 6) {
throw new IllegalArgumentException("Invalid MAC address.");
}
try {
for (int i = 0; i < 6; i++) {
bytes[i] = (byte) Integer.parseInt(hex[i], 16);
Log.d("GetMacbytes", "calculated");
Log.d("GetMacBytes (bytes)", new String(bytes));
}
}
catch (NumberFormatException e) {
Log.e("GetMacBytes","error");
}
return bytes;
}
public static void wakeup(String broadcastIP, String mac) {
Log.d("wakeup", "method started");
if (mac == null) {
Log.d("Mac error at wakeup", "mac = null");
return;
}
try {
byte[] macBytes = getMacBytes(mac);
Log.d("wakeup (bytes)", new String(macBytes));
byte[] bytes = new byte[6 + 16 * macBytes.length];
for (int i = 0; i < 6; i++) {
bytes[i] = (byte) 0xff;
}
for (int i = 6; i < bytes.length; i += macBytes.length) {
System.arraycopy(macBytes, 0, bytes, i, macBytes.length);
}
Log.d("wakeup", "calculating completed, sending...");
InetAddress address = InetAddress.getByName(broadcastIP);
DatagramPacket packet = new DatagramPacket(bytes, bytes.length,address,9);
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
socket.close();
Toast.makeText(null, "Time up! Couldn't find Computer", Toast.LENGTH_SHORT ).show();
Log.d("wakeup", "Magic Packet sent");
}
catch (Exception e) {
Log.e("wakeup", "error" + e.getMessage());
}
}
}
When I run it here come an error:
05-30 06:26:15.607: D/Read mac=(1755): XX-XX-XX-XX-XX-XX
05-30 06:26:15.617: D/Read ip=(1755): xxx-xxx-xx-xxx
05-30 06:26:15.617: D/wakeup(1755): method started
05-30 06:26:15.617: D/GetMacBytes(1755): method started
05-30 06:26:15.617: D/GetMacbytes(1755): calculated
05-30 06:26:15.617: D/GetMacBytes (bytes)(1755): <����������
05-30 06:26:15.617: D/GetMacbytes(1755): calculated
05-30 06:26:15.657: D/GetMacBytes (bytes)(1755): <���������
05-30 06:26:15.657: D/GetMacbytes(1755): calculated
05-30 06:26:15.657: D/GetMacBytes (bytes)(1755): <�������
05-30 06:26:15.667: D/GetMacbytes(1755): calculated
05-30 06:26:15.667: D/GetMacBytes (bytes)(1755): <������
05-30 06:26:15.667: D/GetMacbytes(1755): calculated
05-30 06:26:15.667: D/GetMacBytes (bytes)(1755): <��=��
05-30 06:26:15.667: D/GetMacbytes(1755): calculated
05-30 06:26:15.667: D/GetMacBytes (bytes)(1755): <��=�
05-30 06:26:15.667: D/wakeup (bytes)(1755): <��=�
05-30 06:26:15.667: D/wakeup(1755): calculating completed, sending...
05-30 06:26:15.667: E/wakeup(1755): errorUnable to resolve host "xxx-xxx-xx-xxx": No address associated with hostname
I don't think you can send UDP via emulator or at least it is not that simple. Try it on your real device.
I got it working with this
public class WakeOnLAN {
public static final int DEFAULT_PORT = 9;
private static final String TAG = WakeOnLAN.class.getSimpleName();
private static final String MAC_REGEX = "([0-9a-fA-F]{2}[-:]){5}[0-9a-fA-F]{2}";
public static int sendPacket(String ipStr, String macStr) {
return sendPacket(ipStr, macStr, DEFAULT_PORT);
}
public static int sendPacket(String ipStr, String macStr, int port) throws IllegalArgumentException {
if (port < 0 || port > 65535) {
throw new IllegalArgumentException("Port must be in the range [0, 65535]. Magic packet is usually used on port 7 or 9");
}
byte[] macBytes = getMacBytes(macStr);
byte[] bytes = new byte[6 + 16 * macBytes.length];
try {
for (int i = 0; i < 6; i++) {
bytes[i] = (byte) 0xff;
}
for (int i = 6; i < bytes.length; i += macBytes.length) {
System.arraycopy(macBytes, 0, bytes, i, macBytes.length);
}
InetAddress address = InetAddress.getByName(ipStr);
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, address, port);
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
socket.close();
Log.d(TAG, "Wake-on-LAN packet sent.");
return 0;
} catch (Exception e) {
Log.e(TAG, "Failed to send Wake-on-LAN packet:" + e);
return -1;
}
}
private static byte[] getMacBytes(String macStr) throws IllegalArgumentException {
if (!macStr.matches(MAC_REGEX)) {
throw new IllegalArgumentException("Invalid MAC address");
}
byte[] bytes = new byte[6];
String[] hex = macStr.split("(:|\\-)");
try {
for (int i = 0; i < 6; i++) {
bytes[i] = (byte) Integer.parseInt(hex[i], 16);
}
} catch (NumberFormatException e) {
// Should not happen, the regex forbids it, but it doesn't compile otherwise.
throw new IllegalArgumentException("Invalid hex digit in MAC address.");
}
return bytes;
}
}
And the Activity
public class WakeOnLanActivity extends AppCompatActivity implements View.OnClickListener {
private static final String TEST_IP = "192.168.1.255";
private static final String MAC = "74:D4:35:E7:BA:DC";
private Button btnSend;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wake_on_lan_demo);
setWidgetConnections();
}
private void setWidgetConnections() {
btnSend = (Button) findViewById(R.id.btnSend);
btnSend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
new WakeOnLanTask(TEST_IP, MAC, 9).execute();
}
});
}
class WakeOnLanTask extends AsyncTask<Void, Void, Integer> {
private String IP;
private String MAC;
private int port;
public WakeOnLanTask(String ip, String mac, int port) {
this.IP = ip;
this.MAC = mac;
this.port = port;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Integer doInBackground(Void... args) {
return WakeOnLAN.sendPacket(IP, MAC, port);
}
#Override
protected void onPostExecute(Integer integer) {
super.onPostExecute(integer);
}
}
#Override
public void onClick(View view) {
}
}
EDIT: My solution was to have a constant class with this code:
static EditText Port = (EditText) MainActivity.mDialog.findViewById(R.id.txtPort); static int mPort = Integer.parseInt(Port.getText().toString()); public static final int PORT = mPort;
I've tried to see the other questions and I understand that I've gotta do something with the UIThread? Honestly, I understand nothing. Im new with android.
The app (chat app) worked fine until I wanted to have multiple ports options depending if I'm hosting (port 5050) or joining (port 80) a chat room. From the beginning i just had a constant value of the port (public static final int PORT) but now i cant have that ofc. If you guys have any other suggestions on how i can have two values of PORT, please share your tips.
Anyway, after trying EVERYTHING I decided to put a method in my main class, and just declare it in other classes. This is the mothod for the value of the port:
public int getPORT() {
txtPORT = (EditText) findViewById(R.id.txtPort);
//String txtPORTa = txtPORT.getText().toString();
int dennaPORT = 0;
if (mJoin.isChecked()) {
dennaPORT = Integer.parseInt(txtPORT.getText().toString());
return dennaPORT;
}
else if (mHost.isChecked()) {
dennaPORT = 5050;
return dennaPORT;
}
return dennaPORT;
}
This is my MainActivity
package chat.chris.android.se.chatup;
import android.app.Activity;
import android.app.Dialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
import java.util.ArrayList;
import chat.chris.android.se.chatup.Listeners.ChatListener;
import chat.chris.android.se.chatup.Listeners.ConnectionListener;
import chat.chris.android.se.chatup.Networking.Client;
import chat.chris.android.se.chatup.Networking.Server;
import chat.chris.android.se.chatup.Utilities.ServerUtils;
import static chat.chris.android.se.chatup.R.id.rdioHost;
import static chat.chris.android.se.chatup.R.id.rdioJoin;
public class MainActivity extends Activity {
private Adapter chatAdapter;
private Button btnSendMessage;
private EditText txtMessage;
private ListView lstMessages;
private static Dialog mDialog;
private Client mClient;
private Server mServer;
private EditText txtPORT;
private RadioButton mJoin;
private RadioButton mHost;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
showChatSelection();
chatAdapter = new Adapter(this, new ArrayList<ChatItem>());
lstMessages = (ListView) findViewById(R.id.lstChat);
lstMessages.setAdapter(chatAdapter);
txtMessage = (EditText) findViewById(R.id.txtSay);
txtMessage.setOnEditorActionListener(txtMessageEditorActionListener);
btnSendMessage = (Button) findViewById(R.id.btnSend);
btnSendMessage.setOnClickListener(btnSendMessageClickListener);
Client.setOnChatListener(chatListener);
Client.setOnConnectionListener(connectionListener);
}
public void showChatSelection() {
mDialog = new Dialog(this);
mDialog.setContentView(R.layout.layout_chat_choose);
mDialog.setTitle("Chat Room");
mDialog.setCancelable(false);
final EditText txtServer = (EditText) mDialog.findViewById(R.id.txtAddress);
final TextView lblServer = (TextView) mDialog.findViewById(R.id.lblAddress);
final TextView txtPort = (EditText) mDialog.findViewById(R.id.txtPort);
final RadioButton mHost = (RadioButton) mDialog.findViewById(rdioHost);
final RadioButton mJoin = (RadioButton) mDialog.findViewById(rdioJoin);
try {
lblServer.setText(ServerUtils.getLocalIp(this));
} catch (NullPointerException e) {
mHost.setEnabled(false);
mHost.setChecked(false);
lblServer.setText("Wifi must be enabled to host");
mJoin.setChecked(true);
txtServer.setVisibility(View.VISIBLE);
txtPort.setVisibility(View.VISIBLE);
}
mDialog.findViewById(R.id.btnChoose).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
mDialog.findViewById(R.id.progLoading).setVisibility(View.VISIBLE);
new SetupChat().execute(mHost.isChecked(), mJoin.isChecked() ? txtServer.getText().toString() : "");
}
});
mHost.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
mJoin.setChecked(false);
txtServer.setVisibility(View.INVISIBLE);
txtPort.setVisibility(View.INVISIBLE);
lblServer.setVisibility(View.VISIBLE);
}
}
});
mJoin.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
mHost.setChecked(false);
txtServer.setVisibility(View.VISIBLE);
txtPort.setVisibility(View.VISIBLE);
lblServer.setVisibility(View.INVISIBLE);
}
}
});
mDialog.show();
}
private final OnClickListener btnSendMessageClickListener = new OnClickListener() {
#Override
public void onClick(View v) {
sendMessage();
}
};
private final OnEditorActionListener txtMessageEditorActionListener = new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int id, KeyEvent event) {
if (id == EditorInfo.IME_ACTION_NEXT || id == EditorInfo.IME_ACTION_DONE)
sendMessage();
return true;
}
};
private final ChatListener chatListener = new ChatListener() {
#Override
public void onChat(String message) {
chatAdapter.addItem(new ChatItem("<html>" + message + "</html>", "Friend"));
}
};
private final ConnectionListener connectionListener = new ConnectionListener() {
#Override
public void onDisconnect(Client client) {
chatAdapter.addItem(new ChatItem(client.getName() + " left the chat room", ""));
}
#Override
public void onJoin(Client client) {
chatAdapter.addItem(new ChatItem(client.getName() + " joined the chat room", ""));
}
};
public void sendMessage() {
String message = txtMessage.getText().toString();
if(message == null || message.isEmpty())
return;
message = message.replace(">", ">");
message = message.replace("<", "<");
try {
if (mServer != null) {
mServer.sendMessage(message);
chatAdapter.addItem(new ChatItem(message, "You"));
} else if (mClient != null) {
mClient.sendMessage(message);
chatAdapter.addItem(new ChatItem(message, "You"));
} else {
return;
}
} catch (Exception e) {
chatAdapter.addItem(new ChatItem(e.getMessage(), "<font color='red'>Error</font>"));
return;
}
txtMessage.setText("");
}
public int getPORT() {
txtPORT = (EditText) findViewById(R.id.txtPort);
//String txtPORTa = txtPORT.getText().toString();
int dennaPORT = 0;
if (mJoin.isChecked()) {
dennaPORT = Integer.parseInt(txtPORT.getText().toString());
return dennaPORT;
}
else if (mHost.isChecked()) {
dennaPORT = 5050;
return dennaPORT;
}
return dennaPORT;
}
private class SetupChat extends AsyncTask<Object,Void, Boolean> {
#Override
protected Boolean doInBackground(Object... args) {
try {
if ((Boolean)args[0]) {
mServer = new Server();
new Thread(mServer).start();
} else {
String address = args[1].toString();
mClient = Client.connect(address);
if (mClient == null)
return true;
new Thread(mClient).start();
}
} catch (Exception e) {
e.printStackTrace();
return true;
}
return false;
}
#Override
protected void onPostExecute(Boolean errors) {
if (errors)
Toast.makeText(getApplicationContext(), "Någonting gick fel\nSkrev du in allting rätt?", Toast.LENGTH_LONG).show();
else
mDialog.dismiss();
}
}
}
This is the client class
package chat.chris.android.se.chatup.Networking;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import chat.chris.android.se.chatup.Listeners.ChatListener;
import chat.chris.android.se.chatup.Listeners.ConnectionListener;
import chat.chris.android.se.chatup.MainActivity;
import chat.chris.android.se.chatup.Utilities.Crypto;
public class Client implements Runnable {
private BufferedReader reader;
private DataOutputStream writer;
private boolean disconnecting;
private byte[] cryptoKey;
private String name;
private static ChatListener chatListener;
private static ConnectionListener connectionListener;
//Instansierar ny klient
public Client(Socket s) throws IOException {
cryptoKey = new byte[16];
try {
reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
writer = new DataOutputStream(s.getOutputStream());
} catch (IOException e) {
disconnect();
return;
}
}
//Ger klienten ett namn
public String getName() {
return name;
}
//Sätter namnet
public void setName(String name) {
this.name = name;
}
public static void setOnChatListener(ChatListener listener) {
chatListener = listener;
}
public static void setOnConnectionListener(ConnectionListener listener) {
connectionListener = listener;
}
public BufferedReader getReader() {
return reader;
}
public byte[] getKey(){
return cryptoKey;
}
public void setKey(byte[] key) {
cryptoKey = key;
}
#Override
public void run() {
if (connectionListener != null) {
connectionListener.onJoin(this);
}
try {
while (!disconnecting) {
String read;
if ((read = reader.readLine()) != null) {
if (chatListener != null) {
chatListener.onChat(Crypto.decrypt(read, cryptoKey));
}
}
else{
return;
}
Thread.sleep(5);
}
} catch (IOException e) {
disconnect();
} catch (Exception e) {
e.printStackTrace();
disconnect();
}
}
//Connectar till adressen och returnerar klienten
public static Client connect(String address) throws IOException {
MainActivity porten = new MainActivity();
int PORT;
PORT = porten.getPORT();
InetAddress localAddress = InetAddress.getByName(address);
InetSocketAddress localSocketAddress = new InetSocketAddress(localAddress, PORT);
Socket socket = new Socket();
socket.connect(localSocketAddress, 5000);
Client client = new Client(socket);
socket.getInputStream().read(client.cryptoKey, 0, 16);
System.out.println("Client -> " + new String(client.cryptoKey));
return client;
}
public void sendMessage(String message) throws Exception {
if(message == null || message.isEmpty())
return;
writer.writeUTF(Crypto.encrypt(message, cryptoKey));
}
public void disconnect() {
if (connectionListener != null) {
connectionListener.onDisconnect(this);
}
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
reader = null;
writer = null;
}
}
And this is the server class
package chat.chris.android.se.chatup.Networking;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Random;
import chat.chris.android.se.chatup.MainActivity;
import static chat.chris.android.se.chatup.Utilities.Constants.MAX_USERS;
//import static chat.chris.android.se.chatup.Utilities.Constants.PORT;
public class Server implements Runnable {
private ArrayList<Client> clientList;
private ServerSocket mSocket;
private byte[] cryptoKey;
private boolean shuttingDown;
MainActivity porten = new MainActivity();
//Instansierar en ny server chatt
public Server() throws IOException {
int PORT = porten.getPORT();
mSocket = new ServerSocket(PORT);
clientList = new ArrayList<>();
Random mRand = new SecureRandom();
cryptoKey = new byte[16];
mRand.nextBytes(cryptoKey);
System.out.println("Server ->" + new String(cryptoKey));
}
public boolean isShuttingDown() {
return shuttingDown;
}
public void setShuttingDown(boolean shuttingDown) {
this.shuttingDown = shuttingDown;
}
#Override
public void run() {
while (!shuttingDown) {
Socket socket = null;
Client client;
try {
socket = this.mSocket.accept();
if (clientList.size() >= MAX_USERS) {
socket.close();
return;
}
socket.getOutputStream().write(cryptoKey);
client = new Client(socket);
client.setKey(cryptoKey);
new Thread(client).start();
clientList.add(client);
} catch (IOException e) {
e.printStackTrace();
try {
if (socket != null)
socket.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
public void sendMessage(String message) throws Exception {
for (Client client : clientList) {
if (shuttingDown)
return;
client.sendMessage(message);
}
}
public void shutdown() {
shuttingDown = true;
try {
mSocket.close();
} catch (IOException e) {
} finally {
mSocket = null;
}
}
}
With this setup im getting these errors:
05-04 00:41:58.969 12319-12370/chat.chris.android.se.chatup W/System.err﹕ java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
05-04 00:41:58.970 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at android.os.Handler.<init>(Handler.java:200)
05-04 00:41:58.975 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at android.os.Handler.<init>(Handler.java:114)
05-04 00:41:58.975 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at android.app.Activity.<init>(Activity.java:793)
05-04 00:41:58.975 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at chat.chris.android.se.chatup.MainActivity.<init>(MainActivity.java:32)
05-04 00:41:58.976 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at chat.chris.android.se.chatup.Networking.Server.<init>(Server.java:21)
05-04 00:41:58.976 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at chat.chris.android.se.chatup.MainActivity$SetupChat.doInBackground(MainActivity.java:229)
05-04 00:41:58.976 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at chat.chris.android.se.chatup.MainActivity$SetupChat.doInBackground(MainActivity.java:221)
05-04 00:41:58.976 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
05-04 00:41:58.976 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-04 00:41:58.976 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
05-04 00:41:58.976 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-04 00:41:58.976 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-04 00:41:58.976 12319-12370/chat.chris.android.se.chatup W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
NEVER create an instance of an Activity, Service, or ContentProvider yourself. Those are always created by the framework. Delete:
MainActivity porten = new MainActivity();
Pass the port into the strangely-named Server class by some other means, such as a constructor parameter or setter method.
I'm developping and android application in which i wan't to read a local json file to populate a ListView, the problem is that i can't read the local json file, and here how i proceed.
First i created an object class because i want to work with ObjectMapper.
already created the base classes (Theme, CouchesTheme and ClassesEvenement).
here's the subclasse LireTheme:
package com.myapp.theme;
public class LireTheme {
private Theme theme;
private CouchesTheme couchesTheme;
private ClassesEvenement classesEvenement;
private String message;
private boolean ok;
public LireTheme() {
super();
// TODO Auto-generated constructor stub
}
public LireTheme(Theme theme, CouchesTheme couchesTheme,
ClassesEvenement classesEvenement, String message, boolean ok) {
super();
this.theme = theme;
this.couchesTheme = couchesTheme;
this.classesEvenement = classesEvenement;
this.message = message;
this.ok = ok;
}
public Theme getTheme() {
return theme;
}
public void setTheme(Theme theme) {
this.theme = theme;
}
public CouchesTheme getCouchesTheme() {
return couchesTheme;
}
public void setCouchesTheme(CouchesTheme couchesTheme) {
this.couchesTheme = couchesTheme;
}
public ClassesEvenement getClassesEvenement() {
return classesEvenement;
}
public void setClassesEvenement(ClassesEvenement classesEvenement) {
this.classesEvenement = classesEvenement;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public boolean isOk() {
return ok;
}
public void setOk(boolean ok) {
this.ok = ok;
}
}
second i created a correspondence HashMap class of Theme list.
package com.myapp.recensement;
import java.util.ArrayList;
import java.util.HashMap;
import com.myapp.theme.LireTheme;
public class LireThemes extends HashMap<String, ArrayList<LireTheme>> {
private static final long serialVersionUID = 1L;
}
and then use it like this.
package com.myapp.recensement;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.ObjectMapper;
import android.os.Environment;
import android.util.Log;
import com.myapp.theme.LireTheme;
public class LireThemesController {
private ObjectMapper objectMapper = null;
private JsonFactory jsonFactory = null;
private JsonParser jp = null;
private ArrayList<LireTheme> themeList = null;
private LireThemes lirethemes = null;
private File jsonFile;
boolean availble=false;
public LireThemesController() {
objectMapper = new ObjectMapper();
jsonFactory = new JsonFactory();
}
public void init() {
availble=isExternalStorageReadble();
if(availble){
Log.w("myApp", "file available");
}else{
Log.w("myApp", "file not available");
}
jsonFile = new File("c:\\lireThemes.json");
try{
jp = jsonFactory.createJsonParser(jsonFile);
lirethemes = objectMapper.readValue(jp, LireThemes.class);
themeList = lirethemes.get("themes");
} catch(JsonParseException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
}
public ArrayList<LireTheme> findAll() {
return themeList;
}
public LireTheme findById(int id) {
return themeList.get(id);
}
public boolean isExternalStorageReadble() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
}
and also already added the permission in the AndroidManifest.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
when i run i get this error :
12-29 04:16:04.287: W/System.err(2060): java.io.FileNotFoundException: /c:\lireThemes.json: open failed: ENOENT (No such file or directory).
any solution for that problem please ?
You cannot read a file on your Android device from c:\, which is a Windows File System path.
You have to copy your JSON file inside the Assets folder and then load it using
public String loadJSONFromAsset() {
String json = null;
try {
InputStream is = getAssets().open("yourfilename.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
The Problem is jsonFile = new File("c:\\lireThemes.json");
There is no c:\lireThemes.json file on your android device.
If you add the file to your assets directory (in your project) you can access by getAssets().open("lireThemes.json") which will return an input stream
or you can put it in your res/raw folder and access it by getActivity().getResources().openRawResource(R.raw.lireThemes) which will also return an input stream
I'm trying to implement a function to listen to door 1900 and catch alive message and device ip, I tried to use some libs I found but my applications crashes all the time just trying to initiate the app.
this is my main function
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splash_screen_layout);
//----------SSDP para identificação da STB--------------------------------
SSDPSocket sock;
try {
sock = new SSDPSocket();
while (true) {
DatagramPacket dp = sock.receive(); **//crashes here**
String c = new String(dp.getData());
System.out.println(c);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//---------------------------------------------------------------------
rest of the lib code
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import java.net.SocketAddress;
public class SSDPSocket {
SocketAddress mSSDPMulticastGroup;
MulticastSocket mSSDPSocket;
public SSDPSocket() throws IOException {
InetAddress localInAddress = InetAddress.getLocalHost(); **//crashes here first**
System.out.println("Local address: " + localInAddress.getHostAddress());
mSSDPMulticastGroup = new InetSocketAddress(SSDP.ADDRESS, SSDP.PORT);
mSSDPSocket = new MulticastSocket(new InetSocketAddress(localInAddress,
0));
NetworkInterface netIf = NetworkInterface
.getByInetAddress(localInAddress);
mSSDPSocket.joinGroup(mSSDPMulticastGroup, netIf);
}
/* Used to receive SSDP packet */
public DatagramPacket receive() throws IOException {
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf, buf.length);
mSSDPSocket.receive(dp);
return dp;
}
public void close() {
if (mSSDPSocket != null) {
mSSDPSocket.close();
}
}
}
public class SSDP {
/* New line definition */
public static final String NEWLINE = "\r\n";
public static final String ADDRESS = "239.255.255.250";
public static final int PORT = 1900;
/* Definitions of start line */
public static final String SL_NOTIFY = "NOTIFY * HTTP/1.1";
public static final String SL_MSEARCH = "M-SEARCH * HTTP/1.1";
public static final String SL_OK = "HTTP/1.1 200 OK";
/* Definitions of search targets */
public static final String ST_RootDevice = "ST:rootdevice";
public static final String ST_ContentDirectory = "ST:urn:schemas-upnp- org:service:ContentDirectory:1";
/* Definitions of notification sub type */
public static final String NTS_ALIVE = "NTS:ssdp:alive";
public static final String NTS_BYE = "NTS:ssdp:byebye";
public static final String NTS_UPDATE = "NTS:ssdp:update";
}
public class SSDPSearchMsg {
static final String HOST = "Host:" + SSDP.ADDRESS + ":" + SSDP.PORT;
static final String MAN = "Man:ssdp:discover";
int mMX = 3; /* seconds to delay response */
String mST; /* Search target */
public SSDPSearchMsg(String ST) {
mST = ST;
}
public int getmMX() {
return mMX;
}
public void setmMX(int mMX) {
this.mMX = mMX;
}
public String getmST() {
return mST;
}
public void setmST(String mST) {
this.mST = mST;
}
#Override
public String toString() {
StringBuilder content = new StringBuilder();
content.append(SSDP.SL_MSEARCH).append(NEWLINE);
content.append(HOST).append(NEWLINE);
content.append(MAN).append(NEWLINE);
content.append(mST).append(NEWLINE);
content.append("MX:" + mMX).append(NEWLINE);
content.append(NEWLINE);
return content.toString();
}
}
Nothing seems to be wrong.
Have you add the multicast permission in Mainifest?
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"></uses-permission>
Android doesnt like you doing expensive operations in the main thread and it throws an exception when yo do it. Try executing that code with a new thread you create. Then it should work.
I've recently read about XMPP and I would like to make an application which can send and receive IM messages so that I could get some experience with using XMPP. The problem is I hardly know anything about using XMPP or about using it with Android. I was wondering if someone could point me in the right direction on how to use XMPP with Android.
Thanks!
Well to start with XMPP you have to
Install OpenFire (The chat server)
Add the smack.jar XMPP client jar into the Android app
Implement the PacketListener like such
public class MyPacketListener implements PacketListener {
#Override
public void processPacket(Packet packet) {
// Write the implementation code here.
//The packet contains the message and the metadata about the message.
}
}
4.Next you need to implement the to handle the connection fail gracefully as such.
public class XMPPConnectionFailedException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1L;
#Override
public String toString() {
return "The Chat server or the Connection to the chat server failed";
}
}
5.Next you would need the class that actually does the connecting to the XMPP server and here is a implementations
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smackx.PrivateDataManager;
import com.test.chat.MyPacketListener;
import com.testchat.exception.XMPPConnectionFailedException;
public class ChatUtil {
public final static String SERVER_HOST = "serverip";
public final static int SERVER_PORT = 5222;
public final static String SERVICE_NAME = "p2547738.pubip.serverbeach.com";
private static XMPPConnection xmppConnection;
public static String CURRENT_RECIPIENT_CHAT_ID;
public static String CURRENT_RECIPIENT_NAME;
public static final String IN = "IN";
public static final String OUT = "OUT";
public static String CURRENT_RECIPIENT_FB_IMAGE;
public static boolean STARTED = false;
public static XMPPConnection getXmppConnection(String username) throws XMPPConnectionFailedException {
try {
if (xmppConnection == null) {
ConnectionConfiguration config = new ConnectionConfiguration(SERVER_HOST, SERVER_PORT, SERVICE_NAME);
xmppConnection = new XMPPConnection(config);
}
if (!xmppConnection.isConnected()) {
xmppConnection.connect();
}
if (!xmppConnection.isAuthenticated()) {
xmppConnection.login(username, "123");
ProviderManager pm = ProviderManager.getInstance();
pm.addIQProvider("query", "jabber:iq:private",new PrivateDataManager.PrivateDataIQProvider());
PacketFilter packetFilter = new MessageTypeFilter(Message.Type.chat);
xmppConnection.addConnectionListener(new ConnectionListener() {
#Override
public void reconnectionSuccessful() {
System.out.println("reconnectionSuccessful");
}
#Override
public void reconnectionFailed(Exception arg0) {
System.out.println("reconnectionFailed");
}
#Override
public void reconnectingIn(int arg0) {
System.out.println("reconnectingIn");
}
#Override
public void connectionClosedOnError(Exception arg0) {
System.out.println("connectionClosedOnError");
}
#Override
public void connectionClosed() {
System.out.println("connectionClosed");
}
});
MyPacketListener listener = new MyPacketListener();
xmppConnection.addPacketListener(shareFareChatListener,packetFilter);
}
Presence presence = new Presence(Presence.Type.available);
xmppConnection.sendPacket(presence);
ChatUtil.STARTED = true;
} catch (Exception e) {
throw new XMPPConnectionFailedException();
}
return xmppConnection;
}
}
6.Finally you try to connect your to the XMPP server using the credentials you used to sign users up as such
private void connectToChat(final String nickname) {
System.out.println("Connect to chat ...");
class ConnectToChatAsync extends AsyncTask {
#Override
protected Integer doInBackground(Context... params) {
try {
Listener.currentActivity = context;
ChatUtil.getXmppConnection(nickname);
return SERVER_SUCCESS_RESPONSE;
}
catch ( XMPPConnectionFailedException e) {
System.err.println("XMPPConnectionFailedException : " + e);
}
return CONNECTIVITY_PROBLEM;
}
#Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
if(result == CONNECTIVITY_PROBLEM){
// ApplicationDialog.showFeedBackDialog(ProjectConstants.XMPP_CHAT_FAILED, context);
}
}
}
new ConnectToChatAsync().execute();
}
That should settle you Programatically, all you got to do is Setup the Openfire Environment.
These links should help you out on that department
Create Your Own Jabber-Based Server That Works With iChat or Any Jabber Client
DIY: Set up the Openfire internal chat server