簡體   English   中英

在Android中運行USSD代碼並將應用程序保留在第一位

[英]Run USSD Code in Android and Keep the App in the firstground

我正在Android中創建一個應用程序,需要在后台運行USSD代碼。 沒有在后台發送我的申請,

每當我使用Intent.ACTION_CALL運行USSD時

String ussdCode = "*" + "123" + Uri.encode("#");
startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode)));

它在后台發送我的應用程序,並在我的應用程序上打開撥號程序接口。

因此,可以在沒有打開撥號器接口的情況下運行USSD代碼。

謝謝。

使用以下代碼:

String ussdCode = "*123#";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(ussdToCallableUri(ussdCode));
try{
    startActivity(intent);
} catch (SecurityException e){
    e.printStackTrace();
}

這是將你的ussd代碼轉換為可調用的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);
}

暫無
暫無

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

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