我如何使用"#"在Android编程中的Uri.parse

时间:2016-11-28 09:34:26

标签: java android

我正在尝试在我的代码中解析*123#但是无论何时我运行该程序,#似乎永远不会出现:

protected void makeCall(){
    Log.i("make call", "");

    Intent phoneIntent = new Intent(Intent.ACTION_CALL);
    phoneIntent.setData(Uri.parse("tel: *123#"));

    try{
        startActivity(phoneIntent);
        finish();
        Log.i("finish making call...", "");
    }catch (android.content.ActivityNotFoundException ex){
        Toast.makeText(MainActivity.this,"call failed",Toast.LENGTH_LONG).show();
    }
} 

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

protected void makeCall(){
    Log.i("make call", "");

    Intent phoneIntent = new Intent(Intent.ACTION_CALL);
    phoneIntent.setData(Uri.parse("tel:*123#"));

    try{
        startActivity(phoneIntent);
       // finish();
        Log.i("finish making call...", "");
    }catch (android.content.ActivityNotFoundException ex){
        Toast.makeText(MainActivity.this,"call failed",Toast.LENGTH_LONG).show();
    }
} 

还必须在Manifest中添加<uses-permission android:name="android.permission.CALL_PHONE" />