什么是从一个转换的最简单的方法file: android.net.Uri,以一个File在Android的?
尝试以下但它不起作用:
final File file = new File(Environment.getExternalStorageDirectory(), "read.me");
Uri uri = Uri.fromFile(file);
File auxFile = new File(uri.toString());
assertEquals(file.getAbsolutePath(), auxFile.getAbsolutePath());
Run Code Online (Sandbox Code Playgroud) 我有一个像下面的邮递员的形象.如何在Retrofit 2中做同样的事情.
我已经宣布了这样的界面.
@Multipart
@POST("/api/Pharmarcy/UploadImage")
Call<ResponseBody> uploadPrescriptionImage(
@Query("accessToken") String token,
@Query("pharmarcyRequestId") int pharmacyRequestedId,
@Part MultipartBody.Part image);
Run Code Online (Sandbox Code Playgroud) 我正在开发一个VideoPlayer.我将已URI启动的意图转换为字符串,它给了我content://media/external......但我需要得到真正的道路.
例如: /storage/extSdcard.....
我该怎么做呢?
如果需要,这是我的代码:
videoURI = getIntent().getData();
vv.setVideoURI(videoURI);
videoName = videoURI.toString();
tvTitle.setText(videoName);
Run Code Online (Sandbox Code Playgroud) 我在 Kotlin 中为 flutter 应用程序编写了一个功能,可以将媒体文件直接从 Android 手机图库共享到应用程序。
在我测试过的许多设备上运行良好,例如 Realme 3 Pro、Oneplus 6t、三星 m40。
但是,在Asus Zenfone Max Pro M2共享任何媒体文件时,都会收到奇怪且不完整的信息URI&path
来自 Kotlin 代码的日志
D/URI =====(26032) : content://com.android.providers.downloads.documents/document/624
D/路径 =====(26032): /document/624
Kotlin 代码
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
this.binding = binding
binding.addOnNewIntentListener(this)
handleIntent(binding.activity.intent, true)
}
----------------------------------------------------------------------
private fun handleIntent(intent: Intent, initial: Boolean) {
when {
(intent.type?.startsWith("text") != true)
&& (intent.action == Intent.ACTION_SEND
|| intent.action == Intent.ACTION_SEND_MULTIPLE) -> { // Sharing images or videos
val value = getMediaUris(intent)
if …Run Code Online (Sandbox Code Playgroud) 我有一个屏幕,在按钮上单击我打开文件选择器,然后我选择一个名为"Test.jpg"的文件进行进一步操作.我使用以下代码来获取该文件的名称.
Uri uri = data.getData();
File file = new File(uri.getPath());
String fileName = file.getName();
Run Code Online (Sandbox Code Playgroud)
以下是调试器的结果
file.getName() => 167522
file.toString() => /external/images/media/167522
Run Code Online (Sandbox Code Playgroud)
我想把Test.jpg作为我的文件名.请告诉我我的代码有什么问题.
我知道有很多关于这个确切主题的问题,但是在花了两天时间阅读并尝试它们后,没有一个能够解决我的问题.
这是我的代码:
我发起了ACTION_GET_CONTENT我的onCreate()
Intent selectIntent = new Intent(Intent.ACTION_GET_CONTENT);
selectIntent.setType("audio/*");
startActivityForResult(selectIntent, AUDIO_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)
检索Uri进入onActivityResult()
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == AUDIO_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
if ((data != null) && (data.getData() != null)) {
audio = data.getData();
}
}
}
Run Code Online (Sandbox Code Playgroud)
传递Uri给另一个活动并检索它
Intent debugIntent = new Intent(this, Debug.class);
Bundle bundle = new Bundle();
bundle.putString("audio", audio.toString());
debugIntent.putExtras(bundle);
startActivity(debugIntent);
Intent intent = this.getIntent();
Bundle bundle = …Run Code Online (Sandbox Code Playgroud) 我正在使用android应用,需要将带有文件的请求发布到服务器。我正在retrofit这样做,我也要Multipartapi请求。然后我用它Intent.createChooser来选择文件。
当我enqueue拨打服务电话时,问题就来了。在onFailure我得到这个错误:
E / Upload errorrrrrr :: / document / image:77317(无此文件或目录)
但是,这是我在以下位置获得的uri和文件路径onActivityResult:
uri: content://com.android.providers.media.documents/document/image%3A77317
路径: /document/image:77317
我把权限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera2.full" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:name="android.hardware.camera.any"
android:required="true" />
Run Code Online (Sandbox Code Playgroud)
@Multipart
@POST("upload_document")
Call<UploadDocuments> uploadDocuments(
@Header("Authorization") String authorization,
@Part MultipartBody.Part document_name,
@Part("document_type") RequestBody document_type,
@Part("fk_id") RequestBody fk_id,
@Part("type") RequestBody type,
@Part("certificate_name") RequestBody certificate_name,
@Part("certificate_description") RequestBody certificate_description,
@Part("notes") RequestBody notes);
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?谢谢 …