我已經編寫了一個使用ussd代碼的應用程序。我想發送一個ussd的請求,但我不知道如何獲取數據並將其保存在字符串中。如何獲得來自Android的USSD代碼的響應?
示例代碼:
@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();
}
}
截圖應用:
如何解決我的問題?
您是否找到了解決問題的方法? – gkiko
不,我不...... ...... –
https://code.google.com/p/android/issues/detail?id=57120#c14 – gkiko