我正在捕捉图像并将其设置为图像视图.
public void captureImage() {
Intent intentCamera = new Intent("android.media.action.IMAGE_CAPTURE");
File filePhoto = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
imageUri = Uri.fromFile(filePhoto);
MyApplicationGlobal.imageUri = imageUri.getPath();
intentCamera.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intentCamera, TAKE_PICTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intentFromCamera) {
super.onActivityResult(requestCode, resultCode, intentFromCamera);
if (resultCode == RESULT_OK && requestCode == TAKE_PICTURE) {
if (intentFromCamera != null) {
Bundle extras = intentFromCamera.getExtras();
if (extras.containsKey("data")) {
bitmap = (Bitmap) extras.get("data");
}
else {
bitmap = getBitmapFromUri();
}
}
else {
bitmap = getBitmapFromUri();
}
// …Run Code Online (Sandbox Code Playgroud) 在Android 4.4(KitKat)中访问新图库之前,我使用此方法在SD卡上获得了真正的路径:
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
startManagingCursor(cursor);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
Run Code Online (Sandbox Code Playgroud)
现在,Intent.ACTION_GET_CONTENT返回不同的数据:
之前:
content://media/external/images/media/62
Run Code Online (Sandbox Code Playgroud)
现在:
content://com.android.providers.media.documents/document/image:62
Run Code Online (Sandbox Code Playgroud)
我怎么能设法获得SD卡上的真实路径?
我正试图从画廊获取图像.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select picture"), resultCode );
Run Code Online (Sandbox Code Playgroud)
从这个活动返回后,我有一个包含Uri的数据.看起来像:
content://media/external/images/1
Run Code Online (Sandbox Code Playgroud)
如何将此路径转换为真实路径(就像' /sdcard/image.png')?
谢谢
我正在使用第三方文件管理器从文件系统中选择一个文件(在我的情况下为PDF).
这是我启动活动的方式:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(getString(R.string.app_pdf_mime_type));
intent.addCategory(Intent.CATEGORY_OPENABLE);
String chooserName = getString(R.string.Browse);
Intent chooser = Intent.createChooser(intent, chooserName);
startActivityForResult(chooser, ActivityRequests.BROWSE);
Run Code Online (Sandbox Code Playgroud)
这就是我所拥有的onActivityResult:
Uri uri = data.getData();
if (uri != null) {
if (uri.toString().startsWith("file:")) {
fileName = uri.getPath();
} else { // uri.startsWith("content:")
Cursor c = getContentResolver().query(uri, null, null, null, null);
if (c != null && c.moveToFirst()) {
int id = c.getColumnIndex(Images.Media.DATA);
if (id != -1) {
fileName = c.getString(id);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
代码片段来自Open Intents文件管理器说明,网址为: …
我正在尝试访问用户设备上的媒体文件(音乐)来播放它们; 一个简单的"你好世界" - 音乐播放器应用程序.
我已经按照一些教程,他们基本上给出了相同的代码.但它不起作用; 它一直在崩溃并告诉我:
error.....
Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=27696, uid=10059 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
....
Run Code Online (Sandbox Code Playgroud)
现在,这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="slimsimapps.troff" >
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
这是我的Java方法:
public void initialize() {
ContentResolver contentResolver = getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = contentResolver.query(uri, null, null, null, null); …Run Code Online (Sandbox Code Playgroud) java android audio-player android-music-player android-external-storage
我试图FileInputStream在用户从图片库中选择的图像上获取一个对象.这是由URI返回的androidandroid.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI
内容://媒体/外部/图像/媒体/ 3
当我尝试从这个对象构造一个java URI对象时,我得到一个IllegalArgumentException,其中包含URI中的异常描述Expected file scheme:content:// media/external/images/media/3而android URI将该方案显示为内容
从未找到原始问题的解决方案.但是如果你想要图片库中图像的字节流,这段代码就可以做到.
content://media/external/images/media/3
Run Code Online (Sandbox Code Playgroud) 我想知道getContentResolver()调用的上下文?
我有一个这样的场景:
我有一个活动A,它调用myFunc()B类方法而不是活动.
所以,在BI类中必须使用getContentResolver().我直接打电话getContentResolver().它显示错误.然后我myFunc(Acitivy act)从活动中调用并调用 act.getContentResolver()它解决了我的问题.这是唯一的调用方式getContentResolver(),这意味着它可以在活动的上下文中使用,也可以单独使用.
我正在尝试将galery中的照片添加到a ImageView但是我收到此错误:
java.lang.RuntimeException:将结果ResultInfo {who = null,request = 1,result = -1,data = Intent {dat = content:// media/external/images/media/1}}传递给activity {hotMetter. pack/hotMetter.pack.GetPhoto}:java.lang.NullPointerException
这是我的代码:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
}
Bitmap bitmap=null;
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == Activity.RESULT_OK)
{
if (requestCode == SELECT_PICTURE)
{
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
tv.setText(selectedImagePath);
img.setImageURI(selectedImageUri);
}
}
public String getPath(Uri uri)
{
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, …Run Code Online (Sandbox Code Playgroud) 在短版 - org.apache...MultipartEntity已被弃用,它的升级MultipartEntityBuilder,出现在我们的在线论坛代表性不足.我们来解决这个问题.如何注册回调,因此我的(Android)应用可以在上传文件时显示进度条?
在长版 -这里的"失踪污垢简单的例子"的MultipartEntityBuilder:
public static void postFile(String fileName) throws Exception {
// Based on: https://stackoverflow.com/questions/2017414/post-multipart-request-with-android-sdk
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(SERVER + "uploadFile");
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addPart("file", new FileBody(new File(fileName)));
builder.addTextBody("userName", userName);
builder.addTextBody("password", password);
builder.addTextBody("macAddress", macAddress);
post.setEntity(builder.build());
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
// response.getStatusLine(); // CONSIDER Detect server complaints
entity.consumeContent();
client.getConnectionManager().shutdown();
} // FIXME Hook up a progress bar!
Run Code Online (Sandbox Code Playgroud)
我们需要解决这个问题FIXME.(额外的好处是可中断上传.)但是(请纠正我是否我错了),所有在线示例似乎都不尽如人意. …
请在下面找到我的代码.我需要获取用户从SDcard中选择的pdf文档的文件路径.问题是URI.getPath()返回:
/file:///mnt/sdcard/my%20Report.pdf/my Report.pdf
Run Code Online (Sandbox Code Playgroud)
正确的道路是:
/sdcard/my Report.pdf
Run Code Online (Sandbox Code Playgroud)
请注意我在stackoverflow上搜索但是找到了获取图像或视频的filePath的示例,在PDF的情况下没有如何获取文件路径的示例?
我的代码,不是所有代码,只有pdf部分:
public void openPDF(View v)
{
Intent intent = new Intent();
//intent.setType("pdf/*");
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Pdf"), SELECT_PDF_DIALOG);
}
public void onActivityResult(int requestCode, int resultCode, Intent result)
{
if (resultCode == RESULT_OK)
{
if (requestCode == SELECT_PDF_DIALOG)
{
Uri data = result.getData();
if(data.getLastPathSegment().endsWith("pdf"))
{
String pdfPath = data.getPath();
}
else
{
CommonMethods.ShowMessageBox(CraneTrackActivity.this, "Invalid file type");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我如何从URI获取正确的路径?
android ×10
uri ×3
audio-player ×1
camera ×1
file-upload ×1
filepath ×1
gallery ×1
getimagedata ×1
http ×1
image ×1
imageview ×1
java ×1
path ×1
pdf ×1
rotation ×1