- 我想添加功能供用户从Microsoft Office镜头中选择PDF,并在
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)
我发现评论很有用,并提出了解决我的第二个问题
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)
}
此功能使您可以检查应用程序是否已安装
private fun appInstalledOrNot(uri:String):Boolean {
val pm = getPackageManager()
try
{
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES)
return true
}
catch (e:PackageManager.NameNotFoundException) {}
return false
}