How to add a menu to set up a dual-sim ringtone in Android Music

Source: Internet
Author: User

1, turn on profile settings The dual-card ringtones cannot be set in the Feature:mtk_multisim_roingtone_support,music. Want to be able to add menu "Us as sim1/sim2 ringtone" in music

1,string.xml, add a new string ringtone_as_sim1_menu and Ringtone_as_sim2_menu:

<string name= "Ringtone_as_sim1_menu" >use as SIM1 ringtone</string>
<string name= "Ringtone_as_sim2_menu" >use as SIM2 ringtone</string>

2,trackbrowseractivity.java:
1), add:
Import Com.mediatek.telephony.SimInfoManager;
Import com.mediatek.common.featureoption.FeatureOption;


2), menu add Us as SIM1 ringtone/us as SIM2 ringtone according to the card situation, referring to modifications between//start Modify and//end Modify
public void Oncreatecontextmenu (ContextMenu menu, view view, Contextmenuinfo Menuinfoin) {
....
int isdrm = 0;
if (MUSICFEATUREOPTION.IS_SUPPORT_DRM) {
ISDRM = Mtrackcursor.getint (Mtrackcursor.getcolumnindexorthrow (MediaStore.Audio.Media.IS_DRM));
int drmmethod = Mtrackcursor.getint (Mtrackcursor.getcolumnindexorthrow (MediaStore.Audio.Media.DRM_METHOD));
if (Candispalyringtone (ISDRM, Drmmethod)) {
Start Modify
if (Featureoption.mtk_gemini_support &&FeatureOption.MTK_MULTISIM_RINGTONE_SUPPORT&& ( Siminfomanager.getinsertedsimcount (this) ==2)) {
Menu.add (0, Use_as_sim1_ringtone, 0, R.string.ringtone_as_sim1_menu);
Menu.add (0, Use_as_sim2_ringtone, 0, R.string.ringtone_as_sim2_menu);
}else//end Modify
Menu.add (0, Use_as_ringtone, 0, R.string.ringtone_menu);
}
} else {
Start Modify
if (Featureoption.mtk_gemini_support && (Siminfowrapper.getdefault (). Getinsertedsimcount () ==2)) {
Menu.add (0, Use_as_sim1_ringtone, 0, R.string.ringtone_as_sim1_menu);
Menu.add (0, Use_as_sim2_ringtone, 0, R.string.ringtone_as_sim2_menu);
}else//end Modify
Menu.add (0, Use_as_ringtone, 0, R.string.ringtone_menu);
}
....
}


3), add Use_as_sim1_ringtone/use_as_sim2_ringtone case processing, refer to//start Modify and//end modify modifications
public boolean oncontextitemselected (MenuItem item) {
....
Switch (Item.getitemid ()) {
....
Case Use_as_ringtone:
Set the system setting the current ringtone
Musicutils.setringtone (this, mselectedid);
return true;
Start Modify
Case Use_as_sim1_ringtone:
Set the system setting the current ringtone
Musicutils.setringtone (this, mselectedid,0);
return true;
Case Use_as_sim2_ringtone:
Set the system setting the current ringtone
Musicutils.setringtone (this, mselectedid,1);
return true;
End Modify
....
}
3,musicutils.java:
1),
Import Com.mediatek.audioprofile.AudioProfileManager;
Import Com.mediatek.telephony.SimInfoManager;
Import com.mediatek.common.featureoption.FeatureOption;

2), add the definition of Use_as_sim1_ringtone/use_as_sim2_ringtone, and modify the Child_menu_base:
Public interface Defs {
....
M:add for DRM
Public final static int drm_info = 15;
Public final static int use_as_sim1_ringtone = 16;
Public final static int use_as_sim2_ringtone = 17;
Public final static int child_menu_base = 16; This should is the last item
Public final static int child_menu_base = 18;


2) Add new Setringtone () parameter to add SlotID
A) Please inquire under Packages\apps\settings\src\com\mediatek\audioprofile\defaultringtonepreference.java's onclick () if there is " Setsimid (Simlist.get (0). Msimid); "This sentence, here indicates the use of a single card when, also add the sim ID, if there is this sentence please refer to the following modification of this article, if there is no next b) Modification:
static void Setringtone (context context, long ID, int slotid) {
Contentresolver resolver = Context.getcontentresolver ();
Set the flag in the database to mark this as a ringtone
Uri Ringuri = Contenturis.withappendedid (MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id);
try {
Contentvalues values = new Contentvalues (2);
Values.put (MediaStore.Audio.Media.IS_RINGTONE, "1");
Values.put (MediaStore.Audio.Media.IS_ALARM, "1");
Resolver.update (Ringuri, values, NULL, NULL);
} catch (Unsupportedoperationexception ex) {
Most likely the card just got unmounted
MUSICLOGUTILS.E (TAG, "couldn ' t set ringtone flag for ID" + ID);
Return
}

string[] cols = new string[] {
MEDIASTORE.AUDIO.MEDIA._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.TITLE
};
M:use Selectionargs Replace set query value in where @{
String where = mediastore.audio.media._id + "=?";
string[] Whereargs = new string[]{string.valueof (ID)};
cursor cursor = query (context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
Cols, where, Whereargs, null);
/// @}



try {
if (cursor! = NULL && cursor.getcount () = = 1) {
Set the system setting the current ringtone
Cursor.movetofirst ();

Audioprofilemanager Mprofilemanager = (audioprofilemanager) context.getsystemservice (Context.AUDIOPROFILE_SERVICE) ;
String Mactiveprofilekey = Mprofilemanager.getactiveprofilekey ();


list<siminfo> simlist = siminfo.getinsertedsimlist (This.getcontext ());
int simnum = Simlist.size ();

if (featureoption.mtk_multisim_ringtone_support&& (slotid==-1) && (simnum==1)) {

String Urikey=mactiveprofilekey + suffix_ringer_uri+suffix_sim_id+simlist.get (0). Msimid;
Settings.System.putString (Resolver,urikey, ringuri.tostring ());
}
else if (featureoption.mtk_multisim_ringtone_support&& (slotid!=-1)) {
Long Simid = Siminfomanager.getidbyslot (context, SlotID);
Mprofilemanager.setringtoneuri (Mactiveprofilekey, Audioprofilemanager.type_ringtone, SimId, RingUri);
}
else{
Settings.System.putString (resolver, Settings.System.RINGTONE, ringuri.tostring ());
}
String message = context.getstring (R.string.ringtone_set, cursor.getstring (2));
Toast.maketext (context, message, Toast.length_short). Show ();
}
} finally {
....
}
}
b) Does the Packages\apps\settings\src\com\mediatek\audioprofile\defaultringtonepreference.java onclick () have "setSimId ( Simlist.get (0). Msimid); "This sentence, if not this sentence, please refer to this article to amend as follows:
static void Setringtone (context context, long ID, int slotid) {
Contentresolver resolver = Context.getcontentresolver ();
Set the flag in the database to mark this as a ringtone
Uri Ringuri = Contenturis.withappendedid (MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id);
try {
Contentvalues values = new Contentvalues (2);
Values.put (MediaStore.Audio.Media.IS_RINGTONE, "1");
Values.put (MediaStore.Audio.Media.IS_ALARM, "1");
Resolver.update (Ringuri, values, NULL, NULL);
} catch (Unsupportedoperationexception ex) {
Most likely the card just got unmounted
MUSICLOGUTILS.E (TAG, "couldn ' t set ringtone flag for ID" + ID);
Return
}

string[] cols = new string[] {
MEDIASTORE.AUDIO.MEDIA._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.TITLE
};
M:use Selectionargs Replace set query value in where @{
String where = mediastore.audio.media._id + "=?";
string[] Whereargs = new string[]{string.valueof (ID)};
cursor cursor = query (context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
Cols, where, Whereargs, null);
/// @}



try {
if (cursor! = NULL && cursor.getcount () = = 1) {
Set the system setting the current ringtone
Cursor.movetofirst ();

Audioprofilemanager Mprofilemanager = (audioprofilemanager) context.getsystemservice (Context.AUDIOPROFILE_SERVICE) ;
String Mactiveprofilekey = Mprofilemanager.getactiveprofilekey ();

if (featureoption.mtk_multisim_ringtone_support&& (slotid!=-1)) {
Long Simid = Siminfomanager.getidbyslot (context, SlotID);
Mprofilemanager.setringtoneuri (Mactiveprofilekey, Audioprofilemanager.type_ringtone, SimId, RingUri);
}
else{
Settings.System.putString (resolver, Settings.System.RINGTONE, ringuri.tostring ());
}
String message = context.getstring (R.string.ringtone_set, cursor.getstring (2));
Toast.maketext (context, message, Toast.length_short). Show ();
}
} finally {
....
}
}


3) The original Setringtone (context context, long ID) is changed to call Setringtone (context context, long ID, int slotid), but SlotID is-1:
static void Setringtone (context context, long ID) {
Setringtone (context, id,-1);
}

Since the individual interfaces are removed in the KK version, the current practice is to restore the JB version of the interface.
To set up a dual-sim ringtone for the KK version of Music, continue with the following modifications:
1. Add the following code at the beginning of the Musicutils.java:
Import java.util.List;
Import Android.provider.Telephony.SIMInfo;

2. Confirm that the library of Telephony-common is added to the android.mk of music:
Local_java_libraries + = mediatek-framework \
Telephony-common

3, add the following method in Mediatek\frameworks\base\telephony\java\com\mediatek\telephony\siminfomanager.java:
/**
* Given a slot, return the Id of the SIM which is currently inserted in this slot
* @param CTX
* @param simslotid the slot which the SIM is inserted
* @return The index of the SIM card in database, 0 indicate-no SIM card is inserted
*/
public static long Getidbyslot (Context ctx, int simslotid) {
Logd ("[getidbyslot]+ simslotid:" + Simslotid);
Siminforecord siminfo = Getsiminfobyslot (CTX, Simslotid);
if (siminfo! = null) {
Logd ("[getidbyslot]-siminfoid:" + siminfo.msiminfoid);
return siminfo.msiminfoid;
}
Logd ("[getidbyslot]-null info, return 0");
return 0;
}

How to add a menu to set up a dual-sim ringtone in Android Music

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.