Get Started         Best Practices         Developer Guide         FAQ        
Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Android Locked to Landscape Orientation.

Alan Pennell-Smith Jul 30, 2015

Hi,

I'm working on a project using the Android AR SDK, which has been working fine.

I've got a requirement to lock the app to a landscape orientation, which again is working ok. But once into the camera/scanning activity and the image is recognised it appears that the loaded content is being applied as if in portrait (so the AR doesn't line up properly).

Is there a setting I need to set to say we're starting (and staying) in landscape orientation?

Thanks

Al


( Agent )
Miquel Ferrarons

Jul 31, 2015

No, there isn’t. What could be happening is that the Android SDK is not managing correctly the EXIF information of the content. This usually happens with images or videos taken from an iPhone. Try to re-encode the video or images in a PC and check again.

If after doing this the problem is still happening, please tell us which item you are using and your email accound, and I will check it.

Best,

Miquel.

0 rated
Alan Pennell-Smith

Aug 03, 2015

Hi Miquel,

Thanks for the reply, we were using PNG's which don't support EXIF, but after changing to a JPG with the orientation EXIF data we're still seeing an issue.

All 3 test items seem to be exhibiting the behaviour, maybe easiest to see with "DubaiVideo" in the account with the email address used for this comment.

This is what we're experiencing: https://www.dropbox.com/s/cdvoy5aub5j7sqh/Screenshot%202015-08-03%2010.15.55.png?dl=0 (Android app, locked to landscape orientation only).

Thanks

Al
0 rated
( Agent )
Miquel Ferrarons

Aug 03, 2015

Hi Alan,

I was checking and I’m noticing that the SDK is currently not handling OK the camera orientation if it’s started directly forced in landscape mode. As a quick fix, try forcing the landscape orientation programatically, rather than doing it in the AndroidManifest, by calling “setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);” at the end of the onPostCreate() method of your CraftARActivity. I just tried that and it’s working fine.

We will take a look and let you know once this is solved.

Miquel.

0 rated
Alan Pennell-Smith

Aug 06, 2015

Hi Miquel,

I've added the setRequestedOrientation call to the end of my onPostCreate but it doesn't seem to be resolving the issue consistently. Sometimes it appears in the right orientation, other times not.

All my activities have to be declared with a landscape screenOrientation as there are no portrait layout styles.

Anything else I can try?

Thanks for your help

Al
0 rated
( Agent )
Miquel Ferrarons

Aug 06, 2015

Can you try to force a call to ‘CraftARSDK.getCamera().restartCamera’ at the end of the onPostCreate method? Maybe restarting the camera will detect the correct orientation and will fix it.

Miquel.

0 rated
Alan Pennell-Smith

Aug 06, 2015

When adding:
mCamera.restartCameraPreview();
or
CraftARSDK.getCamera().restartCameraPreview();

to the end of the onPostCreate it crashes the app with:

java.lang.NullPointerException: Attempt to invoke virtual method 'void cc.openframeworks.OFAndroidVideoGrabber.restartPreview()' on a null object reference
at com.craftar.ImplCraftARCameraOF.restartCameraPreview(ImplCraftARCameraOF.java:152)

We're not doing anything overly complex, just locking the app to landscape, is there any news on the SDK being updated to handle this correctly?

Thanks

Al
0 rated
( Agent )
Miquel Ferrarons

Aug 06, 2015

Hi Alan,

We will include this bugfix for the next release, expected to be in September/October.

Anyway, the trick of calling setRequestedOrientation() seems to be working fine for me, and I would like to know in which cases it’s not working. Below I’m pasting a sample snippet using finder mode (beware to not to consume your scans. I just did it using finder for simplicity).

Can you please test if this is working for you, without adding anything else? I’m testing in a Nexus 4, running Android 5.1.1.

public class SimpleMainActivity extends CraftARActivity implements CraftARResponseHandler{

	private final String TAG = "SimpleMainActivity";
	private final static String COLLECTION_TOKEN="your_collection_token";
	
	CraftARCloudRecognition mCloudRecognition;
	CraftARTracking mCraftARTracking;
	
	@Override
	public void onPostCreate() {
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		
		View mainLayout = (View) getLayoutInflater().inflate(R.layout.cameraonly_layout, null);
		CraftARCameraView cameraView = (CraftARCameraView) mainLayout.findViewById(R.id.camera_preview);
		setCameraView(cameraView);
		setContentView(mainLayout);
		
		//Initialize the SDK. From this SDK, you will be able to retrieve the necessary modules to use the SDK (camera, tracking, and cloud-recgnition)
		CraftARSDK.init(getApplicationContext(),this);
				
		//Setup the finder-mode: Note! PRESERVE THE ORDER OF THIS CALLS
		mCloudRecognition= CraftARSDK.getCloudRecognition();//Obtain the cloud recognition module
		//Obtain the tracking module
		mCraftARTracking = CraftARSDK.getTracking();
		
		//mCloudRecognition.setCRSConnect(new MyCRSConnect());//Set your connect class!
		mCloudRecognition.setResponseHandler(this); //Tell the cloud recognition who will receive the responses from the cloud
		mCloudRecognition.setCollectionToken(COLLECTION_TOKEN); //Tell the cloud-recognition which token to use from the finder mode
		mCloudRecognition.startFinding(); //Start the finder mode
	}
	
	@Override
	public void searchCompleted(ArrayList<CraftARItem> results) {
		Log.d("MainActivity","requestCompletedResponse");
		if(results.size()==0){
			Log.d(TAG,"Nothing found");
			return;
		}
		
		//Some item was found
		mCloudRecognition.stopFinding();
		for(CraftARItem item:results){
			if (item.isAR()) {
				Log.d(TAG,"Add AR item and start tracking");
				try {
					mCraftARTracking.addItem((CraftARItemAR)item);
					mCraftARTracking.startTracking();
				} catch (CraftARSDKException e) {
					e.printStackTrace();
				}
			}
			String text="Found item "+item.getItemName();
			Log.d(TAG,text);
			Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
		}	
	}
	
	
	@Override
	public void requestFailedResponse(int requestCode,
			CraftARCloudRecognitionError responseError) {
		Log.d(TAG,"requestFailedResponse:"+requestCode+" ,errorCode:"+responseError.getErrorCode()+":"+responseError.getErrorMessage());	
	}

	@Override
	public void connectCompleted(){}
}

Best,

Miquel.

0 rated
Alan Pennell-Smith

Aug 07, 2015

Hi Miquel,

Thanks for the example, ours was pretty much the same. I think we've cracked it now:
Seeing as the rest of the app is already landscape the setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); didn't seem to trigger the change.

So I removed screenOrientation="landscape" from the activity using CraftAR in the manifest, and added setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) to the onCreate, so the onPostCreate was registering it switch back to landscape. A bit hacky, but it seems to be consistently working now.

Thanks for you all your help

Al
1 rated
( Agent )
Miquel Ferrarons

Aug 07, 2015

Thanks Alan,

I forgot to tell you to remove the screenOrientation=“landscape” from the manifest, which was something necessary.

Glad it works now,

Thanks for your feedback,

Miquel.

0 rated

Post Your Public Answer

Your name (required)
Your email address (required)
Answer (required)

Couldn't find what you were looking for?

support@catchoom.com
https://cdn.desk.com/
false
catchoom
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete