- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用相机或图库为我的应用拍照。但有时在单击相机中的图像然后切换到图库后,图库会崩溃。
代码如下:
case R.id.etUploadImage:
Log.d(TAG, " add photo");
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
Toast.makeText(getApplicationContext(), "sdcard not mounted",
Toast.LENGTH_SHORT).show();
break;
}
AlertDialog.Builder photoDialog = new AlertDialog.Builder(this);
photoDialog
.setTitle("Photo source")
.setCancelable(true)
.setPositiveButton("Open Gallery",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
startActivityForResult(
new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI),
54);
}
})
.setNegativeButton("Open Camera",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
//String fileName = "temp.jpg";
Date date = new Date();
DateFormat df = new SimpleDateFormat("-mm-ss");
String newPicFile = "Bild"+ df.format(date) + ".jpg";
String outPath = "/sdcard/" + newPicFile;
File outFile = new File(outPath);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE,
outFile.getAbsolutePath());
mCapturedImageURI = getContentResolver()
.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
Intent intent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
mCapturedImageURI);
startActivityForResult(intent, 96);
}
});
photoDialog.show();
break;
}
onActivityResult() 是:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 54 && resultCode == RESULT_OK) {
if(data !=null){
fileName = getRealPathFromURI(data.getData());
mUploadImage.setText(getStringNameFromRealPath((String) fileName));
} else {
Toast.makeText(getApplicationContext(),"Please select another image.", Toast.LENGTH_SHORT).show();
}
} else if (requestCode == 96 && resultCode != 0) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(mCapturedImageURI, projection, null,
null, null);
int column_index_data = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
fileName = cursor.getString(column_index_data);
String s[] = fileName.split("/");
mUploadImage.setText(s[s.length - 1]);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCapturedImageURI));
}
}
是什么导致画廊崩溃。请帮助我。
最佳答案
所以,经过多次尝试后,我找到了适合我的解决方案..
要打开相册或相机:-
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
Toast.makeText(getApplicationContext(), "sdcard not mounted",
Toast.LENGTH_SHORT).show();
break;
}
AlertDialog.Builder photoDialog = new AlertDialog.Builder(this);
photoDialog
.setTitle("Photo source")
.setCancelable(true)
.setPositiveButton("Open Gallery",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
startActivityForResult(
new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI),
54);
}
})
.setNegativeButton("Open Camera",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
int apiLevel = Integer.parseInt(Build.VERSION.SDK);
if(apiLevel < 11) {
try{
//String fileName = "temp.jpg";
Calendar c = Calendar.getInstance();
CAPTURE_TITLE = "si_"+c.getTimeInMillis()+".jpg";
File file = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera", CAPTURE_TITLE);
Uri ImageURI = Uri.fromFile(file);
Intent intent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
ImageURI );
startActivityForResult(intent, 99);
}
catch(Exception e)
{
LogCreator lg = new LogCreator();
lg.writeBarcodeToFile("Image exc1", e.toString());
}
}
else{
//String fileName = "temp.jpg";
Date date = new Date();
DateFormat df = new SimpleDateFormat("-mm-ss");
String newPicFile = "Bild"+ df.format(date) + ".jpg";
String outPath = "/sdcard/" + newPicFile;
File outFile = new File(outPath);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE,
outFile.getAbsolutePath());
mCapturedImageURI = getContentResolver()
.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
Intent intent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
mCapturedImageURI);
startActivityForResult(intent, 96);
}
}
});
photoDialog.show();
现在是 onActivityResult()
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 54 && resultCode == RESULT_OK) {
if(data !=null){
fileName = getRealPathFromURI(data.getData());
mUploadImage.setText(getStringNameFromRealPath((String) fileName));
} else {
Toast.makeText(getApplicationContext(),"Please select another image.", Toast.LENGTH_SHORT).show();
}
}
else if (requestCode == 99 && resultCode != 0) {
try {
File file = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera", CAPTURE_TITLE);
fileName = Environment.getExternalStorageDirectory() + "/DCIM/Camera/"+CAPTURE_TITLE;
Uri imgUri = Uri.fromFile(file);
//new GetThumbnail().execute(imgUri);
mUploadImage.setText(CAPTURE_TITLE);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if (requestCode == 96 && resultCode != 0) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(mCapturedImageURI, projection, null,
null, null);
int column_index_data = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
fileName = cursor.getString(column_index_data);
String s[] = fileName.split("/");
mUploadImage.setText(s[s.length - 1]);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCapturedImageURI));
}
}
这些是我用来获取路径的方法:-
/*
* Returns image real path.
*/
private String getRealPathFromURI(final Uri contentUri) {
final String[] proj = { MediaStore.Images.Media.DATA };
@SuppressWarnings("deprecation")
final Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
/*
* Cuts selected file name from real path to show in screen.
*/
private String getStringNameFromRealPath(final String bucketName) {
return bucketName.lastIndexOf('/') > 0 ? bucketName
.substring(bucketName.lastIndexOf('/') + 1) : bucketName;
}
希望对您有所帮助。
关于android - 图库(进程 com.cooliris.media)意外停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14038275/
当我想用这个名为 Asfbin 的神奇工具拆分教程视频文件( .wmv )时,查看了媒体播放器中的所有设置,但徒劳地找不到一个... 有没有办法用milliseconds设置windows media
在我的应用程序API级别targetSdkVersion 23中,我添加了以下权限:
出于某种原因,当我发送电子邮件时,我的媒体查询没有应用。我将它从 Outlook 2007 发送到 gmail 并使用 iphone 4s 查看它。我试过使用更简单的@media 查询规则(即仅更改字
我看了一本学习python编程的书,它显示了代码: import media 所以我从链接http://pragprog.com/titles/gwpy/source_code 下载了gwpy-cod
我正在尝试使用一个小的 from,只有 3 个元素。这是我正在使用的,有人可以让我知道我哪里出错了吗?我已尝试同时使用最小宽度和最大宽度,但似乎没有任何效果。 html,body{margin:0p
要修复的网站问题: 我想弄清楚为什么我的一些@media 查询是重叠的。如果您查看我的代码,您会看到 @media 查询被标记为每个设备维度。 @media SCREEN SIZE: MASSIVE
我正在编辑一个预先存在的样式表。它目前有 0-319px 和 320-479px 的@media 部分,以及其他一些用于更大屏幕的部分。我正在尝试添加特定于 iPhone 的样式。但是,我的iphon
我读到在其他@media 查询中嵌套@media 查询在CSS3 中是完全有效的。 但是,我通过 CSS 验证器收到以下解析错误: @media screen and (max-width: 768p
我面临的情况是,对于我的一个类(class),@media 查询只是没有被读取,相反,即使 @media 标准正在被读取,类也没有围绕 @media 查询被读取的情况遇见了。 这是代码: @media
如果我从 android webrtc SDK(由 antmedia 提供)流式传输到 Ant Media 的社区版,则保存的最终视频会出现拉伸(stretch)(以手机纵向模式拍摄)。 Check
我想知道 Mobicent Media 服务器如何使用 URL 播放音频的详细信息?它在哪种方法中使用 URL 进行流式传输。对于本地存储,我了解但对于远程存储(URL),我不知道它是如何工作的。我在
简单是辉煌的关键。 我看到了 @media print 和 @media screen 标签背后的一些意义。但是将 @media screen 与(@media all 而不是打印)进行比较让我感到困
我有以下 sass: .branded @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (m
我都试过了,得到的结果相似。一直找不到答案。 最佳答案 开头和结尾的斜杠分别对匹配的内容添加了限制。 media:没有斜线,匹配当前目录和所有子目录下的文件和目录。 media/:尾部加斜杠表示只匹配
我正在尝试让 Enquire.js 为旧版浏览器工作。我正在使用文档中的深度支持方法: Modernizr.load([ { test: window.matchMedia,
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
我希望将 H264 视频流式传输到 Windows Phone 8 应用程序。 那么我该如何使用 ShardDX 呢? (或者可能来自媒体基金会的 native 功能)。 我找到了用于播放视频的 Me
我想使用 cordova 录制用户的音频。在研究中,我发现了两个似乎可以完成这项工作的插件。第一media plugin及其他media capture plugin .现在我的问题是我可以从两个插件
我正在尝试弄清楚如何构建我的 CSS 文件(现在已经很多了),我想知道拥有以下内容之间是否有任何实际区别: 或拥有: @media print { definitions } 我是从浏览器的
这个问题在这里已经有了答案: Media=All vs Media=Screen (2 个答案) 关闭 8 年前。
我是一名优秀的程序员,十分优秀!