tblTreePhoto.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(getParent());
alertDialog.setTitle("Select Photo");
alertDialog.setPositiveButton("Take Photo", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface arg0, int arg1)
{
if(Tree_Image.count<3)
{
Intent i1 = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File out = Environment.getExternalStorageDirectory();
out = new File(out, "newImage.jpg");
i1.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out));
getParent().startActivityForResult(i1, 10);
}
else
{
Toast.makeText(getApplicationContext(), "You can not add more than 2 photos" , 1).show();
}
}
});
alertDialog.setNeutralButton("Gallery", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
if(Tree_Image.count<3)
{
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
getParent().startActivityForResult(Intent.createChooser(intent,"Select Picture"),1);
}
else
{
Toast.makeText(getApplicationContext(), "You can not add more than 2 photos" , 1).show();
}
}
});
alertDialog.setNegativeButton("View Selected Photos", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface arg0, int arg1)
{
Intent i = new Intent(getParent(),Show_Selected_Images.class);
//i.putExtra("cqname", client_name.getText().toString());
startActivity(i);
}
});
alertDialog.show();
}
});
这是我的onActivityResult方法:-
protected void onActivityResult(int requestCode, int resultcode, Intent intent)
{
int orientation =0;
Log.d("result ","code uis"+resultcode);
super.onActivityResult(requestCode, resultcode, intent);
if (requestCode == 1)
{
if (intent != null && resultcode == RESULT_OK)
{
Uri selectedImage = intent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
Log.v("log","filePath is : "+filePath);
cursor.close();
try
{
ExifInterface exif = new ExifInterface(filePath);
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
//Toast.makeText(getApplicationContext(), ""+orientation, 1).show();
Log.v("log", "ort is "+orientation);
}
catch (IOException e)
{
e.printStackTrace();
}
if(bmp != null && !bmp.isRecycled())
{
bmp = null;
}
File f = new File(filePath);
bmp = decodeFile(f,400,400);
if (orientation==6)
{
Matrix matrix = new Matrix();
matrix.postRotate(90);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
else if (orientation==8)
{
Matrix matrix = new Matrix();
matrix.postRotate(270);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
else if (orientation==3)
{
Matrix matrix = new Matrix();
matrix.postRotate(180);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
Log.v("log", "before width is "+bmp.getWidth() + " and height is "+bmp.getHeight());
bt=Bitmap.createScaledBitmap(bmp,320, 300, false);
// Bitmap bt_thumb = Bitmap.createScaledBitmap(bmp, 70, 70, false);
Intent i = new Intent(Tree_Assessmnt_Tree.this,Tree_Image.class);
i.putExtra("userid", uid);
// TabGroupActivity parentActivity = (TabGroupActivity) getParent();
startActivity(i);
}
else
{
Log.v("log", "Photopicker canceled");
}
}
else if (requestCode == 10)
{
File out = new File(Environment.getExternalStorageDirectory(), "newImage.jpg");
if(!out.exists())
{
Log.v("log", "file not found");
Toast.makeText(getBaseContext(),"Error while capturing image", Toast.LENGTH_LONG).show();
return;
}
Log.v("log", "file "+out.getAbsolutePath());
File f = new File(out.getAbsolutePath());
try
{
ExifInterface exif = new ExifInterface(out.getAbsolutePath());
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
//Toast.makeText(getApplicationContext(), ""+orientation, 1).show();
Log.v("log", "ort is "+orientation);
}
catch (IOException e)
{
e.printStackTrace();
}
Bitmap photo =decodeFile(f,400,400);
if (orientation==6)
{
Matrix matrix = new Matrix();
matrix.postRotate(90);
photo = Bitmap.createBitmap(photo, 0, 0, photo.getWidth(), photo.getHeight(), matrix, true);
}
else if (orientation==8)
{
Matrix matrix = new Matrix();
matrix.postRotate(270);
photo = Bitmap.createBitmap(photo, 0, 0, photo.getWidth(), photo.getHeight(), matrix, true);
}
else if (orientation==3)
{
Matrix matrix = new Matrix();
matrix.postRotate(180);
photo = Bitmap.createBitmap(photo, 0, 0, photo.getWidth(), photo.getHeight(), matrix, true);
}
//Bitmap photo = (Bitmap) intent.getExtras().get("data");
//bt=Bitmap.createScaledBitmap(photo, 380, 520, false);
bt=photo;
// bt=Bitmap.createScaledBitmap(photo,320, 300, false);
// Log.v("log", "before width is "+bt.getWidth() + " and height is "+bt.getHeight());
/* gamePic.setBackgroundResource(0);
gamePic.setImageBitmap(photo);*/
//txtPhoto.setText(""+DrawOnImage_Activity.count);
Intent i = new Intent(Tree_Assessmnt_Tree.this,Tree_Image.class);
i.putExtra("userid", uid);
startActivity(i);
}
else if(requestCode==6)
{
if (intent == null)
{
Log.v("log", "Null data, but RESULT_OK, from image picker!");
Toast t = Toast.makeText(this, "No Photo Slected",Toast.LENGTH_SHORT);
t.show();
return;
}
}
}
另一种做法是这样的。
:)
我一直在为android开发一个应用程序,它利用了android可比性库(android-support-v4)。在SDK 20之前,我能够在清单中使用以下< code>uses-sdk条目编译我的应用程序。 我的所有为结果启动活动的片段都正确地收到了结果。 有一天(在我更新到SDK 20之前),我在修复lint问题,并根据lint标志的请求将< code > Android:targetSdkV
我创建了一个应用程序来显示。但是,当我启动应用程序在模拟器关闭说。我在网上搜索,但找不到任何解决方案。我的代码activity_main.xml 美娜ctivity.java 我已经为Tab1、Tab2和Tab3创建了单独的. java文件。 Logcat是 06-01 01:40:35.429 1847-1847/com。realtech。6月1日带dalvikvm的标签﹕ threadid=1
我正试图拍摄一张照片并将照片发送到服务器,但目前我没有进入onActivityResult,也不知道发生了什么 代码如下: 我可以预览相机,但在android照片上的点击没有击中activiyt结果上的log.d,有什么提示吗? logcat:
问题内容: 我知道以下代码应在Android中使用以下代码显示和隐藏一个微小的圆形进度条: 问题是我正在使用TabHost,并且需要能够通过“子”活动之一来执行此操作。我有什么办法可以做到这一点? 我在intarwebs上发现了这个问题,但是如您所见,它没有得到回答。 问题答案: 我找到了答案。在您的父活动中,执行 任何操作 之前,需要进行requestWindowFeature调用,然后在子活动
我在google上搜索onactivityresult()是不推荐的。但我的问题没有解决。下面是片段的代码
我是一个新的android和有以下查询。 我正在建立一个应用程序,其中包含两个活动第一和第二,发送消息给对方。“第一个”向“第二个”发送消息,然后“第二个”启动,显示接收到的消息,并向“第一个”发回消息。最后,首先显示收到的消息。 在第一个活动中,我必须使用startActivityForResult启动第二个活动,因为我需要返回响应。 谢了! PS-我已经尝试删除语句-if(resultCode