Note that there are some explanatory texts on larger screens.

plurals
  1. POCamera intent not working
    primarykey
    data
    text
    <p>I am trying to open the camera once i click a button and then display the captured picture on the screen,but nothing happens when i click the button.The camera does not open.Below is the code of my java program and it's corresponding xml file.</p> <p>My class:</p> <pre><code>package com.example.splashscreen; import java.io.IOException; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; public class CameraappActivity extends Activity implements View.OnClickListener{ ImageButton imb1; ImageView imv1; Button b1; final static int cameradata=1; Bitmap bmp; Intent i1; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cameraapp); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.cameraapp, menu); initialise(); imb1.setOnClickListener(this); b1.setOnClickListener(this); return true; } private void initialise() { // TODO Auto-generated method stub imv1=(ImageView)findViewById(R.id.imview1); imb1=(ImageButton)findViewById(R.id.imb2); System.out.println("Hello"); b1=(Button)findViewById(R.id.setw); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.imb2:i1=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); System.out.println("entered"); startActivityForResult(i1, cameradata); break; case R.id.setw: try{ getApplicationContext().setWallpaper(bmp);} catch(IOException e){ e.printStackTrace(); } break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); System.out.println("Hi1"); if(resultCode==RESULT_OK) { System.out.println("Hi2"); Bundle b1=data.getExtras(); bmp=(Bitmap)b1.get("data"); imv1.setImageBitmap(bmp); } } } </code></pre> <p>My XML:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".CameraappActivity" &gt; &lt;ImageButton android:id="@+id/imb2" android:layout_width="100dp" android:layout_height="100dp" android:layout_above="@+id/setw" android:layout_alignLeft="@+id/setw" android:layout_marginBottom="24dp" android:src="@drawable/sunset1" android:contentDescription="Take picture"/&gt; &lt;ImageView android:id="@+id/imview1" android:layout_width="200dp" android:layout_height="300dp" android:layout_above="@+id/imb2" android:layout_centerHorizontal="true" android:layout_marginBottom="96dp" android:src="@drawable/ic_launcher" /&gt; &lt;Button android:id="@+id/setw" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="40dp" android:text="@string/sew" /&gt; &lt;/RelativeLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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