- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的课上有这样的东西:
public class Main extends Activity {
private static final int CAMERA_PICK = 1;
private static final int GALLERY_PICK = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button photo = (Button) findViewById(R.id.button);
photo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
createDialog();
}
});
private void createdialog(Activity activity) {
final CharSequence[] items = { "Take shot", "Take from gallery" };
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("Get image");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
if (item == 0) {
takePhoto();
}
if (item == 1) {
choosePhoto();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
protected void choosePhoto() {
// not necessary;
}
protected void takePhoto() {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "myPic"
+ String.valueOf(System.currentTimeMillis()) + ".jpg"));
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
try {
cameraIntent.putExtra("return-data", true);
startActivityForResult(cameraIntent, CAMERA_PICK);
//Doing something with the picture here;
}
} catch (Exception e) {
e.printStackTrace();
}
}
// TODO
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (resultCode) {
case CAMERA_PICK:
break;
case RESULT_OK:
Toast.makeText(Main.this, "Photo selected", Toast.LENGTH_SHORT).show();
break;
}
}
}
如您所见,我正在尝试使用手机的摄像头拍照并稍后在 ImageView 中使用它。问题是我无法触发方法 onActivityResult(...)!当我执行 startActivityForResult(cameraIntent, CAMERA_PICK);我没有办法操纵 RESULT_OK、RESULT_CANCEL 甚至我定义为 CAMERA_PICK 的那个。 onActivityResult(...) 应该完美工作,因为我不明白我做错了什么!
如有任何帮助,我们将不胜感激。
I've already found the problem. I was using an activity group and I didn't realized that the onActivityResult() triggered was the first one of all the activities...
最佳答案
在某些真实设备上从图库中挑选照片时,我遇到了同样的问题。经过大量搜索,我找到了 this .表示可能会触发 Dialog 的 onActivityResult 而不是 Activity 来获取返回值。此问题不会在所有设备上发生。
关于android - 在 Android 上使用相机时,onActivityResult 无法与 RESULT_OK、RESULT_CANCEL 等一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6576399/
我希望能够在使用默认相机玻璃器皿拍摄照片时跟踪图像文件名。这样我就可以在完成后删除它们。我有以下代码: ... Intent intent = new Intent(M
我想用我的相机拍照。我只是暂时需要它们,所以我执行以下操作: private void takePicture() { Intent intent = new Intent(MediaStor
在获取当前位置流时,我使用 SettingsClient 根据当前 LocationRequest 检查是否满足位置设置。目前,我的优先级设置为 HIGH_ACCURACY,这需要不惜一切代价启用 G
我有 2 个 Activity 类和 1 个 Non-Activity 类,它们从传入构造函数的 Context 调用 startActivityForResult()。它看起来是这样的:FirstA
我正在尝试使用 MediaStore.ACTION_IMAGE_CAPTURE Intent 拍摄个人资料照片。 启动 Intent 的代码: Intent cameraIntent = new In
我正在尝试使用 startActivityForResult() 获取拨号器 Intent 的结果 下面是我的拨号器 Intent 代码。 button.setOnClickListe
我是 Java 和 Android 新手,但我有一个应用程序可以从相机拍摄照片并将其保存为文件。我可以启动相机并拍照,但在 onActivityResult 中,resultCode 始终为 RESU
我可能以错误的方式解决了这个问题.. 我正在做的是在没有互联网连接时显示一条警告消息,“确定”按钮会将用户引导至 wifi 设置以打开互联网。当用户在更改(或不更改)互联网设置后返回到应用程序时,我希
我有一个期望用户选择项目的 Activity ,但用户可以选择单击后退按钮而不选择项目。这个“项目选择” Activity 是从 startActivityForResult() 开始的。 我想知道两
我想知道以下问题。在 Android 文档中,他们推荐以下内容: “提示:当您的配置 Activity 首次打开时,将 Activity 结果设置为 RESULT_CANCELED,以及 EXTRA_
首先,这不是过早返回结果代码的常见问题。在这种情况下,只有在画廊中挑选了一个项目后才会返回。 在我的测试用例中,我使用以下代码调用图库: Intent intent = new Intent(); i
我正在构建一个自定义启动器。我已经按照步骤在 Android 文档中提到用于托管 App Widgets 以及浏览默认启动器源代码。但是,当我使用作为 AppWidgetManager.ACTION_
我正在尝试将 Google 云端硬盘应用到我的 Android 应用程序,但我什至无法连接到 Api 客户端。我不知道为什么: 我已经在开发者控制台中为 ~/.android/debug.keysto
我正在启动从图库中挑选图片的 Intent ,但 Intent 总是返回结果代码 RESULT_CANCELED。我尝试了很多不同的代码,但没有任何帮助让我觉得我可能遗漏了一些东西,比如在 Andro
这是我的问题,我的主视图只显示一个按钮,按下此按钮会显示另一个 View 。此 View 只有另一个按钮,当按下此按钮时,当前 View 结束,控件返回上一个 View 。 为了显示我使用 start
我的小部件有一些问题。这是描述: 上下文: 我有一个家庭小部件。 当我添加它时,它会弹出一个配置 Activity ,用于为小部件设置一些参数。 如果我在完成配置Activity之前调用setResu
我一直在搜索 Google 文档和示例代码以及 Stack Overflow 以寻找解决方案,虽然我看到很多人遇到相同的症状,但我没有找到任何对我的具体情况有帮助的东西. 基本上我正在尝试为 Goog
在一种特殊情况下,我一直在努力使用新的 LocationServices.SettingsApi。我已经在 SplashActivity 上编写了用于位置设置的代码(自动打开 GPS 的 Google
我的 Activity 中有以下按钮,可打开图库以选择单个或多个图像,在此下方是 OnActivityResult 函数,返回结果为 RESULT_CANCELLED 用于多张图片,RESULT_OK
当出现分享弹窗时,我在 WhatsApp 上分享内容成功,但仍然返回 RESULT_CANCELLED。当我使用 Gmail 发送电子邮件时,结果相同。 使用 startActivityForResu
我是一名优秀的程序员,十分优秀!