欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-11-12 10:22:28
要求设置默认信道50与60,并支持双卡。 在phoneapp.java文件中增加code: 在文件开头部分import 包: 复制代码 代码如下: import andro...
要求设置默认信道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;
}