gpt4 book ai didi

java - 如何从Intent接收文件路径

转载 作者:行者123 更新时间:2023-12-02 01:42:06 27 4
gpt4 key购买 nike

在我的应用程序中,我有一个文本编辑器,其中包含我的应用程序要处理的文件的路径。我有一个浏览按钮,以便用户可以选择文件。选择文本后,编辑应包含路径/文件信息。在按钮的 onClick 方法中,我有以下代码:

 Intent intent = new Intent( Intent.ACTION_GET_CONTENT ); 
intent.setType ( "*/*" );
startActivity ( Intent.createChooser ( intent, "Select a file" ) );

用户完成后如何获取Uri?

最佳答案

startActivityForResult()dev guide ,置顶推荐Android docs on Intents

Starting an activity

An Activity represents a single screen in an app. You can start a new instance of an > Activity by passing an Intent to startActivity(). The Intent describes the activity to start and carries any necessary data.

If you want to receive a result from the activity when it finishes, call startActivityForResult(). Your activity receives the result as a separate Intent object in your activity's onActivityResult() callback. For more information, see the Activities guide.

关于java - 如何从Intent接收文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54320094/

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