2015-03-10 4 views
-2

Я работаю над приложением android. У меня есть 2 действия, MainActivity Вызывает намерение, которое использует мою CameraActivity, которая описана ниже.Приостановить все темы

public class CameraActivity extends ActionBarActivity { 

    private static final int REQUEST_IMAGE = 100; 
    private static final int REQUEST_VIDEO = 200; 
    private static final int SELECT_IMAGE = 300; 

    Button mCaptureButton; 
    Button mGalleryButton; 
    ImageView mImageView; 
    TextView mText; 
    File mDestination; 
    int mMediaType = 0; 

    Uri mAttachedImage = null; 

    String mCurrentPhotoPath; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_camera); 

     mCaptureButton = (Button)findViewById(R.id.capture); 
     mCaptureButton.setOnClickListener(mCameraListener); 

     mGalleryButton= (Button)findViewById(R.id.gallery); 
     mCaptureButton.setOnClickListener(mGalleryListener); 

     mGalleryButton= (Button)findViewById(R.id.send); 
     mCaptureButton.setOnClickListener(mSendListener); 

     mImageView = (ImageView)findViewById(R.id.image); 
     mText = (TextView)findViewById(R.id.file); 

     //Generar una codificación para el nombre 
     //mCurrentPhotoPath = this.getImageFileName(); 
     //mDestination = new File(Environment.getExternalStorageDirectory(), mCurrentPhotoPath + ".jpg"); 
     mDestination = new File(Environment.getExternalStorageDirectory(), "MyImage.jpg"); 

    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_camera, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 

    String getImageFileName() 
    { 
     String mTimeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 
     String sImgFileName = "GPS_JPG_" + mTimeStamp; 
     return sImgFileName; 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     //PAra imágenes 
     if(requestCode == REQUEST_IMAGE && resultCode == Activity.RESULT_OK && mMediaType == 0) { 
      //Process and display the image 
      try{ 
       FileInputStream in = new FileInputStream(mDestination); 
       //BitmapFactory.Options mOptions = new BitmapFactory.Options(); 
       //mOptions.inSampleSize = 1; //Para reducir el tamaño del archivo 
       //Bitmap userImage = BitmapFactory.decodeStream(in, null, mOptions); 
       Bitmap userImage = BitmapFactory.decodeStream(in); 
       mImageView.setImageBitmap(userImage); 
      }catch (Exception e) 
      { 
       e.printStackTrace(); 
      } 
      //Bitmap userImage = (Bitmap)data.getExtras().get("data"); 
      //mImageView.setImageBitmap(userImage); 
     } 
     //Para Video 
     if(requestCode == REQUEST_VIDEO && resultCode == Activity.RESULT_OK && mMediaType == 1) { 
      try{ 
       String mLocation = data.getData().toString(); 
       mText.setText(mLocation); 
      }catch (Exception e) 
      { 
       e.printStackTrace(); 
      } 
     } 
     //Para la Galería 
     if(requestCode == SELECT_IMAGE && resultCode == Activity.RESULT_OK) { 
      try{ 
       Uri mSelectedImageTmp = data.getData(); 
       InputStream mImageStream = getContentResolver().openInputStream(mSelectedImageTmp); 
       Bitmap mSelectedImage = BitmapFactory.decodeStream(mImageStream); 
       mImageView.setImageBitmap(mSelectedImage); 
      }catch (Exception e) 
      { 
       e.printStackTrace(); 
      } 
     } 
    } 


    /** 
    * Llama al procedimiento de tomar fotos 
    */ 
    private View.OnClickListener mCameraListener = new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      try { 
       //Agregar codigo para diferenciar Foto de Video 
       if(mMediaType == 0){ 

        Intent mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
        mIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mDestination)); 
        if (mIntent.resolveActivity(getPackageManager()) != null) { 
         startActivityForResult(mIntent, REQUEST_IMAGE); 
        } 
       } 
       else 
       { 
        Intent mIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
        //Add (optional) extra to save video to our file 
        mIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mDestination)); 
        //Optional extra to set video quality 
        mIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); 
        if (mIntent.resolveActivity(getPackageManager()) != null) { 
         startActivityForResult(mIntent, REQUEST_VIDEO); 
        } 
       } 
      } catch (ActivityNotFoundException e) { 
       //Handle if no application exists 
      } 
     } 
    }; 

    private View.OnClickListener mGalleryListener = new View.OnClickListener(){ 
     @Override 
     public void onClick(View v) { 

      try{ 
       //Intent mPhotoSelectIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
       Intent mPhotoSelectIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
       mPhotoSelectIntent.setType("image/*"); 

       if(Build.VERSION.SDK_INT >= 18){ 
        mPhotoSelectIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); 
       } 

       startActivityForResult(mPhotoSelectIntent, SELECT_IMAGE); 
      } 
      catch(Exception ex) 
      { 

      } 
     } 
    }; 

    /** 
    * Procedimiento para envíar la data al server 
    */ 
    private View.OnClickListener mSendListener = new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

     } 
    }; 


} 

Так что проблема в том, что я получаю следующие сообщения, и намерение, которое открывает камеру, кажется, приостановлено. Я новичок в Android, так что я делаю неправильно?

Надеюсь, вы могли бы мне помочь.

Это мой Logcat

03-10 21:30:54.340 1916-1916/sarode.muninews I/art﹕ Not late-enabling -Xcheck:jni (already on) 
03-10 21:30:55.005 1916-1923/sarode.muninews W/art﹕ Suspending all threads took: 43.166ms 
03-10 21:30:55.101 1916-1928/sarode.muninews W/art﹕ Suspending all threads took: 66.286ms 
03-10 21:30:55.108 1916-1928/sarode.muninews I/art﹕ Background sticky concurrent mark sweep GC freed 1801(119KB) AllocSpace objects, 0(0B) LOS objects, 25% free, 465KB/623KB, paused 69.733ms total 328.923ms 
03-10 21:30:55.291 1916-1928/sarode.muninews W/art﹕ Suspending all threads took: 56.251ms 
03-10 21:30:55.296 1916-1928/sarode.muninews I/art﹕ Background partial concurrent mark sweep GC freed 113(33KB) AllocSpace objects, 0(0B) LOS objects, 52% free, 456KB/968KB, paused 58.321ms total 172.911ms 
03-10 21:30:55.454 1916-1934/sarode.muninews D/OpenGLRenderer﹕ Render dirty regions requested: true 
03-10 21:30:55.456 1916-1916/sarode.muninews D/﹕ HostConnection::get() New Host Connection established 0xa6dae620, tid 1916 
03-10 21:30:55.466 1916-1916/sarode.muninews D/Atlas﹕ Validating map... 
03-10 21:30:55.570 1916-1928/sarode.muninews I/art﹕ Background sticky concurrent mark sweep GC freed 2902(177KB) AllocSpace objects, 0(0B) LOS objects, 17% free, 799KB/968KB, paused 6.153ms total 62.260ms 
03-10 21:30:55.598 1916-1934/sarode.muninews D/﹕ HostConnection::get() New Host Connection established 0xa6dae9a0, tid 1934 
03-10 21:30:55.618 1916-1934/sarode.muninews I/OpenGLRenderer﹕ Initialized EGL, version 1.4 
03-10 21:30:55.664 1916-1934/sarode.muninews D/OpenGLRenderer﹕ Enabling debug mode 0 
03-10 21:30:55.677 1916-1934/sarode.muninews W/EGL_emulation﹕ eglSurfaceAttrib not implemented 
03-10 21:30:55.677 1916-1934/sarode.muninews W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6d956c0, error=EGL_SUCCESS 
03-10 21:30:56.741 1916-1928/sarode.muninews I/art﹕ Background sticky concurrent mark sweep GC freed 178(24KB) AllocSpace objects, 0(0B) LOS objects, 5% free, 914KB/968KB, paused 4.185ms total 268.968ms 
03-10 21:30:56.876 1916-1916/sarode.muninews I/Choreographer﹕ Skipped 69 frames! The application may be doing too much work on its main thread. 
03-10 21:30:56.962 1916-1923/sarode.muninews W/art﹕ Suspending all threads took: 63.663ms 
03-10 21:30:56.992 1916-1928/sarode.muninews I/art﹕ Background partial concurrent mark sweep GC freed 257(38KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 892KB/1404KB, paused 2.726ms total 141.552ms 
03-10 21:31:02.298 1916-1934/sarode.muninews W/EGL_emulation﹕ eglSurfaceAttrib not implemented 
03-10 21:31:02.298 1916-1934/sarode.muninews W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5c536c0, error=EGL_SUCCESS 
03-10 21:31:17.536 1916-1934/sarode.muninews W/EGL_emulation﹕ eglSurfaceAttrib not implemented 
03-10 21:31:17.536 1916-1934/sarode.muninews W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5c536c0, error=EGL_SUCCESS 
03-10 21:31:17.752 1916-1923/sarode.muninews W/art﹕ Suspending all threads took: 19.847ms 
03-10 21:31:17.775 1916-1928/sarode.muninews I/art﹕ Background sticky concurrent mark sweep GC freed 2825(130KB) AllocSpace objects, 0(0B) LOS objects, 12% free, 1227KB/1404KB, paused 3.490ms total 299.942ms 
03-10 21:31:17.820 1916-1928/sarode.muninews W/art﹕ Suspending all threads took: 44.499ms 
03-10 21:31:18.107 1916-1916/sarode.muninews W/IInputConnectionWrapper﹕ finishComposingText on inactive InputConnection 
03-10 21:31:22.990 1916-1923/sarode.muninews W/art﹕ Suspending all threads took: 9.156ms 
03-10 21:31:23.015 1916-1928/sarode.muninews I/art﹕ Background sticky concurrent mark sweep GC freed 716(30KB) AllocSpace objects, 0(0B) LOS objects, 11% free, 1246KB/1404KB, paused 28.796ms total 60.860ms 
03-10 21:31:23.039 1916-1928/sarode.muninews W/art﹕ Suspending all threads took: 22.880ms 
03-10 21:31:29.149 1916-1928/sarode.muninews I/art﹕ Background sticky concurrent mark sweep GC freed 776(36KB) AllocSpace objects, 0(0B) LOS objects, 10% free, 1255KB/1404KB, paused 23.451ms total 30.459ms 
03-10 21:31:32.767 1916-1923/sarode.muninews W/art﹕ Suspending all threads took: 5.871ms 
03-10 21:31:33.725 1916-1928/sarode.muninews W/art﹕ Suspending all threads took: 22.085ms 
03-10 21:31:34.611 1916-1928/sarode.muninews I/art﹕ Background sticky concurrent mark sweep GC freed 459(20KB) AllocSpace objects, 0(0B) LOS objects, 9% free, 1266KB/1404KB, paused 33.821ms total 73.711ms 
03-10 21:31:35.828 1916-1928/sarode.muninews I/art﹕ Background partial concurrent mark sweep GC freed 1438(72KB) AllocSpace objects, 0(0B) LOS objects, 29% free, 1218KB/1730KB, paused 2.764ms total 219.659ms 
03-10 21:31:35.845 1916-1928/sarode.muninews W/art﹕ Suspending all threads took: 16.503ms 
03-10 21:32:11.825 1916-1923/sarode.muninews W/art﹕ Suspending all threads took: 12. 

Спасибо заранее

ответ

-6

проверяя мой код, я нашел все мои кнопки были плохо закреплены за их listerners. После выполнения некоторых изменений все работало, как я хочу.

Благодарим за помощь.

+9

Можете ли вы опубликовать рабочий код? У меня такая же проблема, и я хотел бы посмотреть, что вы сделали, чтобы исправить вашу проблему. – akousmata

Смежные вопросы