BrU32

Android Java Native Snap Photo SRC

Jul 19th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:gravity="center">
  5. <Button
  6. android:id="@+id/test"
  7. android:text="Take Picture"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"/>
  10. </LinearLayout>
  11.  
  12. package com.mycompany.myapp;
  13.  
  14. import android.app.*;
  15. import android.os.*;
  16. import android.content.*;
  17. import android.widget.Button;
  18. import android.view.*;
  19. import android.text.*;
  20. import android.content.Intent;
  21. import android.provider.*;
  22.  
  23. public class MainActivity extends Activity
  24. {
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState)
  27. {
  28. super.onCreate(savedInstanceState);
  29. setContentView(R.layout.main);
  30. final Button but=(Button)findViewById(R.id.test);
  31. but.setOnClickListener(new View.OnClickListener(){
  32. public void onClick(View v){
  33. Intent tp=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  34. if(tp.resolveActivity(getPackageManager())!=null){
  35. startActivity(tp);
  36. }
  37. }
  38.  
  39. });
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment