当前位置:  编程技术>移动开发

android如何设置小区广播默认信道(50与60并支持双卡)

    来源: 互联网  发布时间:2014-10-17

    本文导语:  要求设置默认信道50与60,并支持双卡。 在PhoneApp.java文件中增加code: 在文件开头部分import 包: 代码如下: import android.provider.Telephony; import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo; import android.content.ContentValues; import android.d...

要求设置默认信道50与60,并支持双卡。

在PhoneApp.java文件中增加code:

在文件开头部分import 包:
代码如下:

import android.provider.Telephony;
import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
import android.content.ContentValues;
import android.database.Cursor;

2.在文件开头部分增加变量:
代码如下:

private final BroadcastReceiver mSmsReadyReceiver = new SmsReadyBroadcastReceiver();
private static final int MESSAGE_SET_STATE = 33;
private static final int MESSAGE_SET_CONFIG = 32;
private static final String KEYID = "_id";
private static final String NAME = "name";
private static final String NUMBER = "number";
private static final String ENABLE = "enable";
private static final Uri CHANNEL_URI = Uri.parse("content://cb/channel");
private static final Uri CHANNEL_URI1 = Uri.parse("content://cb/channel1");

3.在mHandeler中增加Case:
代码如下:

case MESSAGE_SET_STATE:
handleSetStateResponse(msg);
break;

4.在oncreate函数中注册cellbroadcastRecivier:
代码如下:

IntentFilter smsReadyIntentFilter = new IntentFilter("android.provider.Telephony.SMS_STATE_CHANGED");
registerReceiver(mSmsReadyReceiver,smsReadyIntentFilter);

5.在类中增加函数:
代码如下:

private class SmsReadyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent){
Log.e("kpp","Sms Ready!!");
String action = intent.getAction();
Log.e("kpp","Sms Ready action ="+action);
if (action.equals("android.provider.Telephony.SMS_STATE_CHANGED")) {
int extra = intent.getIntExtra("simId",0);
boolean isReady = intent.getBooleanExtra("ready",false);
Log.e("kpp","Sms Ready extra ="+extra);
Log.e("kpp","Sms Ready isReady ="+isReady);
if(!isReady){
return;
}
Message msg;
msg = mHandler.obtainMessage(MESSAGE_SET_STATE, extra, MESSAGE_SET_STATE,null);

if (FeatureOption.MTK_GEMINI_SUPPORT == true)
{
((GeminiPhone)phone).activateCellBroadcastSmsGemini(0,msg, extra);
}
else
{
phone.activateCellBroadcastSms(0,msg);
}
}
}
}


private void handleSetStateResponse(Message msg) {
int simId = msg.arg1;
if (msg.arg2 == MESSAGE_SET_STATE) {
AsyncResult ar = (AsyncResult) msg.obj;
if (ar == null) {
Log.i(LOG_TAG, "handleSetStateResponse,ar is null");
return;
}
if (ar.exception != null) {
if (DBG)
Log.d(LOG_TAG, "handleSetStateResponse: ar.exception="+ ar.exception);
} else {
Log.i(LOG_TAG, "handleSetStateResponse: re get ok");
addCustomChanneltoList(PhoneConstants.GEMINI_SIM_1,"Channel1",50);
addCustomChanneltoList(PhoneConstants.GEMINI_SIM_1,"Channel2",60);
addCustomChanneltoList(PhoneConstants.GEMINI_SIM_2,"Channel1",50);
addCustomChanneltoList(PhoneConstants.GEMINI_SIM_2,"Channel2",60);
}
}
}

private void addCustomChanneltoList(int mSimId,String channelName,int channelNum){
Log.d(LOG_TAG, "addCustomChanneltoList: mSimId=" + mSimId
+ ", channelName= " + channelName + ", channelNum= " + channelNum);
if(queryChannelFromDatabase(mSimId,channelName,channelNum)){
SmsBroadcastConfigInfo[] objectList = new SmsBroadcastConfigInfo[1];
objectList[0] = new SmsBroadcastConfigInfo(channelNum,channelNum, -1, -1, true);
Message msg1 = mHandler.obtainMessage(MESSAGE_SET_CONFIG, 0,MESSAGE_SET_CONFIG, null);
if (FeatureOption.MTK_GEMINI_SUPPORT == true)
{
((GeminiPhone)phone).setCellBroadcastSmsConfigGemini(objectList, objectList, msg1, mSimId);

}
else
{
phone.setCellBroadcastSmsConfig(objectList, objectList, msg1);
}
}
}

private boolean queryChannelFromDatabase(int mSimId,String channelName,int channelNum){
// ClearChannel();
Log.d(LOG_TAG, "queryChannelFromDatabase: mSimId=" + mSimId
+ ", channelName= " + channelName + ", channelNum= " + channelNum);
String[] projection = new String[] { KEYID, NAME, NUMBER, ENABLE };
String SELECTION = "(" + NUMBER + " = " + channelNum + ")";
Cursor cursor = null;
if(mSimId==PhoneConstants.GEMINI_SIM_1){
cursor = this.getContentResolver().query(CHANNEL_URI,projection, SELECTION, null, null);
}else if(mSimId==PhoneConstants.GEMINI_SIM_2){
cursor = this.getContentResolver().query(CHANNEL_URI1,projection, SELECTION, null, null);
}

if (cursor.getCount() == 0){
ContentValues values = new ContentValues();
values.put(NAME,channelName);
values.put(NUMBER, channelNum);
values.put(ENABLE, true);
try {
if(mSimId==PhoneConstants.GEMINI_SIM_1){
this.getContentResolver().insert(CHANNEL_URI, values);
}else if(mSimId==PhoneConstants.GEMINI_SIM_2){
this.getContentResolver().insert(CHANNEL_URI1, values);
}
} catch (Exception e){
return false;
}
}
cursor.close();
return true;
}

    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • Android开发之广播机制浅析
  • Android 开机广播的使用及配置
  • android 如何获取MCC/MNC控制小区广播的开启
  • android连接wifi时获取广播地址代码
  • Android 监听apk安装替换卸载广播的实现代码
  • Android中BroadcastReceiver(异步接收广播Intent)的使用
  • 申请Android Map 的API Key(v2)的最新申请方式(SHA1密钥)
  • Android瀑布流实例 android_waterfall
  • Android开发需要的几点注意事项总结
  • Android系统自带样式 (android:theme)
  • android 4.0 托管进程介绍及优先级和回收机制
  • Android网络共享软件 Android Wifi Tether
  • Android访问与手机通讯相关类的介绍
  • Android 图标库 Android GraphView
  • Android及andriod无线网络Wifi开发的几点注意事项
  • 轻量级Android开发工具 Android Tools
  • Android 2.3 下StrictMode介绍
  • Android 开发环境 Android Studio
  • IDEA的Android开发插件 idea-android
  • Android手机事件提醒 Android Notifier
  • XBMC的Android客户端 android-xbmcremote
  • Android小游戏 Android Shapes
  • Android电池监控 Android Battery Dog
  • android开发:“android:WindowTitle”没有对应项no resource
  • Android 上类似IOS 的开关控件。 Android ToggleButton
  • 网络技术 iis7站长之家
  • Android 2D游戏引擎 Android Angle


  • 站内导航:


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

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

    浙ICP备11055608号-3