android Music 中如何添加设置双卡铃声的菜单

1,打开情景模式的设置双卡铃声的feature:MTK_MULTISIM_ROINGTONE_SUPPORT,Music中却不能设置双卡铃声。
希望能在Music添加菜单“Us as SIM1/SIM2 ringtone”

1,string.xml,添加新的string ringtone_as_sim1_menu和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),添加:
import com.mediatek.telephony.SimInfoManager;
import com.mediatek.common.featureoption.FeatureOption;


2),menu根据插卡情况添加Us as SIM1 ringtone/Us as SIM2 ringtone, 参考//start modify和//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),添加USE_AS_SIM1_RINGTONE/USE_AS_SIM2_RINGTONE case的处理,参考//start modify和//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),添加USE_AS_SIM1_RINGTONE/USE_AS_SIM2_RINGTONE的定义,并修改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 be the last item
        public final static int CHILD_MENU_BASE = 18;


2)增加新的setRingtone()参数中增加slotId
a)请查询下packages\apps\settings\src\com\mediatek\audioprofile\DefaultRingtonePreference.java 的onClick()是否有“ setSimId(simList.get(0).mSimId);” 这句,这里表示使用单卡的时候,也加上SIM ID,如果有这句话请参考本条如下修改,如果没有下一条 b)的修改,:
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<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)packages\apps\settings\src\com\mediatek\audioprofile\DefaultRingtonePreference.java 的onClick()是否有“ setSimId(simList.get(0).mSimId);” 这句,如果没有这句话请参考本条如下修改:
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)原来的setRingtone(Context context, long id)改成调用 setRingtone(Context context, long id, int slotID),但是slotId为-1:
static void setRingtone(Context context, long id) {
  setRingtone(context, id,-1);
  }
 
由于KK版本中删除了个别接口,目前的做法是恢复JB版本的接口。
对于KK版本中Music设置双卡铃声,请继续做如下修改:
1、在MusicUtils.java中开始处添加如下代码:
import java.util.List;
import android.provider.Telephony.SIMInfo;
 
2、确认在Music的Android.mk中添加telephony-common的library:
LOCAL_JAVA_LIBRARIES += mediatek-framework \
        telephony-common
 
3、在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;
    }

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。