所以我找到了一个会提示用来打开设备库的函数。但是在四处搜索时我找不到任何能够帮助我修改此内容以返回图像路径的内容。他们说了一些关于onActivityResult()的内容,我把它放在void本身上,然后被拒绝。对此有何帮助?r如何修改此函数以返回图像路径?
public void chooser() {
AlertDialog.Builder myDialog
= new AlertDialog.Builder(IPAddress.this);
myDialog.setTitle("Import Menu Images");
LinearLayout layout = new LinearLayout(IPAddress.this);
layout.setOrientation(LinearLayout.VERTICAL);
myDialog.setView(layout);
myDialog.setPositiveButton("Open Folder", new DialogInterface.OnClickListener() {
// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
Intent i = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 1);
}
});
myDialog.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
});
myDialog.show();
}
我想这回选择的图像的路径,然后我会使用该路径复制所述文件并将其保存到我对活动的OnCreate中创建的目录。
另外,我似乎无法能够调试上述功能,当我点击“打开文件夹”按钮,它会给出一个错误说
The application Camera(process.com.android.gallery) has stopped unexpectedly. Please try again.
,我已经试过多次。我甚至在模拟器中添加了前置摄像头。
的功能在这里称为:
Button menu_image = (Button) findViewById(R.id.menu_image);
menu_image.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View arg0) {
chooser();
}
});
所以我想选择器返回一个字符串类型,如果有可能,我会再使用进行文件的复制,然后重命名(?)。
该方法是如何调用的?你想在哪里返回路径? – 2013-02-22 03:41:59
我会发布它被称为sory的地方,请稍等片刻 – 2013-02-22 03:43:33