How Android Sets the cell broadcast default channel (50 and 60 and supports dual SIM) _android

Source: Internet
Author: User
Requires the default channel 50 and 60 to be set and a dual SIM card is supported.

Add code to the Phoneapp.java file:

At the beginning of the file, import the package:
Copy Code code 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 Code code 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 Code code as follows:

Case Message_set_state:
Handlesetstateresponse (msg);
Break

4. Register the Cellbroadcastrecivier in the OnCreate function:
Copy Code code as follows:

Intentfilter smsreadyintentfilter = new Intentfilter ("Android.provider.Telephony.SMS_STATE_CHANGED");
Registerreceiver (Msmsreadyreceiver,smsreadyintentfilter);

5. Add functions to the class:
Copy Code code 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.