@@ -0,0 +1,2759 @@
+/*%0A * Copyright (C) 2016. All rights reserved.%0A *%0A * @author  Arno Zhang%0A * @email   zyfgood12@163.com%0A * @date    2016/10/13%0A */%0A%0Apackage com.jungle.widgets.misc;%0A%0Aimport android.content.ContentResolver;%0Aimport android.content.Context;%0Aimport android.database.ContentObserver;%0Aimport android.database.Cursor;%0Aimport android.net.Uri;%0Aimport android.os.Handler;%0Aimport com.jungle.base.manager.ThreadManager;%0A%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Apublic class SmsContentFilterReader extends ContentObserver %7B%0A%0A    private final Uri SMS_IN_BOX = Uri.parse(%22content://sms%22);%0A    public static final Pattern SIX_NUMBER_PATTERN = Pattern.compile(%22%5B0-9%5D%7B6%7D%22);%0A    public static final Pattern FOUR_NUMBER_PATTERN = Pattern.compile(%22%5B0-9%5D%7B4%7D%22);%0A%0A%0A    public interface OnFilterListener %7B%0A        void onFilter(String content);%0A    %7D%0A%0A%0A    private Context mContext;%0A    private Pattern mFilterPattern;%0A    private OnFilterListener mFilterListener;%0A%0A%0A    public SmsContentFilterReader(Context context, OnFilterListener listener) %7B%0A        this(context, ThreadManager.getInstance().getUIHandler(), FOUR_NUMBER_PATTERN, listener);%0A    %7D%0A%0A    public SmsContentFilterReader(%0A            Context context, Handler handler,%0A            Pattern pattern, OnFilterListener listener) %7B%0A%0A        super(handler);%0A        mContext = context;%0A        mFilterPattern = pattern;%0A        mFilterListener = listener;%0A        mContext.getContentResolver().registerContentObserver(SMS_IN_BOX, true, this);%0A    %7D%0A%0A    public void detachReader() %7B%0A        mContext.getContentResolver().unregisterContentObserver(this);%0A    %7D%0A%0A    @Override%0A    public void onChange(boolean selfChange) %7B%0A        super.onChange(selfChange);%0A%0A        ContentResolver resolver = mContext.getContentResolver();%0A        String%5B%5D projection = new String%5B%5D%7B%22body%22%7D;%0A        String whereCondition = String.format(%0A                %22 date %3E %25d%22, System.currentTimeMillis() - 1000 * 10);%0A%0A        Cursor cursor = null;%0A        try %7B%0A            cursor = resolver.query(%0A                    SMS_IN_BOX, projection, whereCondition, null, %22date desc%22);%0A            if (cursor == null) %7B%0A                return;%0A            %7D%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A            return;%0A        %7D%0A%0A        if (!cursor.moveToNext()) %7B%0A            cursor.close();%0A            return;%0A        %7D%0A%0A        int index = cursor.getColumnIndex(%22body%22);%0A        if (index != -1) %7B%0A            String body = cursor.getString(index);%0A            Matcher matcher = mFilterPattern.matcher(body);%0A            if (matcher.find()) %7B%0A                String content = matcher.group();%0A                mFilterListener.onFilter(content);%0A            %7D%0A        %7D%0A%0A        cursor.close();%0A    %7D%0A%7D%0A

add SMS reader.