[英]how to get my android USSD program to work
我正在構建一個簡單的撥號程序來幫助我檢查我的帳戶余額,但是由於某些未知原因,我遇到了一些錯誤,我在xml上有一個按鈕,將其onclick元素設置為sendMessage1,但是在我的代碼中使用phoneNum [ 1]告訴我不能拒絕符號phoneNum [1]。 這是我的代碼
/**Called when the user clicks the Send button */
public void sendMessage1(View view){
//example phoneNum[1] = "*556";
String encodedHarsh = Uri.encode("#");
startActivity(new Intent
("android.intent.action.DIAL",
Uri.parse("tel:"+ phoneNum[1]+ encodedHarsh)));
//Do something in response to button
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mtn);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_mtn, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
您必須這樣做:
String encodedHarsh = "*" + "556" + Uri.encode("#");
startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + encodedHarsh)));
注意,不要忘記在清單上添加uses-permisions
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.