How to set the default channel for residential broadcasting in android (50 and 60 with dual-card Support)

Source: Internet
Author: User

The default channels are 50 and 60, and dual-card is supported.

Add the code to the PhoneApp. java file:

Import package at the beginning of the file:Copy codeThe Code is as follows: import android. provider. Telephony;
Import com. android. internal. telephony. gsm. SmsBroadcastConfigInfo;
Import android. content. ContentValues;
Import android. database. Cursor;

2. Add the variable at the beginning of the file:Copy codeThe Code is as follows: 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. Add Case in mHandeler:Copy codeThe Code is as follows: case MESSAGE_SET_STATE:
HandleSetStateResponse (msg );
Break;

4. Register cellbroadcastRecivier in the oncreate function:Copy codeThe Code is as follows: IntentFilter smsReadyIntentFilter = new IntentFilter ("android. provider. Telephony. SMS_STATE_CHANGED ");
RegisterReceiver (mSmsReadyReceiver, smsReadyIntentFilter );

5. Add a function to the class:Copy codeThe Code is as follows: 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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.