Start a new topic

Unable to open camera using SDK 7 Eample

Hi,


Using the example for SDK 7 on  Android Studio 2.3 


Was unable to open the camera although the code works with WIkitude Logo appearing.



Please see below.


public class MainActivity extends AppCompatActivity {

    public ArchitectView architectView;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        WebView.setWebContentsDebuggingEnabled(true);

        this.architectView = new ArchitectView(this);

 

        final ArchitectStartupConfiguration config = new ArchitectStartupConfiguration();

        config.setLicenseKey("EFJLYb9wI2tOR6s0aMqJA4DDaHD62u0+A1pPpwkp9PFJ10+3rt9qpaupxsvMbWCSmLSdyucaAcajvrVboBotifB68CVx1IUIDPa5bGyHlEhZiAc3Dk8PC6+E3BMILcVJVxBfNSB0l1mgXjSl3DMgoBLvZH3FMLOaxJN3IFXDRdxTYWx0ZWRfX8YjJhoSXu2jqlRsjr9weKL18fD4MIDgi//Ebo2KJ3G+195jucHz02Zkm/TQHqZ89/g/ae2Hvguu77gXMH43Z1Cp+Y9lhfRKE+d3FE6rU3fPoST07suxtFm6bBz0oVAWzqTiMrjDMnWEHu8oBHx845DwimzkFUGKKajCSSzgQGZbWsk0XQQinASKOzFlmL3vbBoTwcrjiFKrAHvSjB6IAJ1nFAmvvMMB5JEMwTzYLAGXujATpmCupQ4C1QjoW0NdV1o209ODBd001ahCZ1QBAILTnjP27Yn9Br7TvVa5mhefipmCGWitg2bIFiuLQfb0WnhQdJ7jIDVZq+Zle/vNnFbpJOa4FVPA+9jboc8qnhmhEQXDS4YxBS3gvLk2p99L84UVBe6OW0Inwf2Fzu080vOxPhRciOVURcNFv7cUjHZcip/LwojjmEaDAHtZdfVbgKz2P18f+t39JzeC8+j8cWvW8YizRZG+fjBU1ERVsZbSyFaTx9qn4mU=");

// config.setCameraPosition("back"); // The default camera is the first camera available for the system.

// config.setCameraResolution(sampleData.getCameraResolution()); // The default resolution is 640x480.

// config.setCameraFocusMode(sampleData.getCameraFocusMode()); // The default focus mode is continuous focusing.

// config.setCamera2Enabled(sampleData.isCamera2Enabled()); // The camera2 api is disabled by default (old camera api is used).

// config.setFeatures(sampleData.getArFeatures()); // This tells the ArchitectView which AR-features it is going to use, the default is all of them.

 

        this.architectView.onCreate( config );

        setContentView(architectView);

 

    }

    @Override

    protected void onPostCreate(@Nullable Bundle savedInstanceState) {

        super.onPostCreate(savedInstanceState);

        this.architectView.onPostCreate();

        try {

            //If authorisation not granted for camera

            if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)

                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 50);

 

            this.architectView.load( "01_ImageTracking_2_DifferentTargets/index.html" );

        } catch(Exception ex ) {

            ex.printStackTrace();

        }

    }

}








Hi,


As this post is dealing with SDK 7, please use the latest SDK version and provide the following details:


  • Which version of the SDK are you using?
  • Are you working with the JS API or the Native API?
  • Are you using any of our Extensions (Cordova, Xamarin, Unity)? If yes, which version are you using?
  • What Unity version are you using?
  • Is this happening with the sample app or in your own app? If it happens with your own app, does the sample app work on your device?
  • Did you make sure to follow the setup guide and also check the migration notes if you migrated from an older version?
  • Did you check the forum for other questions dealing with the same issue?


Thx and greetings


Nicola

Hello! 

I have the same problem with my android app. Black screen and wikitude logo only. I then have to go to my divice's settings to give permission but I don't like that. 

I added on the AndroidManifest the line 

<uses-feature android:name="android.hardware.camera" android:required="true" />

but I don't have any file in my project with the name MainActivity.java and I do not have good knowledge of coding.
Can you help me? I am using Unity with Wikitude.

hi YT,

I also face the problem with you. I can't access the camera permission. When I code the ArchitectView.onResume, my apps cannot be run. I don't know how to solve. Can you please help me?

Hi YT,


do you want to store the AR experience? 

You could maybe download the AR experience (the html + js + assets) store it and then use architectView.load with an absolute path to the file.


Best Regards,

Alex

Hi Alex, 


Thanks! Works great and thanks for the activity life cycle tip!


A few of my customers use AR as a sales tool and sometimes do not have access to wifi at the customers factory.  As such need to offer the option of storing the content in the cache after they have downloaded and viewed the content in a wifi environment.


Do you you have any tips as to how to realise this?


Also, should I be starting a new topic for item?


Thanks again!

YT




Hi YT,


the code you attached(MainActivity.java) is also missing the call to ArchitectView.onResume. 

You have to call onCreate/onPostCreate/onResume/onPause/onDestroy in the equivalent Activity lifecycle callback.


Best Regards,

Alex

Hi Alex,


Thanks.  Obviously my snippets are not too good.


But Yes, that is added.  And we can see the wikitude logo on the dark screen but unable to see the camera feed.


Attached is the for your perusal.


Thanks.


Regards


YT


java

Hi YT,


In the snippet you added to your question you are missing ArchitectView lifecycle calls. 

You have to call onCreate/onPostCreate/onResume/onPause/onDestroy in the equivalent Activity lifecycle callback.


Best Regards,

Alex

Hi Nicola,


Kindly find the fie attached.


Thanks!


YT

xml
Hi YT Ho,

Can you please also send the AndroidManifest.xml so we can check if the Permissions are correct?

Thx and greetings

Nicola


 

Hello YT Ho,

Please make sure that you have set the correct permissions in order to allow the camera to access your app. Have a look at the code inside the files AndroidManifest.xml and info.plist. Also, please follow our documentation section here.

Thanks
Eva

 

Login or Signup to post a comment