How to add a menu for setting dual-card ringtones in android Music

Source: Internet
Author: User

How to add a menu for setting dual-card ringtones in android Music

1. Enable the scenario mode to set the feature of the dual-card ringtone: MTK_MULTISIM_ROINGTONE_SUPPORT, but the dual-card ringtone cannot be set in Music. To add "Us as SIM1/SIM2 ringtone" in Music"

1, string. xml, add the new string ringtone_as_sim1_menu and ringtone_as_sim2_menu:

Use as SIM1 ringtone
Use as SIM2 ringtone

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


2) add Us as SIM1 ringtone/Us as SIM2 ringtone in menu based on the plug-in card. For details, refer to the 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. For details, refer to the modification between // start modify and // end modify.
Public boolean onContextItemSelected (MenuItem item ){
....
Switch (item. getItemId ()){
....
Case USE_AS_RINGTONE:
// Set the system setting to make this the current ringtone
MusicUtils. setRingtone (this, mSelectedId );
Return true;
// Start modify
Case USE_AS_SIM1_RINGTONE:
// Set the system setting to make this the current ringtone
MusicUtils. setRingtone (this, mSelectedId, 0 );
Return true;
Case USE_AS_SIM2_RINGTONE:
// Set the system setting to make this 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 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 shoshould be the last item
Public final static int CHILD_MENU_BASE = 18;


2) Add slotId to the new setRingtone () parameter.
A) query packages \ apps \ settings \ src \ com \ mediatek \ audioprofile \ DefaultRingtonePreference. whether java's onClick () has "setSimId (simList. get (0 ). mSimId); "indicates that the sim id is added when a single card is used. If there is a sim id, please refer to this article for the following modifications. 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 to make this the current ringtone
Cursor. moveToFirst ();

AudioProfileManager mProfileManager = (AudioProfileManager) context. getSystemService (Context. AUDIOPROFILE_SERVICE );
String mActiveProfileKey = mProfileManager. getActiveProfileKey ();


List 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) packages \ apps \ settings \ src \ com \ mediatek \ audioprofile \ DefaultRingtonePreference. whether java's onClick () has "setSimId (simList. get (0 ). mSimId); ". If you do not have this sentence, modify it 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 to make this 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 the slotId is-1:
Static void setRingtone (Context context, long id ){
SetRingtone (context, id,-1 );
}

Because some interfaces are deleted in the KK version, the current method is to restore the interfaces of the JB version.
To set dual-card ringtones for Music in KK, make the following changes:
1. Add the following code at the beginning of MusicUtils. java:
Import java. util. List;
Import android. provider. Telephony. SIMInfo;

2. Confirm to add the telephony-common library to Music's Android. mk:
LOCAL_JAVA_LIBRARIES + = mediatek-framework \
Telephony-common

3. Add the following method to mediatek \ frameworks \ base \ telephony \ java \ com \ mediatek \ telephony \ SimInfoManager. java:
/**
* Given a slot, return the Id of the SIM which is currently inserted in that slot
* @ Param ctx
* @ Param simSlotId the slot which the SIM is inserted
* @ Return the index of the SIM card in database, 0 indicate that 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;
}

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.