在Android中,可以使用'Intent.ACTION_VIEW'来打开应用内的Activity或者外部的URL。以下是在应用内打开'Intent.ACTION_VIEW'的一些示例代码:

  1. 在应用内打开另一个Activity:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, AnotherActivity.class);
startActivity(intent);
  1. 在应用内打开外部的URL:
String url = 'https://www.example.com';
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
  1. 在应用内打开电话拨号界面:
String phoneNumber = 'tel:1234567890';
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(phoneNumber));
startActivity(intent);
  1. 在应用内打开地图应用:
String location = 'geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+California';
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(location));
startActivity(intent);

请注意,如果要打开外部的URL或者其他应用的Activity,需要先检查是否有相应的应用或者权限可用。可以使用PackageManager来检查是否存在可处理的应用:

PackageManager packageManager = getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
    startActivity(intent);
} else {
    Toast.makeText(this, 'No application available to handle this request', Toast.LENGTH_SHORT).show();
}
Android Intent.ACTION_VIEW: 应用内打开Activity和URL

原文地址: https://www.cveoy.top/t/topic/qkaL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录