I am newbie in creating android app.The problem is i am only able to open my camera after clicking the camera button but when i click the picture it does not get stored in my mobile anywhere.So i want that when i open my camera through the camera button i should be able to click a picture and able to store it in my mobile somewhere in an directory in the internal sorage of my mobile such as ("pitchers directory under some other folder name as (camera demo folder)")
my java file is-
public class B1ITEM1L3 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_b1_item1_l3 );
JSONArray jsonArray=getJSonData( "B1ITEM1DATA.json" );
ArrayList<JSONObject> listItems=getArrayListFromJSONArray(jsonArray);
ListView listV= findViewById(R.id.list_viewL3ITEM1);
ListAdapter adapter = new ListadapterB1ITEM1 (this,R.layout.list_layoutb1item1,R.id.textView,listItems);
listV.setAdapter(adapter);
}
private JSONArray getJSonData(String fileName){
JSONArray jsonArray=null;
try {
InputStream is = getResources().getAssets().open(fileName);
int size = is.available();
byte[] data = new byte[size];
is.read(data);
is.close();
String json = new String(data, "UTF-8");
jsonArray=new JSONArray(json);
}catch (IOException e){
e.printStackTrace();
}catch (JSONException je){
je.printStackTrace();
}
return jsonArray;
}
private ArrayList<JSONObject> getArrayListFromJSONArray(JSONArray jsonArray){
ArrayList<JSONObject> aList= new ArrayList<>();
try {
if (jsonArray != null) {
for (int i = 0; i < jsonArray.length(); i++) {
aList.add(jsonArray.getJSONObject(i));
}
}
}catch (JSONException je){je.printStackTrace();}
return aList;
}
public void opencamera(View view) {
Intent intent = new Intent( MediaStore.ACTION_IMAGE_CAPTURE );
startActivity( intent );
} }
my listadapter file is-
class ListadapterB1ITEM1 extends ArrayAdapter<JSONObject> {
int vg;
ArrayList<JSONObject> list;
Context context;
public ListadapterB1ITEM1(Context context, int vg, int id, ArrayList<JSONObject> list){
super(context,vg, id,list);
this.context=context;
this.vg=vg;
this.list=list;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(vg, parent, false);
TextView txtId= itemView.findViewById( R.id.textView);
// TextView txtName= itemView.findViewById(R.id.textView2);
// TextView txtSex=(TextView)itemView.findViewById(R.id.txtsex);
try {
txtId.setText(list.get(position).getString("id"));
// txtName.setText(list.get(position).getString("name"));
// txtSex.setText(list.get(position).getString("sex"));
} catch (JSONException e) {
e.printStackTrace();
}
return itemView;
}
}
main xml file is-
<ListView
android:id="@+id/list_viewL3ITEM1"
android:layout_width="match_parent"
android:layout_height="453dp"
android:descendantFocusability="beforeDescendants">
</ListView>
<Button
android:id="@+id/button"
android:layout_width="136dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="2dp"
android:text="save as draft"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/list_viewL3ITEM1"
android:layout_marginStart="16dp"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/button2"
android:layout_width="136dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="16dp"
android:layout_marginTop="2dp"
android:text="cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/list_viewL3ITEM1"
android:layout_marginEnd="16dp"
tools:ignore="HardcodedText" />
list layout xml file is-
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="29sp"
android:layout_marginEnd="4sp"
android:layout_marginLeft="16sp"
android:layout_marginTop="16sp"
app:layout_constraintEnd_toStartOf="@+id/textView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginRight="4sp"
android:layout_marginStart="16sp" />
<TextView
android:id="@+id/textView"
android:layout_width="228dp"
android:layout_height="100dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/imageButton"
app:layout_constraintHorizontal_bias="0.978"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imageButton"
android:onClick="opencamera"
android:layout_width="78dp"
android:layout_height="60dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:drawable/ic_menu_camera"
android:layout_marginEnd="16dp"
tools:ignore="ContentDescription" />
<EditText
android:id="@+id/editText"
android:layout_width="345dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textShortMessage"
android:hint="Leave a Comment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
android:layout_marginStart="24dp"
android:layout_marginRight="16dp"
tools:ignore="HardcodedText" />
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…