当前位置:  编程技术>移动开发
本页文章导读:
    ▪推荐一个美站点,音视频学习        推荐一个好站点,音视频学习 http://www.shouyanwang.org/forum.php ......
    ▪ 短信发送状态汇报流程分析        短信发送状态报告流程分析 短信发送状态报告流程分析 //应用层分析: //SmsSingleRecipientSender.java public boolean sendMessage(long token) throws MmsException { if (mMessageText == null) { // Don't try to send an empty mess.........
    ▪ 擒获home事件       捕获home事件 android中得home事件app是不能捕获的,但是我们可以通过如下方法捕获它   /** * home键的捕获,需要重写onAttachedToWindow并设置type */ private boolean catchHome=true; @Override public vo.........

[1]推荐一个美站点,音视频学习
    来源: 互联网  发布时间: 2014-02-18
推荐一个好站点,音视频学习

http://www.shouyanwang.org/forum.php


    
[2] 短信发送状态汇报流程分析
    来源: 互联网  发布时间: 2014-02-18
短信发送状态报告流程分析

短信发送状态报告流程分析

//应用层分析:
//SmsSingleRecipientSender.java
public boolean sendMessage(long token) throws MmsException {
if (mMessageText == null) {
// Don't try to send an empty message, and destination should be just
// one.
throw new MmsException("Null message body or have multiple destinations.");
}
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> messages = null;
if ((MmsConfig.getEmailGateway() != null) &&
(Mms.isEmailAddress(mDest) || MessageUtils.isAlias(mDest))) {
String msgText;
msgText = mDest + " " + mMessageText;
mDest = MmsConfig.getEmailGateway();
messages = smsManager.divideMessage(msgText);
} else {
messages = smsManager.divideMessage(mMessageText);
// remove spaces from destination number (e.g. "801 555 1212" -> "8015551212")
mDest = mDest.replaceAll(" ", "");
}
int messageCount = messages.size();

if (messageCount == 0) {
// Don't try to send an empty message.
throw new MmsException("SmsMessageSender.sendMessage: divideMessage returned " +
"empty messages. Original message is \"" + mMessageText + "\"");
}

boolean moved = Sms.moveMessageToFolder(mContext, mUri, Sms.MESSAGE_TYPE_OUTBOX, 0);
if (!moved) {
throw new MmsException("SmsMessageSender.sendMessage: couldn't move message " +
"to outbox: " + mUri);
}

ArrayList<PendingIntent> deliveryIntents =  new ArrayList<PendingIntent>(messageCount);
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>(messageCount);
for (int i = 0; i < messageCount; i++) {
if (mRequestDeliveryReport) {
// TODO: Fix: It should not be necessary to
// specify the class in this intent.  Doing that
// unnecessarily limits customizability.
deliveryIntents.add(PendingIntent.getBroadcast( //设置回执状态报告intent
mContext, 0,
new Intent(
MessageStatusReceiver.MESSAGE_STATUS_RECEIVED_ACTION, //底层发出的状态报告消息
mUri,
mContext,
MessageStatusReceiver.class),  //接收消息:MessageStatusReceiver. MESSAGE_STATUS_RECEIVED_ACTION,

0));
}
Intent intent  = new Intent(SmsReceiverService.MESSAGE_SENT_ACTION,
mUri,
mContext,
SmsReceiver.class);

int requestCode = 0;
if (i == messageCount -1) {
// Changing the requestCode so that a different pending intent
// is created for the last fragment with
// EXTRA_MESSAGE_SENT_SEND_NEXT set to true.
requestCode = 1;
intent.putExtra(SmsReceiverService.EXTRA_MESSAGE_SENT_SEND_NEXT, true);
}
sentIntents.add(PendingIntent.getBroadcast(mContext, requestCode, intent, 0));
}
try {
smsManager.sendMultipartTextMessage(mDest, mServiceCenter, messages, sentIntents, deliveryIntents/*在下发短信时设置deliveryIntents*/);  //注意此处
} catch (Exception ex) {
throw new MmsException("SmsMessageSender.sendMessage: caught " + ex +
" from SmsManager.sendTextMessage()");
}
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
log("sendMessage: address=" + mDest + ", threadId=" + mThreadId +
", uri=" + mUri + ", msgs.count=" + messageCount);
}
return false;
}

//应用层接收短信状态信息,并更新数据库
//MessageStatusReceiver.java
public void onReceive(Context context, Intent intent) {
        mContext = context;
        if (MESSAGE_STATUS_RECEIVED_ACTION.equals(intent.getAction())) {

            Uri messageUri = intent.getData();
            byte[] pdu = (byte[]) intent.getExtra("pdu");

            SmsMessage message = updateMessageStatus(context, messageUri, pdu);//更新短信状态:数据库SMS表status字段,状态报告取值:
/*STATUS_NONE = -1;
STATUS_COMPLETE = 0;
STATUS_PENDING = 32;
STATUS_FAILED = 64;
                */

            // Called on the UI thread so don't block.
            if (message.getStatus() < Sms.STATUS_PENDING)
                MessagingNotification.nonBlockingUpdateNewMessageIndicator(context,
                        true, message.isStatusReportMessage());
       }
}

//框架层分析:
//SMSDispatcher.java

@Override
    public void handleMessage(Message msg) {
        AsyncResult ar;

        switch (msg.what) {
          case EVENT_NEW_SMS_STATUS_REPORT:
                handleStatusReport((AsyncResult)msg.obj); //转到派生类GsmSMSDispatcher.java中处理
           break;

}
     }

//GsmSMSDispatcher.java
@Override
    protected void handleStatusReport(AsyncResult ar) {
        String pduString = (String) ar.result;
        SmsMessage sms = SmsMessage.newFromCDS(pduString);

        int tpStatus = sms.getStatus();

        if (sms != null) {
            int messageRef = sms.messageRef;
            for (int i = 0, count = deliveryPendingList.size(); i < count; i++) {
//deliveryPendingList定义在父类SMSDispatcher.java中,并在handleSendComplete函数里对每个短信发送完成后获取状态信息:
          /*if (tracker.mDeliveryIntent != null) {
                // Expecting a status report.  Add it to the list.
                int messageRef = ((SmsResponse)ar.result).messageRef;
                tracker.mMessageRef = messageRef;
                deliveryPendingList.add(tracker);
            }*/
//
                SmsTracker tracker = deliveryPendingList.get(i);
                if (tracker.mMessageRef == messageRef) {
                    // Found it.  Remove from list and broadcast.
                    if(tpStatus >= Sms.STATUS_FAILED || tpStatus < Sms.STATUS_PENDING ) {
                       deliveryPendingList.remove(i);
                    }
                    PendingIntent intent = tracker.mDeliveryIntent;
                    Intent fillIn = new Intent();
                    fillIn.putExtra("pdu", IccUtils.hexStringToBytes(pduString));
                    fillIn.putExtra("encoding", getEncoding());
                    try {
                        intent.send(mContext, Activity.RESULT_OK, fillIn);
                    } catch (CanceledException ex) {}

                    // Only expect to see one tracker matching this messageref
                    break;
                }
            }
        }
        acknowledgeLastIncomingSms(true, Intents.RESULT_SMS_HANDLED, null);
    }

 


    
[3] 擒获home事件
    来源: 互联网  发布时间: 2014-02-18
捕获home事件

android中得home事件app是不能捕获的,但是我们可以通过如下方法捕获它

 

	/**
	 * home键的捕获,需要重写onAttachedToWindow并设置type
	 */
	 private boolean catchHome=true;
    @Override
      public void onAttachedToWindow() {
    	if(catchHome)
            this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    	super.onAttachedToWindow();
    }

 

然后在keydown方法中

	public boolean onKeyDown(int keyCode,KeyEvent event){
		Log.d(this, "**************keycode home", "onKeyDown");
		if(keyCode==KeyEvent.KEYCODE_HOME){
						Log.d(this, "**************keycode home", "KEYCODE_HOME");
		}
		return super.onKeyDown(keyCode, event);
	}

 

但是捕获后会有个问题:app将不会在执行系统的home事件。

有大牛知道如何解决这个问题的话望告知


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android实用的代码片段 常用代码总结 iis7站长之家
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3