返回顶部
首页 > 资讯 > 移动开发 >android如何设置小区广播默认信道(50与60并支持双卡)
  • 748
分享到

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

默认Android 2022-06-06 10:06:52 748人浏览 独家记忆
摘要

要求设置默认信道50与60,并支持双卡。 在PhoneApp.java文件中增加code: 在文件开头部分import 包: 代码如下: import Android.pro

要求设置默认信道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;
}
您可能感兴趣的文章:Android 广播大全 Intent Action 事件详解Android基于广播事件机制实现简单定时提醒功能代码Android实现静态广播监听器的方法Android广播接收机制详细介绍(附短信接收实现)Android中的广播和广播接收器代码实例Android 监听apk安装替换卸载广播的实现代码android如何默认打开小区广播具体实现Android给自定义按键添加广播和通过广播给当前焦点输入框赋值


--结束END--

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

本文链接: https://lsjlt.com/news/27666.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作