GTalk

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

GTalk

Postby Vladimir » Fri Mar 21, 2008 1:41 pm

Hi!

I'd like to write an application which is able to send messages to the server (with the help of gtalk) and to receive them from server (via gtalk again).

I failed to make GTalkDataMessageSender (this is one of the demos provided) work. Each time I start it
message "the default Gtalk session cannot be found" appears.

Any ideas?
Vladimir
Freshman
Freshman
 
Posts: 3
Joined: Fri Mar 21, 2008 1:12 pm

Top

Postby Poffy » Fri Mar 21, 2008 7:40 pm

Have you set up XMPP settings?

Go to Dev Tools (in the emulator) then scroll to XMPP settings and enter a gmail account.
Poffy
Freshman
Freshman
 
Posts: 3
Joined: Tue Mar 18, 2008 10:29 pm

GTalk: handset to server

Postby Vladimir » Sat Mar 22, 2008 10:03 am

Thanks, it works now.

Is it possible to initiate data exchange between a server and an Android application via GTalk?

First, I'd like be able to send a message from Android app. to GTalk desktop client, but I cannot guess how to do it. For example, there is a method IGTalkSession.sendDataMessage(String to, Intent broadcastIntent) which should be used to send a message from one device to other (like in GTalkDataMessageSender, GTalkDataMessageReceiver demos).

How can it be used to send a message to the server? or may be there is another way to do it?
Vladimir
Freshman
Freshman
 
Posts: 3
Joined: Fri Mar 21, 2008 1:12 pm

Postby inter » Tue Apr 08, 2008 6:55 pm

Hii

I went to the Dev Toolv.Add account in XMPP Settings .But not successed .The error message: wrong pass and username . But when i used that username and password sign in Google Talk .That work
inter
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 21, 2008 10:13 am

about gtalk

Postby swapsnil » Tue Apr 15, 2008 12:03 pm

Hi all,

I am using tatasu's code for creating a gtalk service(chat client).
Here two classes are used one is messaging.java and other is simpletalk.java.

In the methods of messaging.java we have many methods overridden.
But this methods are not overridded in the code i am getting.

The messaging.java is as below....can you plz tell me how can this be done....i have tried the overridding phenomenon(as how a method is overrided), but i am still facing the problem..

The lines creating problems are made red....

package com.tatsu.android.simpletalk;

import android.app.ListActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.Resources;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.IBinder;
import android.provider.Im;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import com.google.android.gtalkservice.GTalkServiceConstants;
import com.google.android.gtalkservice.IChatSession;
import com.google.android.gtalkservice.IGTalkService;
import com.google.android.gtalkservice.IGTalkSession;

public class Messaging extends ListActivity implements ServiceConnection {
private IGTalkSession mIGTalkSession;
private String mAccountName;
private String mContactName;

@Override
protected void onCreate(Bundle icicle) {
final String[] from = new String[] { Im.Messages.TYPE, Im.Messages.BODY };
final int[] to = new int[] { R.id.message_from, R.id.message_body };

super.onCreate(icicle);
setContentView(R.layout.messaging);

bindService(new Intent().setComponent(GTalkServiceConstants.GTALK_SERVICE_COMPONENT), this, 0);

Resources res = getResources();
Bundle extras = getIntent().getExtras();
mAccountName = extras.getString(res.getString(R.string.name_account).toString());
mContactName = extras.getString(res.getString(R.string.name_contact).toString());

setListAdapter(new SimpleCursorAdapter(this, R.layout.message_line, managedQuery(Im.Messages.CONTENT_URI, null,
Im.Messages.CONTACT + "='" + mContactName + "'", Im.Messages.DATE + " ASC"), from, to) {
@Override
public void setViewText(TextView v, String text) {
super.setViewText(v, convText(v, text));
}
});

EditText inputMessage = (EditText) findViewById(R.id.input_message);
inputMessage.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) { switch (event.getAction()) { case KeyEvent.ACTION_UP:
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_NEWLINE:
sendMessage(mContactName, ((EditText) v).getText().toString());
((EditText) v).setText("");
return true;
default:
break;
}
break;
default:
break;
}
return false;
}
});
}

@Override
protected void onDestroy() {
unbindService(this);
super.onDestroy();
}

@Override
public void onContentChanged() {
super.onContentChanged();
int count = getListView().getCount();
if (count > 0) {
getListView().setSelection(count - 1);
}
}

@Override
public void onServiceConnected(ComponentName name, IBinder service) { try {

mIGTalkSession = IGTalkService.Stub.asInterface(service).getDefaultSession();
} catch (DeadObjectException e) {
mIGTalkSession = null;
}
}

@Override
public void onServiceDisconnected(ComponentName name) { mIGTalkSession = null;
}

private String convText(TextView v, String text) {
switch (v.getId()) {
case R.id.message_from:
return Integer.valueOf(text).equals(Im.MessageType.INCOMING) ? mContactName : mAccountName;
}
return text;
}

private void sendMessage(String message_to, String message_body) {
IChatSession chatSession;

if (mIGTalkSession != null) {
try {
chatSession = mIGTalkSession.createChatSession(message_to);
chatSession.sendTextMessage(message_body);
} catch (DeadObjectException e) {
;
}
}
}
}
swapsnil
Freshman
Freshman
 
Posts: 3
Joined: Mon Mar 17, 2008 7:41 am

Postby com2usprav » Fri Apr 25, 2008 1:59 pm

Hi swapsnil
Even i Faced the similar problem while using tatsu code

Instead of copying the complete project of tatsus code in the work space and importing the project

Create a New Project in the name of Simple Talk and copy the source and resourse in the newly created projecte by you...

u can over come the problem now

and i am unable to solve one problem in the Gtalk of u overcome it send me a reply

I am unable to get the result for the below query


managedQuery(Im.Messages.CONTENT_URI, null,
Im.Messages.CONTACT + "='" + mContactName + "'", Im.Messages.DATE + " ASC"), from, to)


Regards
Pravin
User avatar
com2usprav
Developer
Developer
 
Posts: 26
Joined: Sat Mar 29, 2008 3:28 pm
Location: Bangalore

Top

Postby com2usprav » Mon Apr 28, 2008 9:36 am

Any one Can Post a Good Tutorial on GTALK Smaples . It will Be Very Helpful .

Cheers
Pravin Kumar
User avatar
com2usprav
Developer
Developer
 
Posts: 26
Joined: Sat Mar 29, 2008 3:28 pm
Location: Bangalore

Postby com2usprav » Mon Apr 28, 2008 9:37 am

Any one Can Post a Good Tutorial on GTALK Smaples . It will Be Very Helpful .

Cheers
Pravin Kumar
User avatar
com2usprav
Developer
Developer
 
Posts: 26
Joined: Sat Mar 29, 2008 3:28 pm
Location: Bangalore

Was finally able to resolve my numeric rounding issues!!

Postby skatalicious » Wed Aug 05, 2009 11:00 pm

swapsnil,

Thanks for your post. Your code,
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setListAdapter(new SimpleCursorAdapter(this, R.layout.message_line, managedQuery(Im.Messages.CONTENT_URI, null,
  2.  
  3. Im.Messages.CONTACT + "=\'" + mContactName + "\'", Im.Messages.DATE + " ASC"), from, to) {
  4.  
  5. @Override
  6.  
  7. public void setViewText(TextView v, String text) {
  8.  
  9. super.setViewText(v, convText(v, text));
  10.  
  11. }
  12.  
  13. });
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


and
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private String convText(TextView v, String text) {
  2.  
  3. switch (v.getId()) {
  4.  
  5. case R.id.message_from:
  6.  
  7. return Integer.valueOf(text).equals(Im.MessageType.INCOMING) ? mContactName : mAccountName;
  8.  
  9. }
  10.  
  11. return text;
  12.  
  13. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


was the answer I have been looking for in trying to resolve the rounding and display issues with displaying my numerical values in my list.

This is what I did...
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. public class testListView extends ListActivity {
  5.  
  6.   ...
  7.  
  8.   private DecimalFormat myCustDecFormatter = new DecimalFormat("########.00");
  9.  
  10.   ...
  11.  
  12.   ...
  13.  
  14.   /** Called when the activity is first created. */
  15.  
  16.   @Override
  17.  
  18.   public void onCreate(Bundle savedInstanceState)  {
  19.  
  20.     ...
  21.  
  22.     ...
  23.  
  24.     ...
  25.  
  26.   }
  27.  
  28.  
  29.  
  30. private void fillData() {
  31.  
  32.     /* Get all of the rows from the database and create the item list */
  33.  
  34.     /* for mult accts, pass in acct name? */
  35.  
  36.     mEntryCursor = mDbHelper.fetchAllEntries();
  37.  
  38.     startManagingCursor(mEntryCursor);
  39.  
  40.    
  41.  
  42.     // Create an array to specify the fields we want to display in the list (only TITLE)
  43.  
  44.     String[] from = new String[]{myDbAdapter.KEY_NMBR,myDbAdapter.KEY_DATE,myDbAdapter.KEY_DESCR,myDbAdapter.KEY_AMT};
  45.  
  46.    
  47.  
  48.     // and an array of the fields we want to bind those fields to (in this case just text1)
  49.  
  50.     int[] to = new int[]{R.id.txtnmbr, R.id.txtdate, R.id.txtdescr, R.id.txtamt};
  51.  
  52.    
  53.  
  54.     // Now create a simple cursor adapter and set it to display
  55.  
  56.     setListAdapter(new SimpleCursorAdapter(this, R.layout.entryrow, mEntryCursor, from, to) {
  57.  
  58.         @Override
  59.  
  60.         public void setViewText(TextView v, String text) {
  61.  
  62.           super.setViewText(v, convText(v, text));
  63.  
  64.         }
  65.  
  66.        
  67.  
  68.     });
  69.  
  70.      
  71.  
  72.   }
  73.  
  74.  
  75.  
  76.   private String convText(TextView v, String text) {
  77.  
  78.     switch (v.getId()) {
  79.  
  80.       case R.id.txtamt:
  81.  
  82.         double dblAmt;
  83.  
  84.         //dblAmt = Double.valueOf(text);
  85.  
  86.         dblAmt = mEntryCursor.getDouble(AMT_COLUMN);
  87.  
  88.         return myCustDecFormatter.format(dblAmt);
  89.  
  90.     }
  91.  
  92.       return text;
  93.  
  94.     }
  95.  
  96. ...
  97.  
  98. ...
  99.  
  100. ...
  101.  
  102. }//end testListView
Parsed in 0.040 seconds, using GeSHi 1.0.8.4
skatalicious
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Aug 05, 2009 10:54 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests