基本信息
源码名称:android 最新版超高仿微信源码。
源码大小:29.05M
文件格式:.zip
开发语言:Java
更新时间:2017-02-16
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

测试账号:15918013302 密码:123456

import java.util.List;


import net.tsz.afinal.FinalDb;
import android.app.Service;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.IBinder;
import android.provider.ContactsContract;
import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.juns.wechat.Constants;
import com.juns.wechat.GloableParams;
import com.juns.wechat.bean.GroupInfo;
import com.juns.wechat.bean.User;
import com.juns.wechat.common.Utils;
import com.juns.wechat.net.BaseJsonRes;
import com.juns.wechat.net.NetClient;

public class UpdateService extends Service {
    protected NetClient netClient;
    protected FinalDb db;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        netClient = new NetClient(this);
        db = FinalDb.create(this, Constants.DB_NAME, false);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        int RunCount = Utils.getIntValue(this, "RUN_COUNT");
        if (RunCount % 10 == 0) {
            initUserList();
            initGroupList();

            String str_contact = Utils.getValue(this, Constants.ContactMsg);
            PackageManager pm = getPackageManager();
            boolean permission = (PackageManager.PERMISSION_GRANTED == pm
                    .checkPermission("android.permission.READ_CONTACTS",
                            "com.juns.wechat"));
            if (TextUtils.isEmpty(str_contact) && permission) {
                str_contact = getContact();
                Utils.putValue(this, Constants.ContactMsg, str_contact);
            }
        }
        return super.onStartCommand(intent, flags, startId);
    }

    // 获取群组列表
    private void initGroupList() {
        GloableParams.ListGroupInfos = db.findAll(GroupInfo.class);
        netClient.post(Constants.getGroupListURL, null, new BaseJsonRes() {

            @Override
            public void onMySuccess(String data) {
                GloableParams.ListGroupInfos = JSON.parseArray(data,
                        GroupInfo.class);
                for (GroupInfo group : GloableParams.ListGroupInfos) {
                    if (db.findById(group.getId(), GroupInfo.class) != null)
                        db.deleteById(GroupInfo.class, group.getId());
                    db.save(group);
                    GloableParams.GroupInfos.put(group.getGroup_id(), group);
                }
                sendBrodcast("GroupList");
            }

            @Override
            public void onMyFailure() {
                // initGroupList();
            }
        });
    }

    // 获取好友列表和订阅号
    private void initUserList() {
        GloableParams.UserInfos = db.findAll(User.class);

        netClient.post(Constants.getUserInfoURL, null, new BaseJsonRes() {

            @Override
            public void onMySuccess(String data) {
                List<User> new_users = JSON.parseArray(data, User.class);
                for (User user : new_users) {
                    if (user.getUserName() == null) {
                        user.setUserName("WX" user.getTelephone());
                        new_users.remove(user);
                        new_users.add(user);
                    }
                    if (db.findById(user.getId(), User.class) != null)
                        db.deleteById(User.class, user.getId());
                    db.save(user);
                    GloableParams.Users.put(user.getTelephone(), user);
                }
                sendBrodcast("UserList");
            }

            @Override
            public void onMyFailure() {
                // initUserList();
            }
        });
    }

    public String getContact() {
        // 获得所有的联系人
        String strTelphones = "";
        String strNames = "";
        Cursor cur = getContentResolver().query(
                ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

        // 循环遍历
        if (cur.moveToFirst()) {
            int idColumn = cur.getColumnIndex(ContactsContract.Contacts._ID);
            int displayNameColumn = cur
                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
            do {
                // 获得联系人的ID号
                String contactId = cur.getString(idColumn);
                // 获得联系人姓名
                String disPlayName = cur.getString(displayNameColumn);
                // 查看该联系人有多少个电话号码。如果没有这返回值为0
                int phoneCount = cur
                        .getInt(cur
                                .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
                if (phoneCount > 0) {
                    // 获得联系人的电话号码
                    Cursor phones = getContentResolver().query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                     " = " contactId, null, null);
                    if (phones.moveToFirst()) {
                        do { // 遍历所有的电话号码
                            String phoneNumber = phones
                                    .getString(phones
                                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                            if (phoneNumber.startsWith(" 186")) {
                                phoneNumber = phoneNumber.substring(4);
                            }
                            if (Utils.isMobileNO(phoneNumber)) {
                                strTelphones = strTelphones "'" phoneNumber
                                         "',";
                                strNames = strNames "',";
                            }
                        } while (phones.moveToNext());
                    }
                }
            } while (cur.moveToNext());
        }
        if (strTelphones.length() > 0 && strNames.length() > 0) {
            strTelphones = strTelphones.substring(0, strTelphones.length() - 1);
            strNames = strNames.substring(0, strNames.length() - 1);
        }
        return strTelphones;
    }

    private void sendBrodcast(String Action) {
        Intent intent = new Intent();
        intent.setAction("com.juns.wechat.Brodcast");
        intent.putExtra("Action", Action);
        sendBroadcast(intent);
    }
}