Problems using Gtalk

Put your problem here if it does not fit any of the other categories.

Problems using Gtalk

Postby xayide » Mon Mar 03, 2008 11:45 am

Hello!

I´ve been using the code provided by the emulator to use Gtalk service. It has two files: GtalkDataMessageSender and GTalkDataMessageReceiver.

I have changed both of them to get a chat-looking interface. What i want is to write the message and show it in the screen, and when other user sends a message to me, i want this message to be shown in the screen as well.

The problem is that no message is ever shown to me. I have debugged many times and no error seems to be. I put here the code , maybe someone sees what i am doing wrong:

Send the text message:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ...
  3.  
  4. } else if (view == mSend) {
  5.  
  6.         // use XmppService to send data message to someone
  7.  
  8.      
  9.  
  10.      themessage=mSendText.getText().toString();
  11.  
  12.      
  13.  
  14.         String username = mRecipient.getText().toString();
  15.  
  16.         if (!isValidUsername(username)) {
  17.  
  18.            showMessage(getText(R.string.invalid_username));              
  19.  
  20.             return;
  21.  
  22.         }
  23.  
  24.  
  25.  
  26.         if (mGTalkSession == null) {
  27.  
  28.           showMessage(getText(R.string.gtalk_service_not_connected));
  29.  
  30.              return;
  31.  
  32.         }
  33.  
  34.  
  35.  
  36.         try {
  37.  
  38.          mGTalkSession.sendDataMessage(username, getIntentToSend());
  39.  
  40.            
  41.  
  42.         } catch (DeadObjectException ex) {
  43.  
  44.             Log.e(LOG_TAG, "caught " + ex);
  45.  
  46.             showMessage(getText(R.string.found_stale_gtalk_service));
  47.  
  48.             mGTalkSession = null;
  49.  
  50.             bindGTalkService();
  51.  
  52.  
  53.  
  54.         }
  55.  
  56.     }
  57.  
  58. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


to view in the screen

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Cursor cursor = managedQuery(Im.Messages.CONTENT_URI, null,
  2.  
  3.   null, null, null);
  4.  
  5.  
  6.  
  7.   // Display the cursor results in a simple list
  8.  
  9.   // Note that the adapter is dyamic (picks up new entries automatically)
  10.  
  11.  
  12.  
  13.   SimpleCursorAdapter adapter =
  14.  
  15.             new SimpleCursorAdapter(this, R.layout.textview1, cursor, new String[]{Im.MessagesColumns.BODY}, new int[]{R.id.text1});
  16.  
  17.  
  18.  
  19.   setListAdapter(adapter);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


and the xml file:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.              android:orientation="vertical"
  7.  
  8.              android:layout_width="fill_parent"
  9.  
  10.              android:layout_height="fill_parent"
  11.  
  12.        >
  13.  
  14.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  15.  
  16.                  android:orientation="horizontal"
  17.  
  18.                  android:layout_width="fill_parent"
  19.  
  20.                  android:layout_height="wrap_content"
  21.  
  22.            >
  23.  
  24.         <EditText android:id="@+id/recipient"
  25.  
  26.                  android:layout_width="wrap_content"
  27.  
  28.                  android:layout_height="wrap_content"
  29.  
  30.                  android:singleLine="true"
  31.  
  32.                  android:textSize="16sp"
  33.  
  34.                  android:minWidth="250dp"
  35.  
  36.                  android:autoText="false"
  37.  
  38.                  android:capitalize="none"
  39.  
  40.                  android:scrollHorizontally="true"/>
  41.  
  42.         <Button android:id="@+id/setup"
  43.  
  44.                android:layout_width="wrap_content"
  45.  
  46.                android:layout_height="wrap_content"
  47.  
  48.                android:text="Setup">
  49.  
  50.             <requestFocus/>
  51.  
  52.         </Button>
  53.  
  54.     </LinearLayout>
  55.  
  56.  
  57.  
  58.     <ListView android:id="@id/android:list"
  59.  
  60.              android:layout_width="fill_parent"
  61.  
  62.              android:layout_height="fill_parent"
  63.  
  64.              android:layout_weight="1"
  65.  
  66.              android:drawSelectorOnTop="false"/>
  67.  
  68.  
  69.  
  70.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  71.  
  72.                  android:orientation="horizontal"
  73.  
  74.                  android:layout_width="fill_parent"
  75.  
  76.                  android:layout_height="wrap_content"
  77.  
  78.            >
  79.  
  80.         <EditText android:id="@+id/sendText"
  81.  
  82.                  android:layout_width="wrap_content"
  83.  
  84.                  android:layout_height="wrap_content"
  85.  
  86.                  android:singleLine="true"
  87.  
  88.                  android:textSize="16sp"
  89.  
  90.                  android:minWidth="250dp"
  91.  
  92.                  android:autoText="false"
  93.  
  94.                  android:capitalize="none"
  95.  
  96.                  android:scrollHorizontally="true"/>
  97.  
  98.         <Button android:id="@+id/send"
  99.  
  100.                android:layout_width="wrap_content"
  101.  
  102.                android:layout_height="wrap_content"
  103.  
  104.                android:text="Send">
  105.  
  106.             <requestFocus/>
  107.  
  108.         </Button>
  109.  
  110.     </LinearLayout>
  111.  
  112. </LinearLayout>
Parsed in 0.008 seconds, using GeSHi 1.0.8.4



Thanks!!
xayide
Junior Developer
Junior Developer
 
Posts: 20
Joined: Tue Feb 05, 2008 1:23 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 13 guests