Android Question All good intentions

greydog

Member
Licensed User
Longtime User
Hi there,
I am trying to get my head around intents and how to use them. I have read the tutorial and understand what they do and roughly how to push them around. What I need to go is get this java code snippet I pinched off the internet to run

finalIntent intent =newIntent(Intent.ACTION_MAIN);
intent.setClassName("com.android.systemui","com.android.systemui.Somnambulator");
startActivity(intent);

This should start the daydream if I can get it working. Does anyone know what I need to do to file this intent?
Thanks
 

keirS

Well-Known Member
Licensed User
Longtime User
Try this:
B4X:
Dim oIntent As Intent
    oIntent.Initialize(oIntent.ACTION_MAIN,"")
    oIntent.SetComponent("com.android.systemui/.Somnambulator")
    StartActivity(oIntent)
 
Upvote 0

greydog

Member
Licensed User
Longtime User
Thank you very much, I am a very happy camper
Now if I could work out how to call a settings screen.... Problem for another day.
 
Upvote 0

greydog

Member
Licensed User
Longtime User
Hi there,
This works on a number of my Android boxes, but on some tablets and my phone the button returns an error "an error has occurred in sub: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.systemui.Somnambulator}; have you declared this activity in your AndroidManifest.xml?"
I have tried a number of ways of declaring it, but no luck. Do you have any ideas about how I should declare this, and why it works on some devices (with nothing special in the xml file) and not others ?
thanks
 
Upvote 0

greydog

Member
Licensed User
Longtime User
Nope, I am totally out of ideas. I have looked through all the example java programs I could find to start a daydream and none explicitly define anything in the manifest file for starting daydreams with the code above. Even a simple app with just a button with the code above will fail. I have it working fine on a android 4.4.2 virtual machine I have running on VirtualBox, but it will not execute on a "real" tablet or phone without throwing the error above. This is really frustrating me as it is the last bug I have to fix before I finish my program.....
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
I am not too familiar with the daydream feature but I have come across this error in my own apps. What versions of Android is on the devices it fails on? Could it simply be that the daydream feature is not available on those devices?

If that's the case then hopefully your app doesn't absolutely need it, otherwise you would have to determine when that feature became available (API level or Android version) and block the non-working devices in your Developer console.

As far as preventing the error:

B4X:
    Dim oIntent As Intent
    oIntent.Initialize(oIntent.ACTION_MAIN,"")
    oIntent.SetComponent("com.android.systemui/.Somnambulator")
    Try
         StartActivity(oIntent)
          Catch
              ToastMessageShow ("Failed to start DayDream!", True)
    End Try
 
Upvote 0

greydog

Member
Licensed User
Longtime User
Hi, thanks for that. Strangely enough if I change the button to bring up the daydream settings screen it works on all devices, but if I try and start the daydream it fails on some??? They are all android 4.3 or later so have daydream on them. I read somewhere the API was experimental and i have found lots of source code for somnambulator that are slightly different, so maybe different vendors have implemented it differently. For now I have just changed to button from starting the daydream to calling up the settings page the letting the user start it from there. If I ever work out how to do it I will update here.
Thanks for the help.
 
Upvote 0

greydog

Member
Licensed User
Longtime User
Yep, there is no difference I can see between them. One device it won't work on is my Samsung Note 3 phone with 4.4.2 installed on it?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…