List of all online gtalk contacts - Android Software Development

I'd like to get a list of the email addresses associated with all the online gtalk contacts. I'm using it to generate a pick list to launch a gtalk chat session with that person from my app.
Code:
private Cursor getGtalkEmails()
{
ContentResolver cr = getContentResolver();
Uri uri = ContactsContract.Data.CONTENT_URI;
String[] projection = new String[] { ContactsContract.Data._ID,
ContactsContract.Data.CONTACT_PRESENCE,
ContactsContract.Data.DISPLAY_NAME,
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Im.PROTOCOL,
ContactsContract.CommonDataKinds.Im.DATA };
String selection = ContactsContract.Data.CONTACT_PRESENCE+"!='0' and " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Data.DISPLAY_NAME
+ " COLLATE LOCALIZED ASC";
return cr.query(uri, projection, selection, selectionArgs, sortOrder);
Unfortunately, this only returns a single contact... And I have 50 people online right now.
So I dumped the entire table and it looks like out of every contact on my phone, only one has a vnd.android.cursor.item/im entry.
So is there an alternative query I could use to filter these out? I can't just use email, because a lot of my contacts have more than one email. If they do, it could pick the wrong one and when I fire the intent to launch a gtalk session it would open up the "add contact" dialog instead of the chat activity.
Thoughts?

Related

sdk help

Hello, I am writting a small app to replace my HTC Touch Today plugin because it is too damn big. My apps is almost done except for launching the different apps in certain case, and that is where I need help:
1- Starting cprog.exe in Call History mode
2- Going to the email
3- Going to the sms list
Thank you for your help
Ok got #3:
PROCESS_INFORMATION pi = {0};
DWORD dwRes = 0;
BOOL bret=CreateProcess(_T("\\Windows\\tmail.exe"), _T("-service \"SMS\""), NULL, NULL, NULL, 0, NULL, NULL, NULL, &pi);
Found #2, but how do you get the default Mail Account, or list them?
\Windows\tmail.exe -service "Name of email account"

Broadcast Receiver pass Data to MainActivity

Hi everyone,
I'm working on a small app. I'm launching the MainActivity and there's some Code. And after some specific Code, I've to wait for an incoming SMS and do other stuff in the MainActivity. But How are the Data's from the Incoming SMS passed to the Main Activity?
I've this BroadCast Receiver:
Code:
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
//---just a trial with app Context
// Starting appState = ((Starting)context);
// appState.setState("Receiver Datas");
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
//appState.setState(str);
//---display the new SMS message---
}
}
My Solution with the Application Context doesn't work...Any Ideas or Suggestions?
Thanks a lot in advance
Can you just launch it and pass it the data you need in the intent extras?
Code:
Intent it=new Intent();
it.setClassName("com.path","com.path.YourAppActivity");
it.putExtra("something","value1");
it.putExtra("something_else","value2");
startActivity(it);
So this can't work, because the Activity is already running...
So the Activity is running and is doing some stuff and then it has to wait until an SMS is received...and then continue...but it has to be in the same Activity.
Like you mentioned it I would start a new Activity...
I'm not entirely sure what it is that you're doing, but you may have to spawn this off as a service, then let the service handle SMS stuff and call back to its parent activity when something needs to be signaled. In this case, you'd need to implement some kind of callback Interface to handle events from the service.

[Q] adding event to android calendar without showing the calendar

i have this code for adding event:
Code:
Intent calendarIntent = new Intent(Intent.ACTION_INSERT, Events.CONTENT_URI);
Calendar beginTime = Calendar.getInstance();
beginTime.set(2013,04,14,21,00,00);
Calendar endTime = Calendar.getInstance();
endTime.set(2013,04,14,21,10,00);
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("title", "Some title");
intent.putExtra("description", "Some description");
intent.putExtra("beginTime", beginTime.getTimeInMillis());
intent.putExtra("endTime", endTime.getTimeInMillis());
startActivity(intent);
but how to insert event without open the calendar ?
thanks
You'll need to use the CalendarContract API, and add a certain permission. This is only possible in 4.0 and up, however.
thank
thanks for the help,
can i get any sample code that works ?
i try some - but no one works for me
Regards,

Consultation about add event to calendar

i have this code for adding event to calendar
long calID = 3;
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2013, 3, 23, 7, 30);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2013, 3, 24, 8, 45);
endMillis = endTime.getTimeInMillis();
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DTEND, endMillis);
values.put(Events.TITLE, "My Test");
values.put(Events.DESCRIPTION, "My Calendar Test");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "Israel/tel-aviv");
Uri uri = cr.insert(Events.CONTENT_URI, values);
i need to change this line: long calID = 3;
with any default calendar id
how to get list of all calendar Accounts and fit him to id ?

[Q] Implementing Android REST client and synchronization

Good afternoon. There is a task to develop a client for android news site. For notification of new posts to be used gcm.
Estimated algorithm:
1. Run the application, the database is empty, make a request to the api get the last 20 records, id 1000 to 980, write to the database.
3. Listview is scrolled to the last record, make a request for records whose id is less than 980, we record from 979 to 959 write to the database.
3. Comes gcm message or clicked update, make a request to the api, get the records whose id> 1000, we record with id 1001 to 1021 write to the database.
The question arises - how to behave in a situation where we assume the device was offline for a week, during which added another 1000 records.
The device connects to the network, gets send-to-sync message, makes a request to the api to get records whose id> 1021, in response to the 1000 records to come.
Intuition suggests that load all 1000 records are not correct, you need to download and say the last 20, but then it turns out that the database will be news for today, last week they will not, and then go for the news before last week
And question number 2 - how to clean old records, to avoid infinite growth of the DB?
What about this: make another table that have only 20 records and when a news comes, it stores it on the first record and deletes last record. Of course records 2-19 iterate.
When you get news on device, get them from this table. If you want to get older news, get the last id from this table and get next 20 news from table that stores all of the records.
---------- Post added at 10:29 AM ---------- Previous post was at 10:20 AM ----------
Answering question 2:
The best solution for me is to make model class News . It makes everything easier with DB. If you have this, you can do something like this:
public void deleteAllNews(){
String selectQuery = "SELECT * FROM " + TABLE_NEWS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(selectQuery, null);
// looping through all rows
if (c.moveToFirst()) {
do {
db.delete(TABLE_NEWS, KEY_ID + " = ?", new String[] { String.valueOf(c.getInt(c.getColumnIndex(KEY_ID)) });
} while (c.moveToNext());
}
db.close();
c.close();
}

Categories

Resources