Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialUnsubscribed User
373 PointsThe Github project is not working properly in the tutorial on "How to use the camera in Android"
I keep getting these two errors when building the project from video 1 in the tutorial
Error:com.android.builder.internal.aapt.AaptException: Failed to crunch file C:\Users\Mads\Desktop\Android Development\android-using-the-camera-workshop-6a42beb7ddb68d3ae94de3bfec48ea73990caf1c\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.4.0\res\drawable-mdpi-v4\abc_switch_track_mtrl_alpha.9.png into C:\Users\Mads\Desktop\Android Development\android-using-the-camera-workshop-6a42beb7ddb68d3ae94de3bfec48ea73990caf1c\app\build\intermediates\res\merged\debug\drawable-mdpi-v4\abc_switch_track_mtrl_alpha.9.png
No idea why though
Ben Deitch
Treehouse TeacherHey Mads!
I think I've actually seen this issue before. It has to do with certain PNG files not working for some reason. Here's a Stack Overflow post that might be helpful. I know when I saw this error I had to actually go in and change my PNGs in some way, but I can't recall exactly what I did.
Also, this is an older workshop, and sometimes things change with Android (or Android Studio) and that ends up breaking some of our previous work. It's just one of the hazards of developing with Android :). That said, I'll be sure to pass this along to Ben J and see if we can't update the GitHub project to not throw any errors in the future.
2 Answers
Unsubscribed User
373 PointsUnfortunately i have already tried that and it does not seem to work. I simply have no idea why haha
Ben Jakuben
Treehouse TeacherUgh - I'm very sorry about this. I'm not able to recreate it, but it may be because of your specific directory structure. Check out this Stack Overflow post about a limitation in Windows.
If that's the problem, can you try moving your project to a directory that doesn't include that long string from the Git commit (6a42beb7ddb68d3ae94de3bfec48ea73990caf1c) after the project name?
Unsubscribed User
373 PointsIt's alright Ben! I found other ways to do it through Youtube. Sometimes technology just won't work haha. But anyways. I was wondering if you would know how to make this save a video instead of a BitMap/Image
package com.google.android.gms.drive.sample.quickstart;
import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream;
import android.app.Activity; import android.content.Intent; import android.content.IntentSender; import android.content.IntentSender.SendIntentException; import android.graphics.Bitmap; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.widget.Button;
import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.drive.Drive; import com.google.android.gms.drive.DriveApi.DriveContentsResult; import com.google.android.gms.drive.MetadataChangeSet;
/**
- Android Drive Quickstart activity. This activity takes a photo and saves it
- in Google Drive. The user is prompted with a pre-made dialog which allows
-
them to choose the file location. */ public class Main2Activity extends Activity implements ConnectionCallbacks, OnConnectionFailedListener {
private static final String TAG = "drive-quickstart"; private static final int REQUEST_CODE_CAPTURE_IMAGE = 1; private static final int REQUEST_CODE_CREATOR = 2; private static final int REQUEST_CODE_RESOLUTION = 3;
private GoogleApiClient mGoogleApiClient; private Bitmap mBitmapToSave;
/**
- Create a new file and save it to Drive. */
private void saveFileToDrive() { // Start by creating a new contents, and setting a callback. Log.i(TAG, "Creating new contents."); final Bitmap image = mBitmapToSave; Drive.DriveApi.newDriveContents(mGoogleApiClient) .setResultCallback(new ResultCallback<DriveContentsResult>() {
@Override public void onResult(DriveContentsResult result) { // If the operation was not successful, we cannot do anything // and must // fail. if (!result.getStatus().isSuccess()) { Log.i(TAG, "Failed to create new contents."); return; } // Otherwise, we can write our data to the new contents. Log.i(TAG, "New contents created."); // Get an output stream for the contents. OutputStream outputStream = result.getDriveContents().getOutputStream(); // Write the bitmap data from it. ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream); try { outputStream.write(bitmapStream.toByteArray()); } catch (IOException e1) { Log.i(TAG, "Unable to write file contents."); } // Create the initial metadata - MIME type and title. // Note that the user will be able to change the title later. MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder() .setMimeType("image/jpeg").setTitle("Android Photo.png").build(); // Create an intent for the file chooser, and start it. IntentSender intentSender = Drive.DriveApi .newCreateFileActivityBuilder() .setInitialMetadata(metadataChangeSet) .setInitialDriveContents(result.getDriveContents()) .build(mGoogleApiClient); try { startIntentSenderForResult( intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0); } catch (SendIntentException e) { Log.i(TAG, "Failed to launch file chooser."); } } });
}
@Override protected void onResume() { super.onResume(); if (mGoogleApiClient == null) { // Create the API client and bind it to an instance variable. // We use this instance as the callback for connection and connection // failures. // Since no account name is passed, the user is prompted to choose. mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } // Connect the client. Once connected, the camera is launched. mGoogleApiClient.connect(); }
@Override protected void onPause() { if (mGoogleApiClient != null) { mGoogleApiClient.disconnect(); } super.onPause(); }
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_CODE_CAPTURE_IMAGE: // Called after a photo has been taken. if (resultCode == Activity.RESULT_OK) { // Store the image data as a bitmap for writing later. mBitmapToSave = (Bitmap) data.getExtras().get("data"); } break; case REQUEST_CODE_CREATOR: // Called after a file is saved to Drive. if (resultCode == RESULT_OK) { Log.i(TAG, "Image successfully saved."); mBitmapToSave = null; // Just start the camera again for another photo. startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), REQUEST_CODE_CAPTURE_IMAGE); } break; } }
@Override public void onConnectionFailed(ConnectionResult result) { // Called whenever the API client fails to connect. Log.i(TAG, "GoogleApiClient connection failed: " + result.toString()); if (!result.hasResolution()) { // show the localized error dialog. GoogleApiAvailability.getInstance().getErrorDialog(this, result.getErrorCode(), 0).show(); return; } // The failure has a resolution. Resolve it. // Called typically when the app is not yet authorized, and an // authorization // dialog is displayed to the user. try { result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION); } catch (SendIntentException e) { Log.e(TAG, "Exception while starting resolution activity", e); } }
@Override public void onConnected(Bundle connectionHint) { Log.i(TAG, "API client connected."); if (mBitmapToSave == null) { // This activity has no UI of its own. Just start the camera. startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), REQUEST_CODE_CAPTURE_IMAGE); return; } saveFileToDrive(); }
@Override public void onConnectionSuspended(int cause) { Log.i(TAG, "GoogleApiClient connection suspended"); } }
Unsubscribed User
373 PointsUnsubscribed User
373 PointsI pay 25 dollars a month for tutorials that are not working and a customer support that takes a million years to answer back...