通过导航抽屉中的SMS列出最近的联系人

时间:2014-08-09 03:25:05

标签: android

我想在最近的顶部列出导航抽屉中最近消息的联系人,但是mDrawerListView(创建导航抽屉的字符串)在NavigationDrawerFragment.java中,列出名称的函数可以&#因为getContentResolver()和getApplicationContext()未定义,所以请使用。我也不确定如何将名单列表中的项目作为mDrawerListView的字符串。

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    mDrawerListView = (ListView) inflater.inflate(
            R.layout.fragment_navigation_drawer, container, false);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }

    });
    getAllSms();
    mDrawerListView.setAdapter(new ArrayAdapter<String>(
            getActionBar().getThemedContext(),
            android.R.layout.simple_list_item_1,
            android.R.id.text1,
            new String[]{
                    getString(R.string.title_section1),
                    getString(R.string.title_section2),
                    getString(R.string.title_section3),
            }));
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    return mDrawerListView;
}
public void getAllSms() {
Uri message = Uri.parse("content://sms/");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(message, null, null, null, null);
int totalSMS = c.getCount();
List<String> names = new ArrayList<String>();
if (c.moveToFirst()) {
    for (int i = 0; i < totalSMS; i++) {
        names.add(getContactName(
                getApplicationContext(),
                c.getString(c
                        .getColumnIndexOrThrow("address"))));
        c.moveToNext();
    }
}
c.close();
}

0 个答案:

没有答案