如何在通知栏上显示volte图标而不是hd?

ht4b089n  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(242)

如标题所述,在启用ims时,如何在通知栏上显示volte图标而不是hd图标。首选网络类型必须仅设置为lte才能启用ims/volte。如何禁用hd图标并替换为volte图标
问:是否有一些要设置/启用的配置来禁用showhdicon配置之类的东西?我是java新手,但我在这个java文件中发现了一个api tho:我应该更改什么值?

  1. package org.codeaurora.ims;
  2. import android.app.ActivityManager;
  3. import android.app.Notification;
  4. import android.app.NotificationChannel;
  5. import android.app.NotificationManager;
  6. import android.content.BroadcastReceiver;
  7. import android.content.Context;
  8. import android.content.Intent;
  9. import android.content.pm.PackageManager;
  10. import android.content.res.Resources;
  11. import android.os.Bundle;
  12. import android.os.PersistableBundle;
  13. import android.os.UserHandle;
  14. import android.telephony.TelephonyManager;
  15. import android.telephony.ims.feature.ImsFeature;
  16. import android.telephony.CarrierConfigManager;
  17. import android.telephony.SubscriptionInfo;
  18. import android.telephony.SubscriptionManager;
  19. import com.qualcomm.ims.utils.Log;
  20. import java.util.List;
  21. /**
  22. * This ImsServiceStateReceiver is generic class which is used to handle
  23. * ims service state and do required process.
  24. */
  25. public class ImsServiceStateReceiver extends BroadcastReceiver {
  26. private static final String LOG_TAG = "ImsServiceStateReceiver";
  27. //This flag will be set to false during initialization.
  28. private boolean mShowHDIcon = true;
  29. private boolean mShowVOLTEIcon = false;
  30. private ImsServiceSub mServiceSub;
  31. private Context mContext;
  32. private int mPhoneId = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
  33. private NotificationManager mNotificationMgr = null;
  34. //Unique number to show HD icon on notification bar
  35. private static final int IMS_HD_ICON = 1000;
  36. private static String CHANNEL_ID = "ims_services_channel_";
  37. private static final String SHOW_HD_ICON = "config_update_service_status";
  38. private static final String SHOW_VOLTE_ICON = "config_update_volte_icon";
  39. public ImsServiceStateReceiver(ImsServiceSub serviceSub, Context context, int phoneId) {
  40. mServiceSub = serviceSub;
  41. mContext = context;
  42. mPhoneId = phoneId;
  43. }
  44. public void updateHDIcon(boolean isVideoCapable, boolean isVoiceCapable) {
  45. Log.i(LOG_TAG, "updateHDIcon isVideo : " + isVideoCapable + " isVoice : " +
  46. isVoiceCapable + " phoneId: " + mPhoneId + " show HD Icon: " + mShowHDIcon);
  47. if (ImsCallUtils.isCarrierOneSupported()) {
  48. return;
  49. }
  50. if (mServiceSub.getFeatureState() == ImsFeature.STATE_READY) {
  51. if (shallShowHDIcon()) {
  52. showHDIcon(isVideoCapable || isVoiceCapable);
  53. } else {
  54. // Remove the HD icon during phone process crash/SIM Remove.
  55. showHDIcon(false);
  56. }
  57. } else {
  58. // Remove the HD icon if featureState is not STATE_READY
  59. showHDIcon(false);
  60. }
  61. }
  62. public static void overrideNotificationAppName(Context context, Notification.Builder n) {
  63. final Bundle extras = new Bundle();
  64. extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME,
  65. context.getResources().getString(R.string.hd_icon_header_app_name));
  66. n.addExtras(extras);
  67. }
  68. private void showHDIcon(boolean showHDIcon) {
  69. if (mShowHDIcon == showHDIcon) return;
  70. if (mNotificationMgr == null) {
  71. try {
  72. mNotificationMgr = (NotificationManager) mContext.createPackageContextAsUser(
  73. mContext.getPackageName(), 0, UserHandle.of(ActivityManager.
  74. getCurrentUser())).getSystemService(Context.NOTIFICATION_SERVICE);
  75. } catch (PackageManager.NameNotFoundException e) {
  76. Log.w(LOG_TAG, "showHDIcon Package name not found: " + e.getMessage());
  77. }
  78. }
  79. if (mNotificationMgr == null) {
  80. Log.e(LOG_TAG, "showHDIcon unable to show HD icon due to NotificationManager is null");
  81. return;
  82. }
  83. mShowHDIcon = showHDIcon;
  84. if (mShowHDIcon) {
  85. NotificationChannel channel = mNotificationMgr.
  86. getNotificationChannel(CHANNEL_ID + mPhoneId);
  87. if (channel == null) {
  88. CharSequence name = mContext.getResources().getString(R.string.ims_channel_name);
  89. int importance = NotificationManager.IMPORTANCE_LOW;
  90. channel = new NotificationChannel(CHANNEL_ID + mPhoneId, name, importance);
  91. mNotificationMgr.createNotificationChannel(channel);
  92. }
  93. Notification.Builder builder = new Notification.Builder(mContext);
  94. builder.setChannelId(channel.getId());
  95. if (mShowVOLTEIcon) {
  96. builder.setContentTitle(mContext.getResources().getString(
  97. R.string.device_is_volte_capable,
  98. mPhoneId + 1));
  99. builder.setSmallIcon(R.drawable.volte_icon);
  100. } else {
  101. builder.setContentTitle(mContext.getResources().getString(
  102. R.string.device_is_hd_capable,
  103. mPhoneId + 1));
  104. builder.setSmallIcon(R.drawable.ims_state);
  105. }
  106. builder.setShowWhen(false);
  107. overrideNotificationAppName(mContext, builder);
  108. Notification notification = builder.build();
  109. notification.flags |= Notification.FLAG_NO_CLEAR;
  110. mNotificationMgr.notify(IMS_HD_ICON + mPhoneId, notification);
  111. } else {
  112. mNotificationMgr.cancel(IMS_HD_ICON + mPhoneId);
  113. }
  114. }
  115. private boolean shallShowHDIcon() {
  116. boolean showHDIcon = false;
  117. SubscriptionManager subManager = (SubscriptionManager) mContext.getSystemService(
  118. Context.TELEPHONY_SUBSCRIPTION_SERVICE);
  119. if (subManager == null) {
  120. Log.i(LOG_TAG, "shallShowHDIcon SubscriptionManager is null");
  121. return showHDIcon;
  122. }
  123. SubscriptionInfo subInfo = subManager.getActiveSubscriptionInfoForSimSlotIndex(mPhoneId);
  124. if (subInfo == null) {
  125. Log.i(LOG_TAG, "shallShowHDIcon SubscriptionInfo is null");
  126. return showHDIcon;
  127. }
  128. int subId = subInfo.getSubscriptionId();
  129. if (!subManager.isActiveSubscriptionId(subId)) {
  130. Log.i(LOG_TAG, "shallShowHDIcon subId is not active");
  131. return showHDIcon;
  132. }
  133. CarrierConfigManager mgr = (CarrierConfigManager) mContext.getSystemService(
  134. Context.CARRIER_CONFIG_SERVICE);
  135. PersistableBundle b = null;
  136. if (mgr != null) {
  137. b = mgr.getConfigForSubId(subId);
  138. }
  139. if (b != null) {
  140. showHDIcon = b.getBoolean(SHOW_HD_ICON, false);
  141. mShowVOLTEIcon = b.getBoolean(SHOW_VOLTE_ICON, false);
  142. }
  143. Log.i(LOG_TAG, "shallShowHDIcon config showHDIcon : " + showHDIcon +
  144. " phoneId : " + mPhoneId);
  145. return showHDIcon;
  146. }
  147. @Override
  148. public void onReceive(Context context, Intent intent) {
  149. SubscriptionManager subManager = (SubscriptionManager) mContext.getSystemService(
  150. Context.TELEPHONY_SUBSCRIPTION_SERVICE);
  151. SubscriptionInfo subInfo = subManager.getActiveSubscriptionInfoForSimSlotIndex(mPhoneId);
  152. if (subInfo == null) {
  153. Log.w(LOG_TAG, "SimStateReceiver onReceive subId is not yet active");
  154. return;
  155. }
  156. int subId = subInfo.getSubscriptionId();
  157. if (TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED.equals(intent.getAction())) {
  158. int simStatus = intent.getIntExtra(TelephonyManager.EXTRA_SIM_STATE,
  159. TelephonyManager.SIM_STATE_UNKNOWN);
  160. int intentSubId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
  161. SubscriptionManager.INVALID_SUBSCRIPTION_ID);
  162. Log.d(LOG_TAG, "SimStateReceiver sub id from intent : " + intentSubId +
  163. " simStatus : " + simStatus);
  164. if (intentSubId == subId && TelephonyManager.SIM_STATE_LOADED == simStatus) {
  165. updateHDIcon(mServiceSub.isVideoSupported(), mServiceSub.isVoiceSupported());
  166. //Update latest known UT value to framework as the UT be reset when IMS
  167. //capabilities come earlier than carrier config sometimes at boot time.
  168. mServiceSub.onIccLoaded();
  169. }
  170. } else if (intent != null && intent.getAction()
  171. .equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
  172. int intentSubId = intent.getIntExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX,
  173. SubscriptionManager.INVALID_SUBSCRIPTION_ID);
  174. Log.d(LOG_TAG, "received carrier config change, sub id from intent : " + intentSubId);
  175. if (subId == intentSubId) {
  176. updateHDIcon(mServiceSub.isVideoSupported(), mServiceSub.isVoiceSupported());
  177. }
  178. }
  179. }
  180. }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题