How can I get contact name with his/her number
Asked Answered
L

4

20

I'm trying to develop a simple app using Android Scripting and Python.

Now, I have a phone number, and I want to find out which contact has that number. I can do a contactsGet() and search for numbers, but so many programs uses that feature that, I think there is an easier way for that.

There is a question with same problem, but Java, is there a Python equivalent? Search contact by phone number

Is there a simple way to achieve that?

Any example code is appreciated.

Edit, after a few days with no answer, I decided to change the question a little: What is the best way for search a number for a list which I got with contactsGet()?

Lille answered 15/5, 2011 at 16:56 Comment(0)
L
1

This is a common problem with layers of abstraction. The layer doesn't abstract a specific functionality, tool, or case you'd like to use. In this case, however, it appears that not all hope is lost. It appears that the android scripting api is an open-source project. Why not contribute a patch that would provide this ability to the project?

I may contribute such a patch at some point in the future, but if it's important to you, you could do the same before I do, and be on your way!

Largely answered 24/5, 2011 at 13:56 Comment(1)
That's the only answer which includes a possible solution to my problem :). It seems there is no other way. Thanks :).Lille
O
1
package com.slk.example.CursorActivity;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.Phones;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

public class CursorActivity extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Cursor contactsCursor = this.managedQuery(Phones.CONTENT_URI, null, null, null, null);
        this.setListAdapter(new MyContactsAdapter(this,contactsCursor));
    }

    private class MyContactsAdapter extends CursorAdapter{
        private Cursor mCursor;
        private Context mContext;
        private final LayoutInflater mInflater;

        public MyContactsAdapter(Context context, Cursor cursor) {
            super(context, cursor, true);
            mInflater = LayoutInflater.from(context);
            mContext = context;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            TextView t = (TextView) view.findViewById(R.id.txtName);
            t.setText(cursor.getString(cursor.getColumnIndex(Phones.NAME)));

            t = (TextView) view.findViewById(R.id.txtDisplayName);
            t.setText(cursor.getString(cursor.getColumnIndex(Phones.DISPLAY_NAME)));

            t = (TextView) view.findViewById(R.id.txtPhone);
            t.setText(cursor.getString(cursor.getColumnIndex(Phones.NUMBER)));
        }

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            final View view = mInflater.inflate(R.layout.main, parent, false);
            return view;
        }
    }
}
Opuntia answered 23/5, 2011 at 12:16 Comment(1)
The question is its Python equivalent.Lille
L
1

This is a common problem with layers of abstraction. The layer doesn't abstract a specific functionality, tool, or case you'd like to use. In this case, however, it appears that not all hope is lost. It appears that the android scripting api is an open-source project. Why not contribute a patch that would provide this ability to the project?

I may contribute such a patch at some point in the future, but if it's important to you, you could do the same before I do, and be on your way!

Largely answered 24/5, 2011 at 13:56 Comment(1)
That's the only answer which includes a possible solution to my problem :). It seems there is no other way. Thanks :).Lille
K
0

You might want to take a look at the ContactsContract data table. Query it with something like this:

    Cursor c = getContentResolver().query(Data.CONTENT_URI,
         new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
                       Data.RAW_CONTACT_ID + "=?" + " AND "
                       + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
                       new String[] {String.valueOf(rawContactId)
         }, null)
Kelantan answered 23/5, 2011 at 18:56 Comment(1)
android-scripting API doesn't provide something like this. Here is what it provides: code.google.com/p/android-scripting/wiki/ApiReferenceLille
S
0

You may try, if didn't yet, the Contact API : http://developer.android.com/resources/articles/contacts.html

Supplicant answered 23/5, 2011 at 22:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.