簡體   English   中英

在android中進行USSD調用

[英]Make USSD call in android

要先檢查余額,我必須撥打電話* xxx#然后我會得到一個響應,有多個選項可供選擇,在輸入特定號碼后我得到余額。

在我的Android應用程序中,我可以使用哪些代碼?

撥打* xxx * x#給我錯誤。

下面是我的代碼,適用於* xxx#調用:

String encodedHash = Uri.encode("#");
String ussd = "*" + encodedHash + lCallNum + encodedHash;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd)));

這對我有用:

private Uri ussdToCallableUri(String ussd) {

    String uriString = "";

    if(!ussd.startsWith("tel:"))
        uriString += "tel:";

    for(char c : ussd.toCharArray()) {

        if(c == '#')
            uriString += Uri.encode("#");
        else
            uriString += c;
    }

    return Uri.parse(uriString);
}

然后在工作代碼中:

Intent callIntent = new Intent(Intent.ACTION_CALL, ussdToCallableUri(yourUSSDCodeHere));
startActivity(callIntent);

不要忘記添加權限,它將解決skype問題:P

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
String ussd = "*XXX*X" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd)));

這對我來說很完美。 只需放置第一束,然后對#進行編碼,使其具有完整的*XXX*X# 這肯定會有所幫助

要記住的重要事項:

如果您的目標是Android Marshmallow(6.0)或更高版本,那么您需要在運行時請求Manifest.permission.CALL_PHONE權限

試試這個,我沒有測試它,但應該工作。

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode("*3282#")));
startActivity(intent);

使用此代碼。 這個對我有用:

Intent intent = new Intent(Intent.ACTION_CALL);
    intent.setData(Uri.parse(Uri.parse("tel:" + "*947")+Uri.encode("#")));
    startActivity(intent);

使用此代碼,它的工作原理

Intent callIntent = new Intent(Intent.ACTION_CALL);
            String ussdCode = "*" + 2 + Uri.encode("#");
            callIntent.setData(Uri.parse("tel:" +ussdCode));

            if (ActivityCompat.checkSelfPermission(MainActivity.this,
                    Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            startActivity(callIntent);

在Manifest文件中也添加此行

<uses-permission android:name="android.permission.CALL_PHONE" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM