Need help for Setting the Camera orientation with intent

1,035 views
Skip to first unread message

Cyril Preiss

unread,
Dec 11, 2013, 10:16:10 AM12/11/13
to tas...@googlegroups.com
Hi, i'm trying to lock camera orientation when i take a video (launched with Misc / Send Intent, put "android.media.action.VIDEO_CAPTURE" in the Action field and set Target to "Activity".)

i have seen various things but i don't know how to use them...

1. is it possible to use this and then how ?

public static final String EXTRA_SCREEN_ORIENTATION

Added in API level 3

The name of the Intent-extra used to control the orientation of a ViewImage or a MovieView. This is an int property that overrides the activity's requestedOrientation.

Constant Value: "android.intent.extra.screenOrientation"
2. i saw this java code, but can i use it in tasker (in don't know how to use javascript):


 public static void setCameraDisplayOrientation(Activity activity,
         
int cameraId, android.hardware.Camera camera) {
     android
.hardware.Camera.CameraInfo info =
             
new android.hardware.Camera.CameraInfo();
     android
.hardware.Camera.getCameraInfo(cameraId, info);
     
int rotation = activity.getWindowManager().getDefaultDisplay()
             
.getRotation();
     
int degrees = 0;
     
switch (rotation) {
         
case Surface.ROTATION_0: degrees = 0; break;
         
case Surface.ROTATION_90: degrees = 90; break;
         
case Surface.ROTATION_180: degrees = 180; break;
         
case Surface.ROTATION_270: degrees = 270; break;
     
}

     
int result;
     
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
         result
= (info.orientation + degrees) % 360;
         result
= (360 - result) % 360;  // compensate the mirror
     
} else {  // back-facing
         result
= (info.orientation - degrees + 360) % 360;
     
}
     camera
.setDisplayOrientation(result);
 
}
3. this solulion ?

protected void setOrientation() {
    int current = getRequestedOrientation();
    // only switch the orientation if not in portrait
    if ( current != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ) {
        setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT );
    }
}

Matt R

unread,
Dec 11, 2013, 1:18:08 PM12/11/13
to tas...@googlegroups.com
There's no way I know of to call java code in Tasker.  Note java != javascript.

Matt

Mike L

unread,
Dec 11, 2013, 4:11:38 PM12/11/13
to tas...@googlegroups.com

Cyril Preiss

unread,
Dec 12, 2013, 5:02:45 AM12/12/13
to tas...@googlegroups.com
thank you but it doesn't do anything for the camera app :(

Marta Hintz

unread,
Dec 12, 2013, 8:32:10 PM12/12/13
to tas...@googlegroups.com
What is it your trying to do? 

Cyril Preiss

unread,
Dec 13, 2013, 1:31:54 AM12/13/13
to tas...@googlegroups.com
i'm using a smartwatch Omate Truesmart.

The problem is that the camera orientation is very sensitive, if i move only a little up or down it will rotate the video, so i wanted to block it.

But it's not the app that rotate, but inside the app.

noni azure

unread,
Apr 4, 2015, 11:05:47 PM4/4/15
to tas...@googlegroups.com
Use this code from the Activity class to lock your screen. Just make sure to place it when you are coming back from the camera app.

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);

If you want to do a check first, to see which orientation your app is at when user comes back, then do this: 

getResources().getConfiguration().orientation

That one is useful if you want to see if the orientation might equal one portrait or landscape, and it it does, then //do something. Like this:

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            mImageBitmap
= rotateBitmap(mImageBitmap, 90);
       
}

Reply all
Reply to author
Forward
0 new messages