Android显式Intent与隐式Intent的使用详解

  public class ActionUrlActivity extends AppCompatActivity implements View.OnClickListener {

  @Override

  protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_action_url);

  findViewById(R.id.btn_dial).setOnClickListener(this);

  findViewById(R.id.btn_sms).setOnClickListener(this);

  findViewById(R.id.btn_my).setOnClickListener(this);

  }

  @Override

  public void onClick(View view) {

  String phoneNo = "12345";

  Intent intent = new Intent();

  switch (view.getId()){

  case R.id.btn_dial:

  //设置意图动作为准备拨号

  intent.setAction(Intent.ACTION_DIAL);

  Uri uri = Uri.parse("tel:"+phoneNo);

  intent.setData(uri);

  startActivity(intent);

  break;

  case R.id.btn_sms:

  //设置意图动作为发短信

  intent.setAction(Intent.ACTION_SENDTO);

  Uri uri2 = Uri.parse("smsto:"+phoneNo);

  intent.setData(uri2);

  startActivity(intent);

  break;

  case R.id.btn_my:

  intent.setAction("android.intent.action.NING");

  intent.addCategory(Intent.CATEGORY_DEFAULT);

  startActivity(intent);

  break;

  }

  }

  }