我拼命尝试将捕获的视频发送到服务器。问题是内置相机应用程序给出的 URI 不是真实的文件路径。看起来是这样的/content:/media/external/video/media/19——
如何直接从这种 URI 访问真实路径或数据?
阅读完 android 文档后,我发现它看起来像内容提供者的符号,但我仍然不知道如何获取我需要的数据。请帮忙!!!
提前致谢
我正在写一个能在背景上产生效果的动态壁纸.我希望用户能够从任何系统壁纸和相机照片中选择背景.我想要的是用户能够按下"设置"菜单中的按钮,显示选项列表就像在主屏幕上设置壁纸一样,减去动态壁纸选项.一旦用户导航选择并选择实际图像,我会将其加载到我的画布上.
我该怎么做呢?
我无法在任何地方找到API来获取壁纸列表.
我已经能够使用Intents提出壁纸提供商列表.然后,我获得了一个使用Intents的动态壁纸提供商列表,并从我的第一个列表中删除它们.给我一个不活的壁纸提供商列表.
怎么办?还有其他方法可以做到这一点,我错过了吗?
请帮忙.
我正在预算一个应用程序,它列出了我在列表中使用录像机录制的所有视频.是否有可能在Uri的帮助下创建缩略图而不是字符串???
我当前的代码如下所示,但它不再有效,因为我对构造函数的输入是Uri而不是字符串.
bmThumbnail = ThumbnailUtils.createVideoThumbnail(
(db_results.get(position)), Thumbnails.MICRO_KIND);
imageThumbnail.setImageBitmap(bmThumbnail);
Run Code Online (Sandbox Code Playgroud)
我退回了错误
The method createVideoThumbnail(String, int) in the type ThumbnailUtils is not applicable for the arguments (Uri, int)
Run Code Online (Sandbox Code Playgroud)
感谢您提前的时间.
我正在尝试选择一个视频,选择并显示视频效果很好,但是当我尝试获取视频文件的完整路径时,我得到了错误的路径。
在下面的代码片段中,我尝试获取文件的完整路径:
Uri uri = Uri.parse(url);
File file = new File((uri.getPath()));
Run Code Online (Sandbox Code Playgroud)
然后,当我设置多部分实体文件主体时,我将file.toString().
尝试上传文件时出现以下异常。
03-28 12:43:27.129: W/System.err(6018): java.io.FileNotFoundException: /content:/media/external/video/media/32398: open failed: ENOENT (No such file or directory)
03-28 12:43:27.157: W/System.err(6018): at libcore.io.IoBridge.open(IoBridge.java:416)
03-28 12:43:27.157: W/System.err(6018): at java.io.FileInputStream.<init>(FileInputStream.java:78)
03-28 12:43:27.157: W/System.err(6018): at org.apache.http.entity.mime.content.FileBody.writeTo(FileBody.java:92)
03-28 12:43:27.165: W/System.err(6018): at org.apache.http.entity.mime.HttpMultipart.doWriteTo(HttpMultipart.java:206)
03-28 12:43:27.165: W/System.err(6018): at org.apache.http.entity.mime.HttpMultipart.writeTo(HttpMultipart.java:224)
03-28 12:43:27.169: W/System.err(6018): at org.apache.http.entity.mime.MultipartEntity.writeTo(MultipartEntity.java:183)
03-28 12:43:27.169: W/System.err(6018): at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:97)
03-28 12:43:27.169: W/System.err(6018): at org.apache.http.impl.AbstractHttpClientConnection.sendRequestEntity(AbstractHttpClientConnection.java:162)
Run Code Online (Sandbox Code Playgroud) 我正在尝试从图库中选择图像然后将此图像转换为文件并通过HttpPost发送它,但我总是得到它FileNotFoundException.我的代码:
选择照片
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 1) {
// currImageURI is the global variable I’m using to hold the content:
currImageURI = data.getData();
//Save the currImageUri (URI type) to global variable.
photosHolder.getInstance().setOneIm(currImageURI);
}
}
}
Run Code Online (Sandbox Code Playgroud)
转换照片
// First Try
File myFile = new File((photosHolder.getInstance().getOneIm()).toString());
params.put("visit_report[photos_attributes][0][file]",myFile); **The exception Raised here
// second try
File myFile2 = new File((photosHolder.getInstance().getOneIm()).getPath());
params.put("visit_report[photos_attributes][1][file]",myFile2); ** Also here
Run Code Online (Sandbox Code Playgroud)
在调试时,这些是myFiles Value:
mFile : …Run Code Online (Sandbox Code Playgroud) 我想显示手机的照片库,当用户选择图像然后通知我的应用程序选择的图像,这样我就可以获得图像信息.
是可能的,怎么样?
我的代码是:
1.
File file = new File(Environment.getExternalStorageDirectory(),"myFolder");
Log.d("path", file.toString());
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setDataAndType(Uri.fromFile(file), "*/*");
startActivityForResult(intent,0);
Run Code Online (Sandbox Code Playgroud)
2.
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent FileReturnedIntent) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, FileReturnedIntent);
Run Code Online (Sandbox Code Playgroud)
如何获取文件路径、名称、扩展名?(假设文件为 doc、pdf、csv 格式)
我有一个应用程序,您可以从库中选择图像或设备上的照片文件夹.选定文件的路径存储在Intent中,因此可以在Activities之间传递它们.我通过intent.getDataString()访问路径.
一旦我拥有了所有选定的图像路径,我将它们存储在ArrayList中并将其传递给ImageAdapter,以便在ListView中显示.
我正在设置FileNotFoundException,有没有人有任何想法?
提前致谢
马特.
import java.util.ArrayList;
import uk.co.mobilewebexpert.infowrapsynclibrary.ApplicationObj;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
public class QueuedImagesActivity extends Activity {
private static final String TAG = QueuedImagesActivity.class.getSimpleName();
private ImageAdapter adapter;
private ListView imageList;
ApplicationObj appObj;
Intent[] photos;
String path;
private ArrayList<String> imagePaths= new ArrayList<String>(); // Edit your code here..
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.image_listview);
appObj = (ApplicationObj) getApplication();
boolean includeBeingProcessed = true;
try {
photos = appObj.getQueuedPhotos(includeBeingProcessed); …Run Code Online (Sandbox Code Playgroud) 我一直在尝试从这个应用程序中的图库中获取图像,然后在按钮上单击我要上传到我的PHP服务器.
"selectedImagePath"为null为什么?如果有人有解决方案,请帮助我!提前致谢.
img = (ImageView) findViewById(R.id.ImageView01);
Button browse = (Button) findViewById(R.id.Button01);
browse.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
}
});
Run Code Online (Sandbox Code Playgroud)
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
selectedImageUri = data.getData();
System.out.println(selectedImageUri);
selectedImagePath = getPath(selectedImageUri);//returns as null
System.out.println("Image Path : " + selectedImagePath);
img.setImageURI(selectedImageUri);
}
}
}
Run Code Online (Sandbox Code Playgroud)
public String getPath(Uri uri) {
String[] …Run Code Online (Sandbox Code Playgroud) 我必须按照Android上的代码启动和录音机:
final Intent recordSoundIntent = new Intent
("android.provider.MediaStore.RECORD_SOUND");
String fileName = Environment.getExternalStorageDirectory() +
File.separator + UUID.randomUUID() + ".3gpp";
recordSoundIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new
File(fileName)));
startActivityForResult(Intent.createChooser(recordSoundIntent,
getString(R.string.record_sound_chooser)), INTENT_SOUND_RECORDING);
Run Code Online (Sandbox Code Playgroud)
我的问题如下:
我的文件名(fileName)无效,从我上次测试运行中返回的data.getData()返回的Uri:content:// media/external/audio/media/41.但是,此文件是在我的SD卡上创建的:recording34485.3gpp.如果在创建声音时无法设置自定义位置,则我希望此文件的位置.
我得到了关于活动结果的文件。或者我应该说它的内容 uri 版本。
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK && requestCode==0){
Log.d("uri data",""+data.getData());
selectedFileUri = data.getData();
Run Code Online (Sandbox Code Playgroud)
我的问题是如何通过 okhttp3 方法发送这个文件?
okhttp 3 方法如下
multipart.addFilePart("data[User][user_picture]", selectedFileUri);
Run Code Online (Sandbox Code Playgroud)
感谢您的时间。
android ×13
java ×2
uri ×2
audio ×1
constructor ×1
file ×1
file-upload ×1
loopj ×1
okhttp ×1
okhttp3 ×1
recorder ×1
string ×1
thumbnails ×1