Android:邮件搜索 - 点击搜索结果时打开特定的邮件对话

时间:2014-07-16 09:11:55

标签: android

我的项目需要一些帮助。

我制作了一个能够在设备中搜索联系人,应用程序和消息的Android应用程序。应用程序和联系人正在运行,但我在发送消息时遇到问题,因为当您点按时它不会转到所需搜索消息的对话。

我想要的只是当您点按搜索消息时,它会转到对话中。当我运行我的代码时,它只会转到对话列表而不是打开特定的对话。 这是消息中的代码:

package com.android.searching.engines;

import java.util.List;
import android.content.ComponentName;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import com.android.searching.ContentManager.Results;

public class SmsEngine extends Engine {
    public SmsEngine(Context context, String type) {
        super(context, type);
        if (sSmsIcon == null) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setType("vnd.android-dir/mms-sms");
            PackageManager pm = context.getPackageManager();
            List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
            if (list != null && list.size() == 1) {
                sSmsIcon = list.get(0).loadIcon(pm);
            }
        }
    }
    private static Drawable sSmsIcon = null;
    private static String smsAll = "content://sms/";
    @Override
    protected void doSearch(Context context, Results results, String pattern, boolean isPresearch) {
        String selection = null;
        if (!pattern.equals("")) {
            selection = "address like '%" + pattern + "%' or body like '%" + pattern + "%'";
        }
        final Uri smsUri = Uri.parse(smsAll);
        Cursor cursor = context.getContentResolver().query(smsUri, null,
        selection, null, "date desc");
        if (cursor != null) {
            int idNum = cursor.getColumnIndex("_id");
            int addressNum = cursor.getColumnIndex("address");
            int bodyNum = cursor.getColumnIndex("body");
            while (cursor.moveToNext()) {
                results.add(new SmsResult(null, cursor.getString(idNum), cursor.getString(addressNum), cursor.getString(bodyNum)));
            }
            cursor.close();
        }
    }
    public class SmsResult extends Engine.IResult {
        protected SmsResult(Drawable icon, String id, String address, String body) {
            super(id, icon, address, body);
        }
        @Override
        public Drawable getIcon() {
            return sSmsIcon == null ? sDefaultIcon : sSmsIcon;
        }
        @Override
        public void onClick(Context context) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setComponent(new ComponentName("com.android.mms",
            "com.android.mms.ui.Conversation"));
            intent.setClassName("com.android.mms", "com.android.mms.ui.ConversationList");
            intent.setType("vnd.android-dir/mms-sms");
            Uri uri = ContentUris.withAppendedId(Uri.parse("content://sms/conversations/"),
            Long.parseLong(mId));
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(uri);
            context.startActivity(intent);
        }
    }
}

您的回复将非常有帮助和赞赏。 谢谢。

0 个答案:

没有答案