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;

}

时间: 2024-11-03 22:15:15

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

Android Stuido中SVN的设置

Android Stuido中自带各种版本控制工具选项,这里介绍下常用版本控制工具SVN的设置. 安装完Android Studio后需要继续安装TorToiseSVN客户端软件,下载地址:http://tortoisesvn.net/: 安装过程中,需要注意的是,TortoiseSVN默认是不安装SVN命令行工具的,如下图所示: 而这一工具恰好是Android Studio所需要的,因此安装中需要勾选command line client tools组件,如下图所示: 安装完成后进入Andro

Android ScrollView中的组件设置android:layout_height=&quot;fill_parent&quot;不起作用的解决办法

例子,在ScrollView下加入的组件,无论如何也不能自动扩展到屏幕高度. 布局文件. [html] <?xml version="1.0" encoding="utf-8"?> <!-- 背景:蓝色 --> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/scrollV

android编程中setLayoutParams方法设置

第一篇 private LinearLayout generateHeadOfControl() { LinearLayout LayoutHead = createLayout(LinearLayout.HORIZONTAL); Button DateButton = generateDateButton(); Button ItemButton = generateItemButton(); DateButton.setLayoutParams(new LinearLayout.Layout

Android适配器中字体颜色设置无效解决

 btn.setTextColor(R.color.main_color); 改为下面方法即可,通过上下文获取颜色值 btn.setTextColor(context.getResources().getColor(R.color.main_color));

NDK笔记(二)-在Android Studio中使用ndk-build

前面一篇我们接触了CMake,这一篇写写关于ndk-build的使用过程.刚刚用到,想到哪儿写哪儿. 环境背景 Android开发IDE版本:AndroidStudio 2.2以上版本(目前已经升级到2.2.3) 计算机环境:Window 64位系统 Demo工程的创建与设置 1.新建一个工程,并在app/src/main路径下新建jni文件夹. 2.在java代码中,新建NdkBuildTest类(包含native方法),并用javah命令生成头文件. 这里需要注意几点: (1)javah是J

NDK笔记(二)-在Android Studio中使用ndk-build(转)

前面一篇我们接触了CMake,这一篇写写关于ndk-build的使用过程.刚刚用到,想到哪儿写哪儿. 环境背景 Android开发IDE版本:AndroidStudio 2.2以上版本(目前已经升级到2.2.3) 计算机环境:Window 64位系统 Demo工程的创建与设置 1.新建一个工程,并在app/src/main路径下新建jni文件夹. 2.在java代码中,新建NdkBuildTest类(包含native方法),并用javah命令生成头文件. 这里需要注意几点: (1)javah是J

android中的颜色设置

1.在android中经常看到设置的颜色为八位的十六进制的颜色值,例如: 1 2 3 public static final class color {     public static final int lightblue=0x7f040000; } 或者在Java中tx.setTextColor(0xffff00f); 说明: 0xffff00ff是int类型的数据,分组一下0x|ff|ff00ff,0x表示颜色整数的标记,ff表示透明度,f00f表示色值,注意:0x后面ffff00ff

Android 中Theme的设置

在 style.xml 中注册自己的theme <style name="Mytext"> <item name="android:textSize">18sp</item> <item name="android:textColor">#ff99</item> </style> 在别的文件中引用 <ListView android:layout_width="

android应用中读取屏幕亮度、设置屏幕亮度、保持屏幕常量

应用中读取.设置屏幕亮度 package com.catcher.testcompass; import android.app.Activity; import android.os.Bundle; import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; import android.provider.Settings.System; import android.