Skip to content

Instantly share code, notes, and snippets.

@tawat25
Created July 9, 2020 13:22
Show Gist options
  • Save tawat25/b5199d6fb41d252cb026742b19f21a2b to your computer and use it in GitHub Desktop.
Save tawat25/b5199d6fb41d252cb026742b19f21a2b to your computer and use it in GitHub Desktop.
package com.example.basiccam1;
import android.content.Intent;
import android.media.audiofx.EnvironmentalReverb;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
private static int TAKE_PHOTO_REQUEST_CODE = 1;
Uri uri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void takePhoto(View v)
{
int REQUEST_CAMERA = 0;
String timeStamp = new SimpleDateFormat("HHmmss").format(new Date());
String imageFileName = "MPIC_" + timeStamp + ".jpg";
File f = new File(Environment.getExternalStorageDirectory(), "img/" + imageFileName);
Log.d("080763_1", "...1");
uri = Uri.fromFile(f);
Log.d("080763_1", "...2");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Log.d("080763_1", "path Filestring ==>" + uri.toString());
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
Log.d("080763_1", "...3");
startActivityForResult(intent, TAKE_PHOTO_REQUEST_CODE);
Log.d("080763_1", "...4");
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Log.d("080763_1", "...5");
if (requestCode == TAKE_PHOTO_REQUEST_CODE && resultCode == RESULT_OK) {
Toast.makeText(this, uri.toString(), Toast.LENGTH_LONG).show();
}
} // onActivity
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment