android - 将活动结果用于多种用途
问题描述
我需要做两件事:-
- 一种从存储中选择文件
- 其次是请求发送短信的权限。
为此,我需要使用活动结果和活动结果合同。(这是新方法)
如何注册两个不同的合约?(选择文件并请求权限)
1.请求权限:
resultLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()
) {
isGranted: Boolean ->
if (isGranted) {
// Permission is granted. Continue the action or workflow in your
// app.
sendSMS()
} else {
// Explain to the user that the feature is unavailable because the
// features requires a permission that the user has denied. At the
// same time, respect the user's decision. Don't link to system
// settings in an effort to convince the user to change their
// decision.
Toast.makeText(requireContext(), "sms text can't be delivered", Toast.LENGTH_LONG).show()
}
}
2.从存储中读取文件:
resultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { result : Any? ->
Log.d(TAG, "resultLauncher execute")
if (result == null)
{
//Toast.makeText(context, getString(R.string.quiz_resume_error_message), Toast.LENGTH_SHORT).show()
Log.d(TAG, "result is null")
} else if (result is Uri) {
Log.d(TAG, "result is Uri type")
user.resume = File(result.toString())
fab.visibility = View.VISIBLE
/*if (user.resume != null)
Toast.makeText(context, getString(R.string.quiz_resume_message), Toast.LENGTH_SHORT).show()*/
}
我怎样才能把这些放在一起?
谢谢!
解决方案
推荐阅读
- python - Python中sklearn包中的Gaussianmixture有什么问题?
- node.js - 有什么方法可以将 .xlsx 文件导入 nodejs 并使用 mongodb 作为数据库?
- amazon-web-services - 使用 AWS SQS 和 Lambda 作为消费者的优先级队列
- dart - 在颤振的一个列表中加载5个视频
- c# - 具有确切字符数的表单验证
- c# - 如何按名称将现有表单动态添加到集合中
- function - 使用 AutoHotKey 打开任何应用程序的功能错误
- file - Ant 可以从两个目录中删除 _identical_ 文件吗?
- flask - 如何运行 websockets 服务器以及为 HTML 页面提供服务的烧瓶服务器?
- windows - 如何使用融合样式禁用焦点边框和背景 QTreeWidget?