startActivityForResult()方法的帮助将其发送到我的应用程序。可能吗?以下代码允许用户从我的应用程序导航到Playstore,然后从Office Lens导航。我如何直接将用户导航到Office Lens
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.microsoft.office.officelens"))
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivityForResult(intent, IMAGE_PICK_CODE)
Run Code Online (Sandbox Code Playgroud)好吧,我发现评论很有用,并提出了解决我的第二个问题的方法
val isAppInstalled = appInstalledOrNot("com.microsoft.office.officelens")
if (isAppInstalled)
{
//This intent will help you to launch if the package is already installed
Toast.makeText(this@ScrollingActivity, "Its toast at if!", Toast.LENGTH_SHORT).show()
val LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.microsoft.office.officelens")
startActivityForResult(LaunchIntent, IMAGE_PICK_CODE)
}
else
{
Toast.makeText(this@ScrollingActivity, "else executed!", Toast.LENGTH_SHORT).show()
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.microsoft.office.officelens"))
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivityForResult(intent, IMAGE_PICK_CODE)
}
Run Code Online (Sandbox Code Playgroud)
此功能使您可以检查是否已安装该应用程序
private fun appInstalledOrNot(uri:String):Boolean {
val pm = getPackageManager()
try
{
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES)
return true
}
catch (e:PackageManager.NameNotFoundException) {}
return false
}
Run Code Online (Sandbox Code Playgroud)