如何从Android电子USSD code反应?反应、电子、Android、code

2023-09-06 00:25:16 作者:- 多情的男人未必花心

我WITE使用USSD code应用程序。我想发送请求USSD,但我不khow获取数据并保存在EQ字符串。

I wite application that use ussd code. I want send request for ussd but I dont khow get data and save in eq String.

样品code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btn = (Button) findViewById(R.id.button1);

    btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            String encodedHash = Uri.encode("#");
            String ussd = "*141*1" + encodedHash;
            startActivityForResult(new Intent("android.intent.action.CALL",
                    Uri.parse("tel:" + ussd)), 1);

        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);

    Toast.makeText(getApplicationContext(),
            "USSD: " + requestCode + "  " + resultCode + " ", 1).show();

    if (requestCode == 1) {

        if (resultCode == RESULT_OK) {
            // String result=data.getStringExtra("result");
            String dd = data.toString();
            Toast.makeText(getApplicationContext(), dd, 1).show();
        }

    }

截图应用程序:

Screenshots application:

如何解决我的问题?

推荐答案

拨号从一个自定义活动一USSD code是直截了当使用拨号或CALL意图,但听返回的结果是不是由于Android的不具有用于拦截USSD适当的支持平台内的电话,但存在原生拨号器应用程序中的部分虽然未公开的支持。

Dialing a USSD code from a custom activity is straight forward using a DIAL or CALL intent, but listening to the returned result is not due to Android not having proper support for intercepting USSD calls within the platform, but partial though undocumented support exists within the native dialer application.

作为开始,看看PhoneUtils类的Andr​​oid源$ C ​​$ C。链接是4.0.3,但我相信这部分的支持已经present自2.3。

As a start, look at the PhoneUtils class in the Android source code. The link is for 4.0.3 but I believe this partial support has been present since 2.3.

具体而言,在看线217,意图名为com.android.ussd.IExtendedNetworkService正在组成。所以,你需要做的是实现自己的服务,响应这一意图。的服务需要根据 IExtendedNetworkService.aidl 这是Android框架的一部分。

Specifically, looking at line 217, an intent with the name "com.android.ussd.IExtendedNetworkService" is being composed. So what you need to do is implement your own service that responds to that intent. The service needs to be implemented according to the IExtendedNetworkService.aidl which is a part of the Android framework.

在AIDL公开了几个功能,但我们所关心的一个是在该服务的getUserMessage(文本)功能。该文本是从USSD调用返回的最终值。

The aidl exposes several functions but the one we care about is the getUserMessage(text) function in that service. The text is the final value returned from the USSD call.

注:

由于该服务是由PhoneUtils绑定的,那么你就需要在手机启动时启动该服务。这也意味着,任何修改,服务将需要一个电话重新启动。 从getUserMessage返回null会燮preSS拨号从表示USSD的结果,但没有办法完全隐藏拨号器。 您还可以使用其他功能来改变显示的文本,而在通话过程中。 这似乎并没有工作在USSD提示(菜单),只对最后的结果。

结帐的一个例子code github上这里。

Checkout an example code on github here.