android如何設定小區廣播預設通道(50與60並支援雙卡)

來源:互聯網
上載者:User

要求設定預設通道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;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.