Get the unread mail count gmail - android

Gmail.java link as referred to in one of the questions on SO is broken.
My code is
String account="abc.xyz#gmail.com";
Uri LABELS_URI = Uri.parse("content://gmail-ls/unread/");
Log.d("pavan","label "+LABELS_URI );
Uri ACCOUNT_URI = Uri.withAppendedPath(LABELS_URI, account);
Log.d("pavan","label "+ACCOUNT_URI );
ContentResolver contentResolver= this.getContentResolver();
Log.d("pavan","contentResolver "+contentResolver );
Cursor cursor = contentResolver.query(ACCOUNT_URI, null, null, null, null);
but the contentResolver line is throwing an error, the logcat says:
cannot find provider info for gmail-ls.
Any ideas how to solve this?

Use the Android Gmail API, if it meets your needs. Otherwise, the Gmail application no longer supports access such as what you are doing.

Related

Is it possible to read SMS in Android NOT for verification code?

I need to get a link from auto-sent-SMS, but this SMS is always from a different number, so it's not like Retriever API.
I wanted to know - is it even possible for Android 8-9 and higher to programmatically read SMS via app?
If you know some examples on how - appreciate if you'll share :)
*most of the topics here are outdated or related to Retriever API so I wanted to know for sure about the latest Android versions.
There are Telephony.Sms.Inbox and Telephony.Sms.Sent content providers to access incoming and outgoing sms data. I used this far far way ago, but now i got my old code, and it still working in api 29. Here is my sample code to get basic data from inbox table, it's full text, but better way is to access content_uri and columns via content provider classes. If you want to get more columns, check docs. Remember, you need to grant READ_SMS permission.
Uri inboxUri = Uri.parse("content://sms/inbox");
String[] projection = new String[] { "_id", "date", "date_sent", "address", "body" };
String sortOrder = "date";
String limit = " DESC";
Cursor cursor = mContext.getApplicationContext().getContentResolver().
query(inboxUri, projection, null, null, sortOrder + limit);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
//read sms data
} while (cursor.moveToNext());
}
cursor.close();
}

How can I access ContactsContract Profile?

I tried to read the complete profile information such a (Full name, phone, adresse, mail .... ).
I have searched everywhere for a good example code. I tried many ways (Uri => Cursor) to access the Profile.
At this time I can fetch just the Full name (of the Profile contact), nothing more.
I can fetch data of other contacts using an Intent, sending to the Contacts app, BUT I CAN'T READ THE PROFILE CONTACT (JUST FULL NAME).
I have added the READ_PROFILE permission in the manifest file.
With the following code I get the Full Name (I can also access first and last name separately ):
Uri uriProfile = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
Cursor cursorProfile = this.getContentResolver().query(uriProfile,
null, null, null, null);
String projection = Profile.DISPLAY_NAME;
String profileName = cursorProfile.getString(cursorProfile.getColumnIndex(projection);
But when I use this the following projection to get Phone Number, it returns an error and the app stops working:
String projection = ContactsContract.CommonDataKinds.Phone.NUMBER
I found a solution using this code:
Get an URI Profile
Crate a cursor pointing to the URI content with null projection. Because for the profile, data are saved differently than a normal contact.
Point the cursor to the wanted data using MIMETYPE.
Uri uriProfile = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
Cursor cursorProfile = getApplicationContext().getContentResolver().query(uriProfile,
null, null, null, null);
String cursorProfile_MIMIETYPE = cursorProfile.getString(cursorProfile.getColumnIndex("MIMETYPE"));

How to read draft message address , it always returns null value

I am implementing sms application, I want to store all sms values into internal xml file and restore sms values from xml file into sms application, so far inbox messages and sent messages working fine but problem with draft messages.
please help me on this , thank you.
// Create Draft box URI
Uri draftURI = Uri.parse("content://sms/draft");
// List required columns
String[] reqCols = new String[] { "_id", "address", "body" };
// Get Content Resolver object, which will deal with Content Provider
ContentResolver cr = getContentResolver();
// Fetch Sent SMS Message from Built-in Content Provider
Cursor c = cr.query(draftURI, reqCols, null, null, null);
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
tutorial link

Unable to access Android content provider

I can see in LogCat that ActivityManager is reporting something about a particular content provider. I use the following code to try to access that content provider in order to learn more about it:
Cursor cursor = context.getContentResolver().query(uriDSDS, null, null, null, null);
String[] columnNames = cursor.getColumnNames();
Log.d(TAG, "columnNames=" + columnNames.toString());
Unfortunately, after trying to get the cursor, I see the following error in LogCat:
Failed to find provider for __
What's the problem? Why can I not access this provider? Could it be that access is restricted to certain apps? Is there a way to go into ADB or something else to see all of the available content providers on the device?
make sure that you add correct Uri
for example
Uri uriDSDS = Uri.parse(
"content://aaa.aaa/values");
As in the working example below, do check if your uriDSDSis correct.
Cursor people = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null,
null);
// get contact id
while (people.moveToNext()) {
if (people != null) {
int numberFieldColumnIndex = people
.getColumnIndex(PhoneLookup._ID);
String number = people.getString(numberFieldColumnIndex);
contactId.add(number);
}
}
people.close();

Get list of mails from Gmail in Android

Have such kind of problem: I need to get list of mails form my gmail account. It`s shown in snippet below:
Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");
File file = new File("content://gmail-ls/messages/"+accounts[0].name+"/");
if(file.exists())
{
Uri uri = Uri.parse("content://gmail-ls/messages"+accounts[0].name+"/");
cursor = this.getContentResolver().query(uri, null, null, null, null);
}
But it doesn't enter in "if" condition as such path does not exist. With out "if" condition it throws with exception on moment when I assign a cursor by a query with Uri to gmail-ls.
Anyone knows how this problem can be solved? Will appreciate any advice!
Looks like it is not possible any more for third-party apps to read email from Gmail
ref http://productforums.google.com/forum/#!msg/gmail/XD0C4sw9K7U/LpNXxFNnfgc

Categories

Resources