I am trying to implement the Commonsware CWAC-Camera and I am running into an issue incorporating it into an existing fragment.
I am getting an issue where I cannot use .add or .replace and it wants me to change CameraFragment to Fragment.
ERROR:
The method add(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, CameraFragment, String)
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="21" />
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import com.commonsware.cwac.camera.CameraFragment;
public void takePicture() {
CameraFragment f = new CameraFragment();
getFragmentManager().beginTransaction()
.add(R.id.contentFragment, f, TAG_CAMERA_FRAGMENT)
.commit();
}
Has anyone experienced this before? Here is the entire fragment.
public class FeedActivity extends Fragment implements OnClickListener {
ImageButton btnCamera, btnGallery;
private final String TAG_CAMERA_FRAGMENT = "camera_fragment";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.activity_feed, container, false);
btnCamera = (ImageButton) view.findViewById(R.id.btn_Camera);
btnCamera.setOnClickListener(this);
btnGallery = (ImageButton) view.findViewById(R.id.btn_Gallery);
btnGallery.setOnClickListener(this);
return view;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_Camera:
Log.e("CAMERA", "CAMERA BUTTON PRESSED");
//takePicture();
break;
case R.id.btn_Gallery:
Log.e("Gallery", "GALLERY BUTTON PRESSED");
break;
}
}
public void takePicture() {
CameraFragment f = new CameraFragment();
getFragmentManager().beginTransaction()
.add(R.id.contentFragment, f, TAG_CAMERA_FRAGMENT)
.commit();
}
}