Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Hi Welcome to Android I also have done this assignment when i have started. here is the code for camera.java </p> </blockquote> <p>`package com.example.android;</p> <p>import java.io.IOException; import java.io.InputStream;</p> <p>import android.app.Activity; import android.app.WallpaperManager; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView;</p> <p>public class Camera extends Activity implements OnClickListener {</p> <pre><code>ImageButton ib; Button b; ImageView iv; Intent i; final static int cameraData = 0; Bitmap bm; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.photo); initialize(); InputStream is = getResources().openRawResource( R.drawable.splash_background); bm = BitmapFactory.decodeStream(is); } public void initialize() { ib = (ImageButton) findViewById(R.id.ibTakePic); b = (Button) findViewById(R.id.bSetWall); iv = (ImageView) findViewById(R.id.ivReturnedPic); b.setOnClickListener(this); ib.setOnClickListener(this); } public void onClick(View v) { switch (v.getId()) { case R.id.bSetWall: try { WallpaperManager.getInstance(getApplicationContext()) .setBitmap(bm); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.ibTakePic: i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(i, cameraData); break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { Bundle extras = data.getExtras(); bm = (Bitmap) extras.get("data"); iv.setImageBitmap(bm); } } </code></pre> <p>}</p> <p>Here is xml for activity </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; </code></pre> <p></p> <pre><code>&lt;Button android:id="@+id/bSetWall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Set Wall" /&gt; &lt;ImageView android:id="@+id/ivReturnedPic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /&gt; &lt;ImageButton android:id="@+id/ibTakePic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/splash_background" /&gt; </code></pre> <p></p> <p>check this link<a href="http://www.youtube.com/results?search_query=Android%20Application%20Development%20Tutorial%20-%2038%20-%20XML%20Image%20View%20for%20Camera%20Application" rel="nofollow">Video tutorial for android </a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload