I am trying to select image from gallery in my app and for that I have written the code to pick image from gallery. But when I try to define the onActivityResult(int requestCode, int resultCode, Intent data)
I am getting the error
onActivityResult(int requestCode, int resultCode, Intent data) in com.example.kmi_dev.fbloginsample clashes with onActivityResult(int requestCode, int resultCode, Intent data) in android.app.Fragment
How should I define onActivityResult
.
Here is the code snippet
public class MyAccount extends Fragment {
private Button button;
private Button button1;
private Button remove;
private Button change;
private EditText editName;
private EditText editGender;
private EditText editAge;
private EditText editCountry;
private EditText editDesccription;
private EditText editSports;
private EditText editFood;
private String apikey;
private ImageView add;
private static int RESULT_LOAD_IMAGE = 1;
String val = null, imgpath=null;
// Session Manager Class
SessionManager session;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Session class instance
session = new SessionManager(getActivity().getApplicationContext());
// get user data from session
HashMap<String, String> user = session.getUserDetails();
// apikey
apikey = user.get(SessionManager.KEY_api);
final LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.my_account_a, null);
button = (Button) layout.findViewById(R.id.account);
button1 = (Button) layout.findViewById(R.id.profile);
remove = (Button) layout.findViewById(R.id.remove);
change = (Button) layout.findViewById(R.id.change);
editName = (EditText) layout.findViewById(R.id.editName);
editGender = (EditText) layout.findViewById(R.id.editGender);
editAge = (EditText) layout.findViewById(R.id.editAge);
editCountry = (EditText) layout.findViewById(R.id.editCountry);
editDesccription = (EditText) layout.findViewById(R.id.editDescription);
editFood = (EditText) layout.findViewById(R.id.editFood);
editSports = (EditText) layout.findViewById(R.id.editSports);
add = (ImageView) layout.findViewById(R.id.add);
// create bitmap from resource
Bitmap bm = BitmapFactory.decodeResource(getResources(),
R.drawable.profile_blank_xlarge);
// set circle bitmap
ImageView mImage = (ImageView) layout.findViewById(R.id.image);
mImage.setImageBitmap(getCircleBitmap(bm));
mImage.setTag("profile_blank_xlarge");
new FetchOperation().execute();
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
post();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
});
if(!mImage.getTag().equals("profile_blank_xlarge")) {
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
remove_image();
}
}
);
}
else
{
remove.setEnabled(false);
}
change.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
change_image();
}
}
);
return layout;
}
//Functions for profile image
private Bitmap getCircleBitmap(Bitmap bitmap) {
final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(output);
final int color = Color.RED;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawOval(rectF, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
bitmap.recycle();
return output;
}
// Function to remove Image
public void remove_image()
{
// create bitmap from resource
Bitmap bm = BitmapFactory.decodeResource(getResources(),
R.drawable.com_facebook_profile_picture_blank_portrait);
// set circle bitmap
ImageView mImage = (ImageView) getView().findViewById(R.id.image);
mImage.setImageBitmap(getCircleBitmap(bm));
mImage.setTag("profile_blank_xlarge");
}
//Function to change image
public void change_image()
{
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
//Want to define onActivityResult here
@Override
? – shkschneider