9/22/2013

Launch Camera App With Predefined Settings via Tasker

During the mid-autumn vacation, someone requested help in my QQ troop of Tasker (ID: 333174356), about how to launch camera app with predefined parameters(e.g. picture size, picture quality, and so on) for specific situation. Because of some other reason, I just give him an idea to try, and I haven’t put it into effect. After the vacation, I have chance to try my idea and it turns out the idea is right. Realized the principle behind the idea may be helpful to more similar situations, hereinafter I will explain the idea in detail, and take the “picture size” parameter of rear camera for example.




Firstly, we know that the “Media -> Take Photo” action will open the camera with custom parameters and then take photo automatically. Unfortunately, we can’t use this action to open the camera with custom parameters just for preview, then take photo manually.


I know a specific intent, which named “android.media.action.IMAGE_CAPTURE” in android, can launch the camera app with preview window. I’ve tried it before. And I find it not support camera parameters. I mean that it only open the camera window with default settings which we can’t change it programmatically.

Below shows the intent I tried:

Send Intent [ Action:android.media.action.IMAGE_CAPTURE Cat:Default Mime Type: Data: Extra: Extra: Package:com.android.camera Class:com.android.camera.Camera Target:Activity ]

As everyone knows, most settings are stored in the format of file, even databases. After some digging, I found the file (data/data/com.android.camera/shared_prefs/com.android.camera_xiaomi_preferences_0.xml) contains the “picture size” setting. We can change the value of “pref_camera_picturesize_key” node in the xml file programmatically. Then we launch the camera app. At last, we can restore the “picture size” setting.


Be careful! If you only follow these steps, the loaded camera app will not meet the desired effect. Because the camera app maybe can’t realize some settings changed, I think. There is a trick that you can disable and enable the app to take into effect. It’s very probably that the app will re-read the preferences file after the disable and enable operation. I guess the camera app read the settings and always runs in background when the device boots. We can disable and enable an app manually in android.


Of course, we can do this with the “Secure Setting” plugin for Tasker.



As for how to change the setting string in the preferences file, you can use shell script(especially “sed”, “awk” command) or use two files for renaming and swapping.

Here is the flowchart of the whole idea. (I've tried it successfully in MIUI 3.9.6)


5 comments:

  1. Nice, so in the preference set up you can state the preview also? Ours hard to take profits if you can't see yourself. Thanks

    ReplyDelete
  2. It will launch camera with preview window.

    I just show you an idea about how to do it. You can try the idea on your phone. Preference files maybe different.

    ReplyDelete
  3. Okay great, this is what I have been looking for!

    ReplyDelete
  4. Thank you for posting the great content…I was looking for something like this…I found it quiet interesting, hopefully and you will keep posting such blogs….Keep sharing.
    Web Application Development Companies in Bangalore, Web Application Development Services in Bangalore

    ReplyDelete
  5. I absolutely admired every bit of it and i additionally accept you book apparent to analysis out fresh things in your site.
    Business Information Blog

    ReplyDelete