我如何获得联系人姓名和他/她的号码
我正在尝试使用Android脚本和Python开发一个简单的应用程序。我如何获得联系人姓名和他/她的号码
现在,我有一个电话号码,我想找出哪个联系人有该号码。我可以做一个contactsGet()并搜索数字,但是很多程序都使用该功能,我认为这有一个更简单的方法。
还有一个问题存在同样的问题,但是Java有没有Python的等价物? Search contact by phone number
有没有简单的方法来实现这一目标?
任何示例代码表示赞赏。
编辑,几天后没有回答,我决定改变一点问题:什么是最好的方式来搜索一个数字的列表,我与contactsGet()?
这是抽象层,一个常见的问题。该图层不会抽象出您想要使用的特定功能,工具或案例。然而,在这种情况下,似乎并非所有的希望都失去了。看来,Android脚本API是一个开源项目。为什么不贡献一个能够为项目提供这种能力的补丁?
我可能会在未来某个时候提供这样的补丁,但是如果它对你很重要,那么你可以在做之前做同样的事情,并且在路上!
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;
}
}
}
问题是它的Python等价物。 – utdemir 2011-05-23 14:27:08
你可能想看看ContactsContract data table。像这样的东西进行查询:
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)
android-scripting API不提供像这样的东西。这是它提供的:http://code.google.com/p/android-scripting/wiki/ApiReference – utdemir 2011-05-23 19:04:47
这是唯一的答案,其中包括我的问题可能的解决方案:)。似乎没有其他办法。谢谢 :)。 – utdemir 2011-05-24 16:15:07