Foto beim Starten einer Activity machen?

E

Extremefall

Ambitioniertes Mitglied
3
Hallo,
ich habe eine Klasse TakePhoto, die beim Aufruf ein Photo macht. Das klappt auch wunderbar.Es dauert etwa 2 Sekunden und dann wird ein Foto gemacht.

Wenn ich nun die Klasse allerdings über eine andere Klasse versuche aufzurfen, geht es nicht. Es gibt dort keiine Exception. Der Aufruf der Activity TakePhoto erfolgt wie folgt:
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[LEFT]package[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] location.android.com;
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.app.Activity;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.content.Intent;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.os.Bundle;
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] StartService [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity {

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onCreate(Bundle savedInstanceState) {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].onCreate(savedInstanceState);
startActivity([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Intent(StartService.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], TakePhoto.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));
}
[/LEFT]
}
[/SIZE]
Die Klasse TakePhoto:
Code:
package location.android.com;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class TakePhoto extends Activity implements SurfaceHolder.Callback {
 // a variable to store a reference to the Surface View at the main.xml file
 private SurfaceView sv;
 // a bitmap to display the captured image
 private Bitmap bmp;
 // Camera variables
 // a surface holder
 private SurfaceHolder sHolder;
 // a variable to control the camera
 private Camera mCamera;
 // the camera parameters
 private Parameters parameters;
 Context appcontext = null;
 private Handler mHandlerFoto = new Handler();
 private Runnable mUpdateTimeTaskFoto = new Runnable() {
  public void run() {
   // get camera parameters
   parameters = mCamera.getParameters();
   parameters.set("camera_id", 2);
   // set camera parameters
   mCamera.setParameters(parameters);
   mCamera.startPreview();
   // sets what code should be executed after the picture is taken
   Camera.PictureCallback mCall = new Camera.PictureCallback() {
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
     // decode the data obtained by the camera into a Bitmap
     bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
     // set the iv_image
     String path = Environment.getExternalStorageDirectory()
       .toString();
     OutputStream fOut = null;
     File file = new File(path, "FitnessGirl.jpg");
     try {
      fOut = new FileOutputStream(file);
      bmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
      fOut.flush();
      fOut.close();
      MediaStore.Images.Media.insertImage(
        getContentResolver(), file.getAbsolutePath(),
        file.getName(), file.getName());
     } catch (Exception e) {
      // TODO Auto-generated catch block
     }
    }
   };
   mCamera.takePicture(null, null, mCall);
   // moveTaskToBack (true);
  }
 };
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  appcontext = getApplicationContext();
  // get the Surface View at the main.xml file
  sv = (SurfaceView) findViewById(R.id.surfaceView);
  // Get a surface
  sHolder = sv.getHolder();
  // add the callback interface methods defined below as the Surface View
  // callbacks
  sHolder.addCallback(this);
  // tells Android that this surface will have its data constantly
  // replaced
  sHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  /**
   * MediaPlayer mp = MediaPlayer.create(appcontext, R.raw.sound);
   * mp.start();
   */
 }
 @Override
 public void onDestroy() {
  super.onDestroy();
 }
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
 }
 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
 }
 private void showMessage(String pMessage) {
  Toast.makeText(getApplicationContext(), pMessage, Toast.LENGTH_LONG)
    .show();
 }
 @Override
 public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
  mHandlerFoto.removeCallbacks(mUpdateTimeTaskFoto);
  mHandlerFoto.postDelayed(mUpdateTimeTaskFoto, 10);
 }
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
  // The Surface has been created, acquire the camera and tell it where
  // to draw the preview.
  try {
   mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
   SurfaceView view = new SurfaceView(this);
   mCamera.setPreviewDisplay(view.getHolder());
  } catch (Exception exception) {
   mCamera.release();
   mCamera = null;
  }
 }
 @Override
 public void surfaceDestroyed(SurfaceHolder holder) {
  // stop the preview
  mCamera.stopPreview();
  // release the camera
  mCamera.release();
  // unbind the camera from this object
  mCamera = null;
 }
}
Die Manifest Datei:
Code:
[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]
[LEFT]<?[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]xml[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]version[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"1.0"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]encoding[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"utf-8"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]?>
<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]manifest[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]xmlns:android[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"http://schemas.android.com/apk/res/android"[/LEFT]
[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]package[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"location.android.com"[/LEFT]
[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:versionCode[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"1"[/LEFT]
[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:versionName[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"1.0"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/SIZE][U][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]uses-sdk[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:minSdkVersion[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"4"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/LEFT]
[/U][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]uses-permission[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"android.permission.CAMERA"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]uses-permission[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]uses-feature[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"android.hardware.camera"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]uses-permission[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"android.permission.WRITE_EXTERNAL_STORAGE"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/COLOR][/SIZE][/COLOR][/SIZE][LEFT][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080][/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT]
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]application[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:label[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@string/app_name"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080][/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]activity[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]".TakePhoto"[/LEFT]
[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:label[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@string/app_name"[/LEFT]
[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:theme[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@style/Theme.Transparent"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]intent-filter[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]category[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"android.intent.category.LAUNCHER" [/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]intent-filter[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]activity[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]activity[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]".StartService"[/LEFT]
[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:label[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@string/app_name"[/LEFT]
[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:theme[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@style/Theme.Transparent"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]intent-filter[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]action[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"android.intent.action.MAIN"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]category[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"android.intent.category.LAUNCHER"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]intent-filter[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]activity[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]service[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]".AppService"[/LEFT]
[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:enabled[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"true"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]application[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT]
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]manifest[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>
[/COLOR][/SIZE][/COLOR][/SIZE]
Das komische ist, dass nach über 50 Sekunden ein Foto geschossen wird. Oder es wird ein Foto geschossen, wenn man beim Handy die Tastensperre aktiviert und dann es wieder öffnet.

Wisst ihr, warum der Aufruf nicht klappt? Denn wenn man die Klase TakePhoto direkt aufruft, geht es ja. Liegt es wohl an dieser Klasse oder am Aufruf? Ich bitte um eure Mithilfe ;)
 
Darf ich dann Teile des Codes für meine App einsetzen? Wird das Bild auch im Hintergrund geschossen?
 
Ich starte die Activity demnach richtig. Wenn ich ein Popup in die Oncreate Methode setze, wird es auch sofort angezeigt. Ein Foto wird immer dann geschossen, wenn die Tastensperre aktiviert war und dann während des deaktivierens.
Wie kann ich denn festlegen, dass direkt beim öffnen der Activity ein Foto geschossen wird?

Die App dient ja eher dazu, auf Befehl ein Foto zu schiessen.
 
Ich gehe mal davon aus, dass du einen Wakelock halten musst, damit sich die CPU nach Aufruf deren Activity nicht gleich wieder schlafen legt.

Gesendet von meinem MB525 mit Tapatalk 2
 
Leider hilft das nicht weiter. Ich habe ausprobiert in der onCreate Methode der TakePhoto Klasse, doch es ändert leider garnichts. Doch ich denke, der Ansatz ist richtig.
Code:
[SIZE=2]
[LEFT]PowerManager pm = (PowerManager) getSystemService(Context.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]POWER_SERVICE[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]FULL_WAKE_LOCK[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"The Tag"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); 
wl.acquire(); [/LEFT]

[/SIZE]

Meine Vermutung: Ich denke, dass die Activity aus irgendeinem Grund noch nicht den Fokus hat. Wenn ich die Datei installiere und dann öffne, passiert nichts. Das Foto wird allerdings sofort geschossen, wenn ich den Bildschirm einmal deaktiviere und sofort nach dem Aktivieren wird ein Foto gemacht. Die Tastensperre muss nicht einmal deaktiviert werden.

Kann man nachträglich einer Activity den Fokus geben? Kann das Problem daran liegen, dass die Activity nicht als Main Activity in der Manifest Datei festgelegt ist?
 
Kann mir wirklich keiner mehr weiterhelfen? Wird die Methode surfaceChanged eventuell nicht aufgerufen? Kann man die Methode manuell aufrufen oder welche Ursache könnte es,noch geben?

Der ursprüngliche Beitrag von 12:03 Uhr wurde um 12:09 Uhr ergänzt:

Ich glaube, der Fehler ist, dass das Handy,erst gedreht werden muss. Versuche das Problem jetzt zu lösen. Ich gebe dann spater Bescheid.

Der ursprüngliche Beitrag von 12:09 Uhr wurde um 12:50 Uhr ergänzt:

hallo,
ich habe das Problem nun selbst lösen können. Der Fehler lag an der Orientierung. Das Foto wird ja erst dann geschossen, wenn sich diese ändert. Also habe ich einfach folgendes zur OnCreate Methode hinzugefügt:
setRequestedOrientation (ActivityInfo.​
SCREEN_ORIENTATION_LANDSCAPE);

setRequestedOrientation (ActivityInfo.
SCREEN_ORIENTATION_PORTRAIT);
Damit klappt es nun und es wird sofort beim Aufruf der Activity ohne Vorschau ein Bild gespeichert. Vielen Dank für die Info.
 

Ähnliche Themen

Laser5001
  • Laser5001
Antworten
2
Aufrufe
900
Laser5001
Laser5001
D
  • Data2006
Antworten
14
Aufrufe
486
jogimuc
J
S
  • Sempervivum
Antworten
2
Aufrufe
607
Sempervivum
S
Zurück
Oben Unten