Skip to content

Commit

Permalink
提交消息中心
Browse files Browse the repository at this point in the history
  • Loading branch information
马天宇 committed Mar 10, 2015
1 parent 911289e commit 4907f8b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LiteCommon是一系列通用类、辅助类、工具类的集合,有以下特
6. receiver包:通用广播接收器
-----
- **ScreenReceiver**: 屏幕接收器,可收到屏幕点亮、关闭的广播,并通过回调通知给调用者
- **SmsReceiver**: 短信接收器,可接受短信广播,并将内容反馈给调用者
- **SmsReceiver**: 短信接收器,可获取收到短信的内容,并将内容反馈给调用者
7. utils包:常用工具类
-----
- **AndroidUtil**: android信息, 获取android手机品牌、商家、版本号等信息
Expand All @@ -63,6 +63,13 @@ LiteCommon是一系列通用类、辅助类、工具类的集合,有以下特
- **TelephoneUtil**: 电话工具类,手机号、运营商、IMEI、IMSI等信息
- **VibrateUtil**: 震动工具类,调用系统震动功能

7. 升级:2014-3-9新增
-----
receiver包:通用广播接收器
- **PhoneReceiver**: 电话监听,来电、来电挂断,电话播出、通话、挂断的监听以及来去电话号码的获取。
- **SmsReceiver**: 短信接收器,升级后可获取短信内容,发送者号码,短信中心号码等。
service包:通用服务
- **NotificationService**:通知监听,各类通知服务的监听,获取通知的简述、标题、内容等信息,可以获取诸如QQ、微信、淘宝、浏览器等所有的在通知栏提示的消息。

关于作者(About Author)
-----
Expand Down
2 changes: 1 addition & 1 deletion android-common.iml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
<orderEntry type="jdk" jdkName="Android API 3 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
42 changes: 35 additions & 7 deletions src/com/litesuits/common/receiver/SmsReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.*;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import com.litesuits.android.log.Log;
Expand All @@ -12,7 +13,7 @@
/**
* Call requires API level 4
* <uses-permission android:name="android.permission.RECEIVE_SMS"/>
*
* <p/>
* action: android.provider.Telephony.SMS_RECEIVED
*
* @author MaTianyu
Expand All @@ -29,18 +30,43 @@ public SmsReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
Log.i(TAG, "收到广播:" + intent.getAction());
if (Log.isPrint) {
Log.i(TAG, "收到广播:" + intent.getAction());
Bundle bundle = intent.getExtras();
for (String key : bundle.keySet()) {
Log.i(TAG, key + " : " + bundle.get(key));
}
}
Object[] pdus = (Object[]) intent.getExtras().get("pdus");
String fromAddress = null;
String serviceCenterAddress = null;
if (pdus != null) {
String msgBody = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {
for (Object obj : pdus) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) obj);
msgBody += sms.getMessageBody();
fromAddress = sms.getOriginatingAddress();
serviceCenterAddress = sms.getServiceCenterAddress();

if (smsListener != null) {
smsListener.onMessage(sms);
}
//Log.i(TAG, "getDisplayMessageBody:" + sms.getDisplayMessageBody());
//Log.i(TAG, "getDisplayOriginatingAddress:" + sms.getDisplayOriginatingAddress());
//Log.i(TAG, "getEmailBody:" + sms.getEmailBody());
//Log.i(TAG, "getEmailFrom:" + sms.getEmailFrom());
//Log.i(TAG, "getMessageBody:" + sms.getMessageBody());
//Log.i(TAG, "getOriginatingAddress:" + sms.getOriginatingAddress());
//Log.i(TAG, "getPseudoSubject:" + sms.getPseudoSubject());
//Log.i(TAG, "getServiceCenterAddress:" + sms.getServiceCenterAddress());
//Log.i(TAG, "getIndexOnIcc:" + sms.getIndexOnIcc());
//Log.i(TAG, "getMessageClass:" + sms.getMessageClass());
//Log.i(TAG, "getUserData:" + new String(sms.getUserData()));
}
}
if (smsListener != null) {
smsListener.onMessage(msgBody);
smsListener.onMessage(msgBody, fromAddress, serviceCenterAddress);
}
}
} catch (Exception e) {
Expand Down Expand Up @@ -68,8 +94,10 @@ public void unRegisterSmsReceiver(Context context) {
}
}

public static interface SmsListener {
public void onMessage(String msg);
public static abstract class SmsListener {
public abstract void onMessage(String msg, String fromAddress, String serviceCenterAddress);

public void onMessage(SmsMessage msg) {}
}

/**
Expand All @@ -79,7 +107,7 @@ public static interface SmsListener {
* @param phone
* @param msg
*/
public void sendMsgToPhone(String phone, String msg) {
public static void sendMsgToPhone(String phone, String msg) {
Log.i(TAG, "发送手机:" + phone + " ,内容: " + msg);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {
SmsManager manager = SmsManager.getDefault();
Expand All @@ -99,7 +127,7 @@ public void sendMsgToPhone(String phone, String msg) {
* @param phone
* @param msg
*/
public void saveMsgToSystem(Context context, String phone, String msg) {
public static void saveMsgToSystem(Context context, String phone, String msg) {
ContentValues values = new ContentValues();
values.put("date", System.currentTimeMillis());
//阅读状态 
Expand Down

0 comments on commit 4907f8b

Please sign in to comment.