question about chat in android app

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

41 Replies - 2786 Views - Last Post: 25 December 2012 - 08:11 PM

#31 Vagosm  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 91
  • Joined: 15-May 12

Re: question about chat in android app

Posted 30 November 2012 - 02:59 PM

I fix the problem with window settins , but i can't conect in the chat of facebook, or msn, or gmail and i don't know why, if anyone can helo me please..
Was This Post Helpful? 0
  • +
  • -

#32 JHol  Icon User is offline

  • New D.I.C Head

Reputation: 14
  • View blog
  • Posts: 45
  • Joined: 10-February 11

Re: question about chat in android app

Posted 03 December 2012 - 01:27 PM

you should have a look on the response from gmail,facebook,msn. and log the output!
and you should preferible consentrate on developing one service at a time, instead of all at once. it makes life a bit more easy!
Was This Post Helpful? 0
  • +
  • -

#33 Vagosm  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 91
  • Joined: 15-May 12

Re: question about chat in android app

Posted 03 December 2012 - 03:28 PM

View PostJHol, on 03 December 2012 - 01:27 PM, said:

you should have a look on the response from gmail,facebook,msn. and log the output!
and you should preferible consentrate on developing one service at a time, instead of all at once. it makes life a bit more easy!


The spinner have the Provision , you choice one of th Provision (facebook,gmail.etc) and the app by his self pass port, host and service in
ConnectionConfiguration connectionConfig =
            new ConnectionConfiguration(host, port, servs); 
.

can you emplain me what is the problem in my code?
i cant understouded.
Was This Post Helpful? 0
  • +
  • -

#34 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10385
  • View blog
  • Posts: 38,434
  • Joined: 27-December 08

Re: question about chat in android app

Posted 07 December 2012 - 01:34 PM

First, please speak in proper English. We are professionals, not teen girls.

Second, you need to post all your code and a specific description of your problems or errors.
Was This Post Helpful? 0
  • +
  • -

#35 Vagosm  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 91
  • Joined: 15-May 12

Re: question about chat in android app

Posted 08 December 2012 - 02:52 PM

View Postmacosxnerd101, on 07 December 2012 - 01:34 PM, said:

First, please speak in proper English. We are professionals, not teen girls.

Second, you need to post all your code and a specific description of your problems or errors.


Sorry for my bad english..
heare is the code i chοose the facebook or msn or gmail and write my username and passord and the application closes by itself not to load the account to do chat..

code for chat
 package com.example.multimedia;

import android.app.Activity;
import java.util.ArrayList;
import java.util.List;
import com.example.multimedia.R; 
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils;
import android.content.Intent;
import android.util.Log;
import android.widget.TextView;


public class ChatActivity extends Activity {
	 
	private ArrayList<String> messages = new ArrayList();
	private Handler handler = new Handler();
	private xmppsettings settings;
	private EditText recipient;
	private EditText text;
	private ListView list;
	private XMPPConnection connection;
	 
	@Override
	public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
       setContentView(R.layout.chat_layout);

       recipient = (EditText) this.findViewById(R.id.recipient);
       text = (EditText) this.findViewById(R.id.text);
       list = (ListView) this.findViewById(R.id.messageList);
       setListAdapter();
      
       
       settings = new xmppsettings(this);
       
       Button setup = (Button) this.findViewById(R.id.settings);
       
       setup.setonclickListener(new View.onclickListener() {
    	               public void onclick(View view) {
    	            	   handler.post(new Runnable() {
    	   	                    public void run() {
    	   	                    	settings.show();
    	   	                    	//settings.dismiss();
    	                       }
    	                   });	 
          }
    	  	        });
      
       Button send = (Button) this.findViewById(R.id.send);
       
       send.setonclickListener(new View.onclickListener() {
          
           public void onclick(View v) {
               String to = recipient.getText().toString();
               String text1 = text.getText().toString();
              
               Log.i("XMPPClient", "Sending text [" + text + "] to [" + to + "]");
               Message msg = new Message(to, Message.Type.chat);// error
               msg.setBody(text1);
               connection.sendPacket(msg);
               messages.add(connection.getUser() + ":");// error
               messages.add(text1);
               setListAdapter();               
           }
       });       
   }
  
   //Called by settings when connection is established
  
   public void setConnection (XMPPConnection connection) {
       this.connection = connection;
       if (connection != null) {
           //Packet listener to get messages sent to logged in user
           PacketFilter filter = new MessageTypeFilter(Message.Type.chat); 
           connection.addPacketListener(new PacketListener() { 
               public void processPacket(Packet packet) {  
                   Message message = (Message) packet;  
                   if (message.getBody() != null) {
                       String fromName = StringUtils.parseBareAddress(message.getFrom()); // error
                       messages.add(fromName + ":");
                       messages.add(message.getBody());
                       handler.post(new Runnable(){
                           public void run() {
                               setListAdapter();
                           }
                       });
                   }
               }
           }, filter);
       }
   }
  
   private void setListAdapter() {
       ArrayAdapter<String> adapter = new ArrayAdapter<String>
           (this, R.layout.chat_layout, messages); 
       list.setAdapter(adapter);
   }
  
}





code for settings give password and ussername
package com.example.multimedia;
import java.util.ArrayList;

import com.example.multimedia.R; 
import android.app.Dialog;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;


public class xmppsettings extends Dialog implements android.view.View.onclickListener  {
    private ChatActivity chatClient; 
    Spinner service;
    TextView username;
    TextView password;
    Button set;
  //  private String[] srv =new String [] {"facebook", "msn", "gmail"}; 
    String host,servs;
	int port;
    
    public xmppsettings(ChatActivity chatClient){ 
        super(chatClient);
        this.chatClient = chatClient; 
    }
   
    protected void onstart() {
        super.onstart();
        getWindow().setFlags(4,4);
        setContentView(R.layout.xmppsettings); 
        setTitle("Connection Settings");
        Button ok = (Button) findViewById(R.id.ok);
        ok.setonclickListener(this);
    }
   
    public void onclick(View v) {
    	
        String[] srv ={"facebook", "msn", "gmail"};
     	service = (Spinner)findViewById(R.id.service);
    	username = (TextView)findViewById(R.id.usname);
    	String usna = username.getText().toString();
    	password = (TextView)findViewById(R.id.pasword);
    	String pass = password.getText().toString();
    	set = (Button) findViewById(R.id.set); 
    	
    	
    	ArrayList<String> list = new ArrayList<String>();
     
        //create an ArrayAdaptar from the String Array
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(xmppsettings.this.getContext(), android.R.layout.simple_spinner_item, list);
        //set the view for the Drop down list
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        //set the ArrayAdapter to the spinner
        service.setAdapter(dataAdapter);
    
        set.setonclickListener(new View.onclickListener() {
            public void onclick(View v) {
                String o = (String) service.getSelectedItem ();
            
               if (o == "facebook") {
            	   host="chat.facebook.com";
            	   port=Integer.parseInt("5222");
            	   servs="chat.facebook.com";
            	  	}
               else if (o=="msn"){
            	   host="messenger.hotmail.com";
            	   port=Integer.parseInt("1863");
            	   servs="msn";
               							}
            			else if (o=="gmail"){
            				host="gtalk.google.com"; //smtp.gmail.com";
                     	   port=Integer.parseInt("465"); 
                     	  servs="gmail";
         											}
        						

            } } );   
    	
        ConnectionConfiguration connectionConfig =
            new ConnectionConfiguration(host, port, servs); 
        XMPPConnection connection = new XMPPConnection(connectionConfig);
       
        try {
            connection.connect();
            Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost());
        } catch (XMPPException ex) { 
        	Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + connection.getHost());
            chatClient.setConnection(null);
        }
        try {
            connection.login(usna, pass); 
            Log.i("XMPPClient", "Logged in as " + connection.getUser());
            // Set status to online / available
            Presence presence = new Presence(Presence.Type.available);
            connection.sendPacket(presence);
            chatClient.setConnection(connection);
        } catch (XMPPException ex) { 
        	Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username);
            chatClient.setConnection(null);
        }
        dismiss();
    }
   
   
    
    
    private String getText(int id) {
        EditText widget = (EditText) this.findViewById(id);
        return widget.getText().toString();
    }
}

Was This Post Helpful? 0
  • +
  • -

#36 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10385
  • View blog
  • Posts: 38,434
  • Joined: 27-December 08

Re: question about chat in android app

Posted 08 December 2012 - 02:59 PM

Do you get any Exceptions? If so, please post the stack traces.

Also, don't compare Strings using the == operator, as it compares their memory locations. Use the String equals() method instead to compare their literal values.
Was This Post Helpful? 0
  • +
  • -

#37 Vagosm  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 91
  • Joined: 15-May 12

Re: question about chat in android app

Posted 09 December 2012 - 04:18 AM

View Postmacosxnerd101, on 08 December 2012 - 02:59 PM, said:

Do you get any Exceptions? If so, please post the stack traces.

Also, don't compare Strings using the == operator, as it compares their memory locations. Use the String equals() method instead to compare their literal values.


i have not an exceptions .
I replaced == with equals() but again the app closed.
Posted Image
Was This Post Helpful? 0
  • +
  • -

#38 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10385
  • View blog
  • Posts: 38,434
  • Joined: 27-December 08

Re: question about chat in android app

Posted 16 December 2012 - 12:38 PM

What does your Logcat say?
Was This Post Helpful? 0
  • +
  • -

#39 Vagosm  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 91
  • Joined: 15-May 12

Re: question about chat in android app

Posted 17 December 2012 - 12:40 PM

View Postmacosxnerd101, on 16 December 2012 - 12:38 PM, said:

What does your Logcat say?

I copy the Logcat
12-17 21:36:17.360: W/KeyCharacterMap(324): No keyboard for id 0
12-17 21:36:17.360: W/KeyCharacterMap(324): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
12-17 21:36:20.670: E/WindowManager(324): Activity com.example.multimedia.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4a6d1920 that was originally added here
12-17 21:36:20.670: E/WindowManager(324): android.view.WindowLeaked: Activity com.example.multimedia.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4a6d1920 that was originally added here
12-17 21:36:20.670: E/WindowManager(324): at android.view.ViewRoot.<init>(ViewRoot.java:247)
12-17 21:36:20.670: E/WindowManager(324): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
12-17 21:36:20.670: E/WindowManager(324): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
12-17 21:36:20.670: E/WindowManager(324): at android.view.Window$LocalWindowManager.addView(window.java:424)
12-17 21:36:20.670: E/WindowManager(324): at android.app.Dialog.show(Dialog.java:241)
12-17 21:36:20.670: E/WindowManager(324): at com.example.multimedia.ChatActivity$1$1.run(ChatActivity.java:64)
12-17 21:36:20.670: E/WindowManager(324): at android.os.Handler.handleCallback(Handler.java:587)
12-17 21:36:20.670: E/WindowManager(324): at android.os.Handler.dispatchMessage(Handler.java:92)
12-17 21:36:20.670: E/WindowManager(324): at android.os.Looper.loop(Looper.java:123)
12-17 21:36:20.670: E/WindowManager(324): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-17 21:36:20.670: E/WindowManager(324): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 21:36:20.670: E/WindowManager(324): at java.lang.reflect.Method.invoke(Method.java:521)
12-17 21:36:20.670: E/WindowManager(324): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-17 21:36:20.670: E/WindowManager(324): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-17 21:36:20.670: E/WindowManager(324): at dalvik.system.NativeStart.main(Native Method)
12-17 21:36:20.900: D/dalvikvm(324): GC_FOR_MALLOC freed 6595 objects / 305160 bytes in 172ms
12-17 21:36:21.130: W/PhoneWindow(324): Previously focused view reported id 2131296259 during save, but can't be found during restore.
12-17 21:36:29.850: W/KeyCharacterMap(324): No keyboard for id 0
12-17 21:36:29.850: W/KeyCharacterMap(324): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
12-17 21:36:50.440: D/PhoneWindow(324): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@4a6a81e0 has no id.
12-17 21:36:50.450: E/WindowManager(324): Activity com.example.multimedia.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4a6ebbe8 that was originally added here
12-17 21:36:50.450: E/WindowManager(324): android.view.WindowLeaked: Activity com.example.multimedia.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4a6ebbe8 that was originally added here
12-17 21:36:50.450: E/WindowManager(324): at android.view.ViewRoot.<init>(ViewRoot.java:247)
12-17 21:36:50.450: E/WindowManager(324): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
12-17 21:36:50.450: E/WindowManager(324): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
12-17 21:36:50.450: E/WindowManager(324): at android.view.Window$LocalWindowManager.addView(window.java:424)
12-17 21:36:50.450: E/WindowManager(324): at android.app.Dialog.show(Dialog.java:241)
12-17 21:36:50.450: E/WindowManager(324): at com.example.multimedia.ChatActivity$1$1.run(ChatActivity.java:64)
12-17 21:36:50.450: E/WindowManager(324): at android.os.Handler.handleCallback(Handler.java:587)
12-17 21:36:50.450: E/WindowManager(324): at android.os.Handler.dispatchMessage(Handler.java:92)
12-17 21:36:50.450: E/WindowManager(324): at android.os.Looper.loop(Looper.java:123)
12-17 21:36:50.450: E/WindowManager(324): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-17 21:36:50.450: E/WindowManager(324): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 21:36:50.450: E/WindowManager(324): at java.lang.reflect.Method.invoke(Method.java:521)
12-17 21:36:50.450: E/WindowManager(324): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-17 21:36:50.450: E/WindowManager(324): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-17 21:36:50.450: E/WindowManager(324): at dalvik.system.NativeStart.main(Native Method)
12-17 21:36:50.670: D/dalvikvm(324): GC_EXTERNAL_ALLOC freed 3062 objects / 155216 bytes in 154ms
12-17 21:36:51.170: D/PhoneWindow(324): couldn't save which view has focus because the focused view android.widget.ScrollView@4a6e1948 has no id.
12-17 21:36:51.170: D/PhoneWindow(324): couldn't save which view has focus because the focused view android.widget.ScrollView@4a6e1948 has no id.
12-17 21:36:56.981: W/KeyCharacterMap(324): No keyboard for id 0
12-17 21:36:56.981: W/KeyCharacterMap(324): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
12-17 21:37:46.180: D/AndroidRuntime(324): Shutting down VM
12-17 21:37:46.180: W/dalvikvm(324): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-17 21:37:46.200: E/AndroidRuntime(324): FATAL EXCEPTION: main
12-17 21:37:46.200: E/AndroidRuntime(324): java.lang.ClassCastException: android.widget.ScrollView
12-17 21:37:46.200: E/AndroidRuntime(324): at com.example.multimedia.xmppsettings.onclick(xmppsettings.java:56)
12-17 21:37:46.200: E/AndroidRuntime(324): at android.view.View.performClick(View.java:2408)
12-17 21:37:46.200: E/AndroidRuntime(324): at android.view.View$PerformClick.run(View.java:8816)
12-17 21:37:46.200: E/AndroidRuntime(324): at android.os.Handler.handleCallback(Handler.java:587)
12-17 21:37:46.200: E/AndroidRuntime(324): at android.os.Handler.dispatchMessage(Handler.java:92)
12-17 21:37:46.200: E/AndroidRuntime(324): at android.os.Looper.loop(Looper.java:123)
12-17 21:37:46.200: E/AndroidRuntime(324): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-17 21:37:46.200: E/AndroidRuntime(324): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 21:37:46.200: E/AndroidRuntime(324): at java.lang.reflect.Method.invoke(Method.java:521)
12-17 21:37:46.200: E/AndroidRuntime(324): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-17 21:37:46.200: E/AndroidRuntime(324): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-17 21:37:46.200: E/AndroidRuntime(324): at dalvik.system.NativeStart.main(Native Method)
12-17 21:37:49.311: I/Process(324): Sending signal. PID: 324 SIG: 9
Was This Post Helpful? 0
  • +
  • -

#40 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: question about chat in android app

Posted 17 December 2012 - 01:36 PM

Something tells me, that you are using the Handler.post(new Runnable()) where you don't need it.
Handler.post should only be used when accessing something on the UI-thread, from a background-thread.
Was This Post Helpful? 0
  • +
  • -

#41 Vagosm  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 91
  • Joined: 15-May 12

Re: question about chat in android app

Posted 25 December 2012 - 10:40 AM

I if anyone can help me please because in day i have to upload it in e-class to see the professor and and to graduate me.
Was This Post Helpful? 0
  • +
  • -

#42 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: question about chat in android app

Posted 25 December 2012 - 08:11 PM

Try no to use Handler.Post to show the window.
You only need Handler.Post when you want to change the UI-thread from a background-thread.
But it the onclick where you are showing the Setting-window, you're already on the UI-thread and therefore do not need to call Handler.Post
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3