I want to get an int with the number of unread emails in the accounts of the device.
I have seen that there is a new way to do this using the "Gmail Labels Public API"
http://android-developers.blogspot.in/2012/04/gmail-public-labels-api.html
I have read the documentation and downloaded the sample application and it really works.
But I have two problems: (
My intention is to get an int with the number of unread conversations, i try this:
String unread = GmailContract.Labels.NUM_UNREAD_CONVERSATIONS.toString();
but not works, always returns "numUnreadConversations"
How I can get an int to this value?
My second problem is this: The code works correctly with the default count of my device, but I want to get the value with all unread conversations of all device gmail accounts
eally appreciate any help
thanks and regards
With GmailContract.Labels.NUM_UNREAD_CONVERSATIONS.toString(); you're just converting the enum to string.
You need a Cursor object to iterate through labels and then acquire the number with cursor.getInt(GmailContract.Labels.NUM_UNREAD_CONVERSATIONS)
Check this code for iterating through accounts and labels.
Related
I'm working with an Android App that functions as an instant messaging service, and I'm at the point of pulling the message data through into a RecyclerView. I have my Firebase Query object returning all the messages that match the id of the chat that has been loaded, this is done like so:
Query qChatMessages = mDbRefMessages
.orderByChild("messageChat")
.equalTo(mChatId);
So far so good, and this is returning the collection of messages that I expect. The problem is now that, upon passing them to the RecyclerView to be displayed, they come out in the inverse order of how you would typically expect an instant messenger to display, so the messages are actually getting older as you scroll down the chat.
My message nodes in the database all have a messageTimestamp field associated with them, so this is what I would want to sort the data by. The problem is that I don't seem to be able to find a way of ordering the data by any field other than the one that I'm querying on, or getting the results back from Firebase and subsequently ordering them.
Does anyone know how I can work around this, or if there's some Firebase capabilities I'm not aware of?
Thanks in advance,
Mark
The easiest way is to store an extra piece of data in your message nodes which is the epoch time multiplied by -1: this way you can sort on this field and the query will return the right order.
See this post on how to get the epoch time: how to get the number of seconds passed since 1970 for a date value?
However, note that with your current data structure, you will encounter a problem: you will need to sort on this new data (e.g. with .orderByChild("messageCreationTime")) AND filter for a given mChatId (e.g. with equalTo(mChatId)), which is not possible.
So, you would have to re-structure your database (if this is possible) like this:
- messages
- mChatId
- messageUniqueID <- most probably auto-generated by Firebase
- messageTitle: ....
- messageCreationTime: -1525857044
And you would query by:
Query qChatMessages = databaseReference.child("messages").child(mChatId)
.orderByChild("messageCreationTime");
I'm developing sms APP and want to receive sms from the specific numbers. But number can be changed sometime with country code as +923201234567 or sometime without country code 03201234567 how I can compare number from database? because don't know in which format number is saved in database(with country code or without country code)
public boolean isMember(String phone, long id){
String query = "SELECT * from members where phone = ? AND active = 1 AND gid = ?";
Cursor c = dbActions.rawQuery(query, new String[]{String.valueOf(phone), String.valueOf(id)});
return c.moveToFirst();
}
Suppose if the number is saved in database without country code 03201234567 then my requirement is to get true if I compare it with country code. +923201234567. Country code could be changed.
PhoneNumberUtils.compare(); is not useful because it not compare with database.
If you can't acquire the correct information always; then you need to look into heuristics.
Meaning: you could write your own comparisons; and when you encounter two numbers like:
03201234567
+923201234567
you can figure: their "tail" is equal; the only difference is that the first one starts with 0 (so no country code) and the second one with +92. So it might be reasonable to declare those two numbers to be equal.
So a "solution" would do things like "normalize" your input (remove all non-digit content; except for leading + signs); and to then make such "tail-bound" comparisons.
If that is "too" fuzzy; I guess then you should step back and describe the requirement that you actually try to resolve here. Why are you comparing numbers; and what do you intend to do with the output of that comparison?!
Normalize all of the phone numbers into the same format before you put them into the database. That way you can just do a normal db search.
The other thing I've done for phone numbers is to convert all letters into the appropriate number, then remove all non digits, then just compare the last 7 digits.
Using SL4A and Python, is there an easy way to get a Contact ID from a phone number?
The phone number is from the 'address' field of an SMS.
I am trying to avoid searching through all contacts.
I use m = droid.smsGetMessageById(id, None).result to get the SMS message. The result looks like:
{u'read': u'1', u'body': u"Hello! Your mobile bill's now ready to view at virginmobile.co.uk/youraccount. We'll collect your Direct Debit of 12.12 on or just after 19th Nov.", u'_id': u'1323', u'date': u'1415372649502', u'address': u'1234567890'}
The value in the address entry is the phone number that sent the SMS.
I want to get a contact ID using this number, but, if possible, I want to avoid searching all my contacts.
I figured it out:
def contactFromPhone(phone):
uri='content://com.android.contacts/data'
filter='data4 LIKE ?'
args=['%'+phone+'%']
columns=['contact_id']
contacts=droid.queryContent(uri, columns, filter, args).result
cs=[]
if len(contacts)>0:
for c in contacts:
cs.append(c['contact_id'])
return cs
'phone' is a normalized phone number
returns a list of contact_id
In an Android app I've got a couple contacts from my contacts list. They can be either emails, phone numbers, or even other things. I now want to check which type it is and bind specific actions to them.
For example, if it is a type vnd.android.cursor.item/email_v2, I want to send a POST message with just the email field, and if it is a type vnd.android.cursor.item/phone_v2 I want to send a POST message with just the phone field.
Any ideas how I could check this?
I guess the way to go would be using overloading:
You implement multiple methods with different input parameters but the same name, such as:
checkContact(email_v2 email){ do things with email }
checkContact(phone_v2 phone){ do things with phone }
checkContact(String s){do things with random string }
I think you get my point.
If you want a simple if-statement, though:
if (contact instanceof vnd.android.cursor.item/email_v2){ do send }
You could try checking the class constant CONTENT_ITEM_TYPE for your different types, something like:
contact.CONTENT_ITEM_TYPE.equals("vnd.android.cursor.item/email_v2");
Some of my users report that on their Samsung devices (GT-N7000 & SGH-I777) a query I make in my app for the CallLog.Calls displays also text messages.
I've created a dump of their CallLog ContentProvider, and it seems to have extra fields not mentioned in the Android API, and not returned on any of our test devices.
Specifically, looking through the dump, there's a field called logtype, which seems to equal 100 for calls, and 300 for text messages.
Having searching online for this field, I didn't find any official documentation for this field's values, but I came across lots of other possible values for this field mainly via crash stack traces, which reveal underlining queries by the ContentProvider:
logtype=300 OR logtype=200
logtype=100 OR logtype=500 OR logtype=800 OR logtype=900 OR
logtype=1000
So I assume that 300/200 are used for text messages, and 100/500/800/900/1000 are used for calls, but I'm not sure, since I haven't seen 500/800/900/1000 being used on the reporting users' devices.
Can someone shed some light for the possible values of logtype, and their meaning?
Hello If you will check callLog.Calls columns you will find messageid field which says that this is message for samsung phones.
So if you just want to get the list of calls without messages simply do :
int messageIdIndex=cursor.getColumnIndex("messageid");
while (cursor.moveToNext())
{
if(messageIdIndex>=0)
messageID=cursor.getLong(messageIdIndex);
if(messageID<=0)
{
//do whatever you need with calls log data
}
}
cursor.close();
I've managed to tentatively solve it by querying CallLog.Calls for the column logtype, if an exception is thrown, I query normally, otherwise, I query with selection of (logtype=100 OR logtype=500)
This seems to be working for my reporting users, but I'm still not sure if it covers all bases, since there are many possible values for logtype for which I don't know the meaning.
If anyone has a better answer, please add it.
When i was debugging a sgs2 device i have found this. may be useful for someone.
SELECT number, name, type, date, duration FROM logs WHERE (
logs.logtype=100 OR
logs.logtype=110 OR
logs.logtype=900 OR
logs.logtype=500 OR
logs.logtype=800 OR
logs.logtype=120 OR
logs.logtype=510 OR
logs.logtype=1000 OR
(logs.logtype=200 AND number NOT IN (SELECT number FROM logs WHERE number LIKE '%#%')) OR logs.logtype=300)
AND ((type != 4)) AND (logtype=100 OR logtype=500)))
ORDER BY date DESC
So far, we have found Samsung devices using the value 1150, 100 or 1000 for the 'logtype' field in the Calls content provider.
I cannot confirm if any of the other values mentioned here are used.