gpt4 book ai didi

android - 如何启动允许用户从 office lens 中选择 pdf 并接收它的 Activity

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:34:43 25 4
gpt4 key购买 nike

  1. 我想添加功能,让用户可以通过 startActivityForResult() 方法从 microsoft office lens 中选择 pdf 并将其发送到我的应用程序。可能吗?
  2. 以下代码允许用户从我的应用程序导航到 playstore,然后导航到 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
}

关于android - 如何启动允许用户从 office lens 中选择 pdf 并接收它的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55044173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com