Extend android app
I'd li开发者_StackOverflowke to create an app that is the same as the default camera app only with one small modification (i.e. video disabled or extra functionality added). How do I do it?
Do I just get the source code of the camera app and modify it or is there a way to extend core components of the Android system?
bizso99,
You can call an Intent
from your Activity
that is simply the camera sans video functionality like so:
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, TAKE_PICTURE);
}
This will return a smaller thumbnail version of the image. If you want the full size you need to use the Mediastore.EXTRA_OUTPUT
like so:
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
mImageFile = new File(pathToStoreImage); //file where image will be stored
mSelectedImagePath = mImageFile.getAbsolutePath(); //path to file where image will be stored
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
Then you can receive the picture in onActivityResult()
Android is open source, so you can download the source for every stock-app in android (not for the google apps like Maps). You can in fact download the most recent original camera app from the android git repo. The building of the apk is only possible if you download the whole android-source. For a overview how to build the android-source, see this howto. You could modify the source for your needs.
I'm quite sure that it is impossible to extend the camera-app without copying the source because there is no plugin-api (or similiar) for the camera-api.
精彩评论