【问题标题】:Sending USSD code with alphabetic characters发送带有字母字符的 USSD 代码
【发布时间】:2014-04-01 11:18:20
【问题描述】:

在我的 android 应用程序中,我使用下面的 Intent 发送 USSD 代码 (#144#73#):

String baseUssd = Uri.encode("#") + "144" + Uri.encode("#");
StringBuilder builder = new StringBuilder();
builder.append(baseUssd);
builder.append("73");
builder.append(Uri.encode("#"));

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + builder.toString()));

它运作良好。

我现在想要的是发送这个代码:

#144#73MA#

我使用拨号盘,按照 Operator USSD 菜单 运行此程序,效果很好。 但是,如果我尝试以编程方式使用上面的Intent 来做这件事,那就行不通了。

我知道用拨号盘输入代码时不能使用字母字符,但我认为这可以通过编程方式实现!!

请有任何想法!

编辑

当我尝试以编程方式发送此信息时:#144#73MA# 我注意到拨号器应用程序将字母字符更改为拨号盘中对应的数字。意思是拨号器转换这个:#144#73MA#

对这个#144#7362#:为什么?

因为:

  • M 匹配数字 6
  • A 匹配数字 2

【问题讨论】:

  • 使用上述无效的 Intent --- 请定义它到底是如何无效的。
  • 感谢@shoerat,很高兴看到您的评论!让我编辑我的答案。
  • 您找到解决方案了吗?

标签: android character-encoding character ussd


【解决方案1】:

意思是拨号器转换这个:#144#73MA#

这个#144#7362#:为什么?

我会尽量只回答为什么部分。

Intent.ACTION_CALLOutgoingCallBroadcaster 类处理。如果你查看processIntent() 方法,有这段代码(撰写本文时的第 438~448 行):

String number = PhoneNumberUtils.getNumberFromIntent(intent, this);
// Check the number, don't convert for sip uri
// TODO put uriNumber under PhoneNumberUtils
if (number != null) {
    if (!PhoneNumberUtils.isUriNumber(number)) {
        number = PhoneNumberUtils.convertKeypadLettersToDigits(number);
        number = PhoneNumberUtils.stripSeparators(number);
    }
} else {
    Log.w(TAG, "The number obtained from Intent is null.");
}

PhoneNumberUtils.convertKeypadLettersToDigits() 将字母转换为等效的数字:

public static String convertKeypadLettersToDigits(字符串输入)

根据 ITU E.161 和 ISO/IEC 9995-8 中描述的电话键盘字母映射,将指定电话号码中的任何字母(即 [A-Za-z])转换为等效的数字。

退货
输入字符串,使用电话键盘字母映射将字母字母转换为数字。例如,输入“1-800-GOOG-411”将返回“1-800-4664-411”。

希望这会有所帮助。

【讨论】:

  • 谢谢,很有帮助!但是请告诉我,是否有可能改变这种行为?通过覆盖OutgoingCallBroadcaster 方法或类似的方法?!
  • 我不知道如何实现这一点,除非您可以使用其他特殊字符而不是字母;例如,~& 而不是 MA
  • 不幸的是我不能。我正在制作一个使用 USSD 运营商代码的应用程序。我无法更改代码!
猜你喜欢
  • 1970-01-01
  • 2013-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多