小编suk*_*rno的帖子

Android联系人提供商仅获取所有电子邮件的电话联系人

我需要获取所有电话联系人及其电子邮件地址和照片uri:

这就是我在做什么:

private void getContacts() {

        ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(Contacts.CONTENT_URI, null, null, null, Contacts.DISPLAY_NAME);

        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {

                // if
                // (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)))
                // > 0) {

                Contact contact = new Contact();

                String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));

                Uri uri = getContactPhotoUri(Long.parseLong(id));
                // set photoUri
                contact.setContactPhotoUri(uri);

                // set name
                contact.setContactName(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));

                // get the phone number
                Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
                while (pCur.moveToNext()) {

                    // …
Run Code Online (Sandbox Code Playgroud)

performance android android-contentresolver android-contentprovider android-contacts

22
推荐指数
1
解决办法
1万
查看次数

Android从收件箱中获取短信,优化了读取所有邮件并对其进行分组的方式

您好我正在实施一个短信应用程序,现在能够检索所有消息与他们各自的联系信息,如显示名称,照片uri ..并在一个自定义列表中显示它们在项目点击带您进行相应的讨论.在这里我的问题是同步所有这些消息的时间,

  1. 我需要优化这个时间.
  2. 每次我在讨论视图中发送新消息并返回到最近的聊天时,我只需要更新特定项目,而不是整个列表.

这是我的代码:

ReadSMS.java:

public class ReadSMS {

    ArrayList<HashMap<Contact, ArrayList<OneComment>>> recentChats;

    Application _context;

    public ReadSMS(Application context) {
        this._context = context;
        this.recentChats = ((ChatApplication) _context).getChats();
    }

    public ArrayList<HashMap<Contact, ArrayList<OneComment>>> getSMS() {

        // Init
        ArrayList<SmsMsg> smsMsgs = new ArrayList<SmsMsg>();
        TreeSet<Integer> threadIds = new TreeSet<Integer>();

        Uri mSmsinboxQueryUri = Uri.parse("content://sms");
        Cursor cursor = _context.getContentResolver().query(
                mSmsinboxQueryUri,
                new String[] { "_id", "thread_id", "address", "date", "body",
                        "type" }, null, null, null);

        String[] columns = new String[] { "address", "thread_id", "date",
                "body", "type" };
        if (cursor.getCount() …
Run Code Online (Sandbox Code Playgroud)

android android-contentresolver android-contentprovider android-contacts

12
推荐指数
2
解决办法
1万
查看次数

某些设备中的Android自定义相机问题

嗨,我有一个自定义相机,我点击按钮,点击它捕获图像...一切都很好,但在某些设备预览是拉伸,预览覆盖屏幕的一半,闪烁...一些奇怪的不需要的影响.如何解决这个问题?

这是我的代码:

相机活动:

preview = new Preview(this, (SurfaceView) findViewById(R.id.surfaceView));

preview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

((FrameLayout) findViewById(R.id.preview)).addView(preview);

preview.setKeepScreenOn(true);

buttonClick = (Button) findViewById(R.id.buttonClick);

buttonClick.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        // preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
        camera.takePicture(shutterCallback, rawCallback, jpegCallback);
        // camera.setDisplayOrientation(90);
        }
});
Run Code Online (Sandbox Code Playgroud)

预览课程:

class Preview extends ViewGroup implements SurfaceHolder.Callback {
    private final String TAG = "Preview";

    SurfaceView mSurfaceView;
    SurfaceHolder mHolder;
    Size mPreviewSize;
    List<Size> mSupportedPreviewSizes;
    Camera mCamera;

    @SuppressWarnings("deprecation")
    Preview(Context context, SurfaceView sv) {
        super(context);

        mSurfaceView = sv;
        // addView(mSurfaceView);

        mHolder = mSurfaceView.getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    } …
Run Code Online (Sandbox Code Playgroud)

performance android android-camera

7
推荐指数
1
解决办法
1121
查看次数

Android xmpp MUC设置默认配置

我正在使用Xabber开源项目,并且能够创建一个新组,但它总是说:这个房间从入口锁定,直到配置得到确认.我试图设置默认配置,但它抛出异常:401未经授权.究竟是什么问题.

final MultiUserChat multiUserChat;
        try {
            multiUserChat = new MultiUserChat(xmppConnection, room);
            // CHANAKYA: set default config for the MUC
            // Send an empty room configuration form which indicates that we want
            // an instant room
            try {
                multiUserChat.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
            } catch (XMPPException e) {
                e.printStackTrace();
            }
Run Code Online (Sandbox Code Playgroud)

android xmpp smack asmack

7
推荐指数
1
解决办法
2575
查看次数

Android gridview图像缓存,在更换之前重复滚动图像

我有GridView的图像视图,从图库的图像缩略图加载.我从一个用图像id和imageview调用方法的类中加载这些缩略图,该方法会将位图设置为通过imageview.这里它工作得很完美,但是当我们抛出网格视图时让线程暂停.

我的问题是它在滚动时暂停,但是当从上到下滚动时,图像在gridview中重复出现.我无法弄清楚确切的问题.帮帮我.谢谢!

我在这里设置暂停:

imagegrid.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                // Pause fetcher to ensure smoother scrolling when flinging
                if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                    bitmapFromId.setPauseWork(true);
                } else {
                    bitmapFromId.setPauseWork(false);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            }
        });
Run Code Online (Sandbox Code Playgroud)

这是我在grdiview适配器中获取的视图:

public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = mInflater.inflate(R.layout.galleryitem, null);
                holder.imageview = (ImageView) convertView.findViewById(R.id.thumbImage);
                holder.checkbox = …
Run Code Online (Sandbox Code Playgroud)

performance android android-adapter android-imageview android-gridview

5
推荐指数
1
解决办法
3284
查看次数