Start a new topic

Fail to connect to camera service

Fail to connect to camera service

1 person has this problem


Hi,

I've created an Android library project with a custom Fragment implementing the Wikitude SDK. I've added the library to an Android application Project which is working fine. Everything works fine and the Wikitude startup screen appears, but when this.architectView.onCreate(architectConfig); gets called. The system throws an exception:


04-01 13:03:25.242: D/ArchitectView(7748): Exception while getting Camera Parameters

04-01 13:03:25.242: D/ArchitectView(7748): java.lang.RuntimeException: Fail to connect to camera service

04-01 13:03:25.242: D/ArchitectView(7748): at android.hardware.Camera.native_setup(Native Method)

04-01 13:03:25.242: D/ArchitectView(7748): at android.hardware.Camera.<init>(Camera.java:343)

04-01 13:03:25.242: D/ArchitectView(7748): at android.hardware.Camera.open(Camera.java:318)

04-01 13:03:25.242: D/ArchitectView(7748): at com.wikitude.architect.ArchitectView.a(Unknown Source)

04-01 13:03:25.242: D/ArchitectView(7748): at com.wikitude.architect.ArchitectView.<init>(Unknown Source)

04-01 13:03:25.242: D/ArchitectView(7748): at java.lang.reflect.Constructor.constructNative(Native Method)

04-01 13:03:25.242: D/ArchitectView(7748): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)

04-01 13:03:25.242: D/ArchitectView(7748): at android.view.LayoutInflater.createView(LayoutInflater.java:594)

04-01 13:03:25.242: D/ArchitectView(7748): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)

04-01 13:03:25.242: D/ArchitectView(7748): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)

04-01 13:03:25.242: D/ArchitectView(7748): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)

04-01 13:03:25.242: D/ArchitectView(7748): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

04-01 13:03:25.242: D/ArchitectView(7748): at com.infosupport.isca_ar.ARFragment.onCreateView(ARFragment.java:31)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.Fragment.performCreateView(Fragment.java:1695)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:861)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1137)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.Activity.onCreateView(Activity.java:4746)

04-01 13:03:25.242: D/ArchitectView(7748): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)

04-01 13:03:25.242: D/ArchitectView(7748): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)

04-01 13:03:25.242: D/ArchitectView(7748): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)

04-01 13:03:25.242: D/ArchitectView(7748): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

04-01 13:03:25.242: D/ArchitectView(7748): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)

04-01 13:03:25.242: D/ArchitectView(7748): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.Activity.setContentView(Activity.java:1895)

04-01 13:03:25.242: D/ArchitectView(7748): at com.infosupport.isca_ar_test.MainFragment.onCreate(MainFragment.java:12)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.Activity.performCreate(Activity.java:5133)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.ActivityThread.access$600(ActivityThread.java:141)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)

04-01 13:03:25.242: D/ArchitectView(7748): at android.os.Handler.dispatchMessage(Handler.java:99)

04-01 13:03:25.242: D/ArchitectView(7748): at android.os.Looper.loop(Looper.java:137)

04-01 13:03:25.242: D/ArchitectView(7748): at android.app.ActivityThread.main(ActivityThread.java:5103)

04-01 13:03:25.242: D/ArchitectView(7748): at java.lang.reflect.Method.invokeNative(Native Method)

04-01 13:03:25.242: D/ArchitectView(7748): at java.lang.reflect.Method.invoke(Method.java:525)

04-01 13:03:25.242: D/ArchitectView(7748): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)

04-01 13:03:25.242: D/ArchitectView(7748): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

04-01 13:03:25.242: D/ArchitectView(7748): at dalvik.system.NativeStart.main(Native Method)

 

I've added permissions and features to both Manifest files:


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.location" android:required="true" />
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<uses-feature android:name="android.hardware.sensor.compass" android:required="true" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

My Fragment code:
public class ARFragment extends Fragment{

private ArchitectView architectView;

public ARFragment()
{

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) 
{
return (FrameLayout)inflater.inflate(R.layout.arview, container, false);
}

@Override
public void onActivityCreated (Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);    
this.architectView = (ArchitectView)getView().findViewById(R.id.architectView);
final ArchitectConfig architectConfig = new ArchitectConfig("");
this.architectView.onCreate(architectConfig);
}
}



What am I doing wrong?

Thanks in advance.

 

Hi,

my first guess is that the camera is already in use, and the ArchitectView cannot open it.

But we also have other known problems with low-end and older (Android 2.3.x) devices, which are solved in the new SDK version to be released soon.

Please let me know:

- does your application use the camera before starting the AR experience?

- on which device are you currently testing the app?

Thanks.

Hi,

Thanks for your answer.

There is no other code in the application yet, so the camera isn't used.
I'm testing on a Galaxy Nexus with Android 4.3 .

I can e-mail you the projects if that's easier for you.

I'm trying to reproduce the issue, could you post your manifest file?

This is the project Manifest:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.pkg?

    android:versionCode="1"

    android:versionName="1.0" >

   

   <uses-sdk

        android:minSdkVersion="15"

        android:targetSdkVersion="19" />

   

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <uses-permission android:name="android.permission.ACCESS_GPS" />

    <uses-permission android:name="android.permission.CAMERA" />

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    

    <!-- Tell the system this app requires OpenGL ES 2.0. -->

    <uses-feature android:glEsVersion="0x00020000" android:required="true" />

    

<!-- rear facing cam -->

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

 

<!-- users location -->

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

 

<!-- accelerometer -->

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

 

<!-- compass -->

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

 

<!-- do not support small resolution screens -->

<supports-screens

android:smallScreens="false" android:largeScreens="true"

android:normalScreens="true" android:anyDensity="true" 

android:xlargeScreens="true" />

 

    <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity

            android:name="com.pkg.MainFragment"

            android:label="@string/app_name"

            android:configChanges="orientation|keyboardHidden|screenSize" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

 

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

     </application>

</manifest>

 

This is the Manifest of the library:


<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.libar"

    android:versionCode="1"

    android:versionName="1.0" >

 

    <uses-sdk

        android:minSdkVersion="15"

        android:targetSdkVersion="19" />

    

   <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <uses-permission android:name="android.permission.ACCESS_GPS" />

    <uses-permission android:name="android.permission.CAMERA" />

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    

    <!-- Tell the system this app requires OpenGL ES 2.0. -->

    <uses-feature android:glEsVersion="0x00020000" android:required="true" />

    

<!-- rear facing cam -->

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

 

<!-- users location -->

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

 

<!-- accelerometer -->

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

 

<!-- compass -->

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

 

<!-- do not support small resolution screens -->

<supports-screens

android:smallScreens="false" android:largeScreens="true"

android:normalScreens="true" android:anyDensity="true" 

android:xlargeScreens="true" />

 

    <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

    </application>

 

</manifest>

 

Did you manage to reproduce the problem? I can e-mail you the Eclipse projects if that's easier for you.

I solved the problem, but still don't know what the problem really was.
I did exactly the same coding, but this time on a Windows computer instead of a Mac.

 

Good to know.

I tried your permission with the sample app, and everything was Ok.

I would suggest that you upgrade to the new SDK version anyway (3.3), which will be released very soon.

Hi,

I'm facing the same problem right now with som Marshmallow devices or randomly, but it's not my purpose to genrate an app running randomly!

Here's my code for the onCreate() in MainActivity called from CustomMainActivity wich extends MainActivity

final StartupConfiguration configuration = new StartupConfiguration(wikitudeAPIKey);
this.architectView.onCreate(configuration);

 

I haven't forget the onResume method :

@Override
protected void onResume() {
super.onResume();
Log.d("action", "resumed");
this.architectView.onResume();
}

 

And the wirdest thing is that i run the app just after boot so no other app use the camera !

Any idea? 

Thanks for helping

Hi Thibaud,

could you please elaborate a little further on what devices you have this problem? Does it only happen on Marshmallow or lower OS versions too?

Best regards,
Simon

Hi Simon,

I'm working on a Moto X with Lollipop where it's works fine and on two others : Nexus 5 and Nexus 9 both running Marshmallow.

The wird thing is that a version of my app worked fine on the nexus 5 and the problem appeared when I uninstall the app and installed it again. But on the nexus 9 never worked.

the error thar occurs on the Activity's onCreate() method with the architectView.oncreate(configuration); so I tried to run it on a try catch as :

try {
this.architectView.onCreate(configuration);
} catch (RuntimeException re) {
re.printStackTrace();
}


 

but the onPostCreate throws another error saying "cannot run onResume if onCreate is not set before so I wrote this code:

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
try {
this.architectView.onPostCreate();
} catch (RuntimeException re){
re.printStackTrace();
this.architectView.onCreate(getResources().getString(R.string.api_key_wikitude_trial));
this.architectView.onPostCreate();
}

try {
this.architectView.load("wikitude/sample/index.html");
} catch (IOException e) {
e.printStackTrace();
} catch (ArchitectView.CamNotAccessibleException camException) {
camException.printStackTrace();
}
}

 

I use also Facebook SDK that is initialized after the architect onCreate method.

Here is my full architect setup:

this.architectView.registerWorldLoadedListener(new ArchitectView.ArchitectWorldLoadedListener() {
@Override
public void worldWasLoaded(String s) {
canScan = true;
tapToScan.setVisibility(View.VISIBLE);
}

@Override
public void worldLoadFailed(int i, String s, String s1) {
Log.d("info", "world loading failed");
}
});
this.architectView.registerUrlListener(this);
Log.d("wikitude key", getResources().getString(R.string.api_key_wikitude));
String wikitudeAPIKey = getResources().getString(R.string.api_key_wikitude_trial);
final StartupConfiguration configuration = new StartupConfiguration(wikitudeAPIKey);
try {
this.architectView.onCreate(configuration);
} catch (RuntimeException re) {
re.printStackTrace();
}

 

Here is other Activity running methods:

@Override
protected void onPause() {
super.onPause();
Log.d("action", "onPause");
this.architectView.onResume();
this.architectView.onPause();
AppEventsLogger.deactivateApp(this); //FB
}

@Override
protected void onResume() {
super.onResume();
Log.d("action", "resumed");
this.architectView.onResume();
AppEventsLogger.activateApp(this); /FB
}

@Override
protected void onDestroy() {
super.onDestroy();
this.architectView.onDestroy();
profileTracker.stopTracking();//FB
}

 

I found the problem:

Since Marshmallow ( Android 6.0 API 23) the OS let user choose which permission for the app. 

To proper use Wikitude we need to access Camera, so if user forbid acces to the camera we can't get Camera service it's linked.

So when I uninstall/reinstall the app Android suppress all permissions including Camera!

I will find a way to search if app camera parameter is allowed by user and if not ask him to activate it, but I think for the next SDK of Wikitude I guess i could be great to add these feature to the managment of architectView as in isDeviceSupported() method cause for the moment this method include just the fact that a camera hardware is present.

If i found the way to ask user to activate permission on start I will publish it ;)

Hi Thibaud,

you beat me to it. I was just about to write you about that too. For a quick fix you can switch your compile and target sdk version to 22 or lower. 

I will investigate this further and look for a convenient way to integrate it into the SDK/Example Application.

If you need to stay on sdk 23 I found a good article on how to implement the permission feature here: http://www.captechconsulting.com/blogs/runtime-permissions-best-practices-and-how-to-gracefully-handle-permission-removal

I'm very sorry about this issue.

Thank you and best regards,
Simon

Don't be sorry, It's normal from Android to add this feature for actual and future versions, it's normal too to let user choose his permission.

Now we know and we can go with it.

I stayed with 23 and did a job as I said that's work , I forbid acces to ArchitectActivity if user is 23 or above and hasn't got his camera permission OK

 

Thanks for helping

Hi Thibaud,

I'm glad you found a solution so quickly. Thank you for pointing out this issue.

Best regards,
Simon
Login or Signup to post a comment