3

我想用USSD對話取決於其自帶撥號任何USSD代碼後* 123#它要求用戶輸入選項號以執行特定的任務(一個或多個)在SIM卡供應商。我需要與該對話框進行交互,以便以編程方式將其輸入到文本框中。如何使用USSD對話編程交互android的

但是,我能夠讀取任何撥打USSD代碼,使用AccessibilityService和我顯示如下圖所示的代碼在Toast響應後進來警報對話框的USSD響應。我還沒有找到任何解決方案與USSD對話框交互。

public class UssdService extends AccessibilityService{ 
    public static String TAG = "USSD"; 

    @Override 
    public void onAccessibilityEvent(AccessibilityEvent event) { 
     Log.d(TAG, "onAccessibilityEvent"); 
     String text = event.getText().toString(); 
     if (event.getClassName().equals("android.app.AlertDialog")) { 
      Log.d(TAG, text); 
      Toast.makeText(this, text, Toast.LENGTH_LONG).show(); 
     } 
    } 

    @Override 
    public void onInterrupt() { 
    } 

    @Override 
    protected void onServiceConnected() { 
     super.onServiceConnected(); 
     Log.d(TAG, "onServiceConnected"); 
     AccessibilityServiceInfo info = new AccessibilityServiceInfo(); 
     info.flags = AccessibilityServiceInfo.DEFAULT; 
     info.packageNames = new String[]{"com.android.phone"}; 
     info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED; 
     info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC; 
     setServiceInfo(info); 
    } 
} 

這裏是清單服務聲明:

<service android:name=".UssdService" 
    android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"> 
    <intent-filter> 
     <action android:name="android.accessibilityservice.AccessibilityService" /> 
    </intent-filter> 
    <meta-data android:name="android.accessibilityservice" 
     android:resource="@xml/config_service" /> 
</service> 
+0

如果你想設置單擊事件,然後使用下面的代碼列表列表= nodeInfo.findAccessibilityNodeInfosByText(「發送」); for(AccessibilityNodeInfo node:list){ node.performAction(AccessibilityNodeInfo.ACTION_CLICK); isDialogClose = true; } –

回答

0

對於USSD對話互動,我用下面的代碼。

我用下面的代碼click事件:

List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("Send"); 
for (AccessibilityNodeInfo node : list) { 
    node.performAction(AccessibilityNodeInfo.ACTION_CLICK); 
} 

EditText用下面的代碼爲setText。這是當前焦點所在的setText

AccessibilityNodeInfo nodeInput = nodeInfo.findFocus(AccessibilityNodeInfo.FOCUS_INPUT); 
Bundle bundle = new Bundle();   
bundle.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,pMPIN); 
nodeInput.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT,bundle); 
nodeInput.refresh();