我需要仅使用文件名来显示图像,而不是使用资源ID.
ImageView imgView = new ImageView(this);
imgView.setBackgroundResource(R.drawable.img1);
Run Code Online (Sandbox Code Playgroud)
我在drawable文件夹中有图像img1.我希望从文件中显示该图像.
我怎样才能做到这一点?
有谁知道完整的选择文件对话框?也许您可以过滤掉除具有特定扩展名的文件之外的所有文件?
我没有发现任何足够轻量的东西可以很容易地实现我的一个项目.唯一的其他选择似乎是使用OI FileManager的开放意图,但这需要用户已经安装了文件管理器.
如果有人能指出允许用户浏览文件夹并选择文件并返回路径的Dialog,我将不胜感激.
我有一个应用程序,我使用相机捕获视频.我可以获得视频的文件路径,但我需要它作为Uri.
我得到的文件路径:
/storage/emulated/0/DCIM/Camera/20141219_133139.mp4
Run Code Online (Sandbox Code Playgroud)
我需要的是这样的:
content//media/external/video/media/18576.
Run Code Online (Sandbox Code Playgroud)
这是我的代码.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
if (requestCode == CAMERA_CAPTURE_VIDEO_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// video successfully recorded
// preview the recorded video
// selectedImageUri = data.getData();
// Uri selectedImage = data.getData();
previewVideo();
tv1.setText(String.valueOf((fileUri.getPath())));
String bedroom=String.valueOf((fileUri.getPath()));
Intent i = new Intent();
i.putExtra(bhk1.BEDROOM2, bedroom);
setResult(RESULT_OK,i);
btnRecordVideo.setText("ReTake Video");
} else if (resultCode == RESULT_CANCELED) {
// user cancelled recording
Toast.makeText(getApplicationContext(),
"User cancelled video recording", …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来获得Android中任何给定视频的分辨率.它不必与Android中支持的其他格式一起使用,但如果确实如此,它会很棒.如果您不确定Android中支持的格式,请参阅此页面:
http://developer.android.com/guide/appendix/media-formats.html
我认为使用MediaPlayer该类可以做我想做的事情,但这看起来非常愚蠢和低效.而且,我想要一种相对较快的方式.
我的目标是Android 3.0+,如果这有任何区别的话.Honeycomb还支持.mkv文件,虽然直到Android 4.0才正式支持.
video android android-3.0-honeycomb android-4.0-ice-cream-sandwich
例如
真正的路径是mnt/sdcard/image_1.jpg Uri路径是内容:// media/external/images/media/140喜欢这个
Uri photoUri =Uri.parse("content://media/external/images/media/140");
Log.d("selectedphoto",""+photoUri);
selectedImagePath = getPath(photoUri);
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中我将Uri转换为实际路径,但是dnt知道如何将实际路径转换为Uri
我搜索了这个主题并找到了这两个网站:
http://developer.android.com/training/basics/intents/sending.html
我想要做的是从Android应用程序中导出一个文件,并将日历导入谷歌日历应用程序.因此,如果我点击一个按钮,我的应用程序应该发送一个意图,Android应用程序选择器应该出现.然后我希望能够选择谷歌日历并让日历导入ical文件.
到目前为止这是我的代码:
Uri uri = Uri.fromFile(new File(fileName));
//Uri uri = Uri.parse(fileName);
Intent calendarIntent = new Intent(Intent.ACTION_VIEW, uri);
final Intent chooser = Intent.createChooser(calendarIntent, "choose");
...
startActivity(chooser);
Run Code Online (Sandbox Code Playgroud)
我可以使用fileName打开文件,所以这不应该是一个问题(fileName只包含类似"file.ics"的东西).如果我运行此代码,Android应用程序选择器说没有应用程序能够处理此操作.我在Eclipse中使用Google API level 7作为库,我使用Android 4.04部署到Galaxy Nexus设备进行测试.我无法弄清楚我做错了什么.有什么建议?在此先感谢您的帮助!
编辑:
以下代码显示了可供选择的应用列表:
Uri uri = Uri.parse(fileName);
Intent calendarIntent = new Intent(Intent.ACTION_SEND, uri);
calendarIntent.setType("text/calendar");
final Intent chooser = Intent.createChooser(calendarIntent, "choose");
Run Code Online (Sandbox Code Playgroud)
但日历不在此列表中.所以我在手机上下载了文件并尝试打开它.即使这样,只有文本编辑器,但没有日历应用程序出现.所以在我看来,不可能将ical文件导入谷歌日历应用程序.我很高兴被证明是错的......
这个问题实际上是在这里被问到并且应该回答:android获取视频缩略图PATH,而不是Bitmap.
我已经尝试了好几次但却无法上班.我总是得到null返回.对此有何帮助?
编辑: 我现在使用的示例代码:
public static String getVideoThumbnailPath(Context context,
String filePath) {
String thubmnailPath;
String where = Video.Thumbnails.VIDEO_ID
+ " In ( select _id from video where _data =?)";
final String[] VIDEO_THUMBNAIL_TABLE = new String[] { Video.Media._ID, // 0
Video.Media.DATA, // 1
};
Uri videoUri = MediaStore.Video.Thumbnails.getContentUri("external");
Cursor c = context.getContentResolver().query(videoUri,
VIDEO_THUMBNAIL_TABLE, where, new String[] { filePath }, null);
if ((c != null) && c.moveToFirst()) {
thubmnailPath = c.getString(1);
c.close();
Log.i(TAG, "thumb path: " + thubmnailPath);
return thubmnailPath; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用媒体播放器类播放mp3.当我硬编码它的mp3资源时,我希望资源来自一个字符串,而不是直接访问它R.raw.mp3name.
Bundle bundle = getIntent().getExtras();
String Choice= bundle.getString("bundledChoice");
Uri myUri = Uri.parse("R.raw." + Choice);
mPlayer = MediaPlayer.create(activity.this, myUri);
mPlayer.start();
Run Code Online (Sandbox Code Playgroud)
如果我将第二行更改为最后一行mPlayer = MediaPlayer.create(activity.this, R.raw.song)它将起作用,问题是从包中获取的字符串动态创建资源URI.
请指教.
我正在尝试在外部播放器上打开我存储在应用程序中的视频.但我不知道该怎么做.
我的视频位于res/raw文件夹中.此链接用于测试.
public void openVideo(View view) {
String vidAddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(vidAddress));
intent.setDataAndType(Uri.parse(vidAddress), "video/*");
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud) android ×9
java ×2
android-4.0-ice-cream-sandwich ×1
android-file ×1
dialog ×1
export ×1
file ×1
icalendar ×1
imageview ×1
string ×1
thumbnails ×1
uri ×1
video ×1