isUserAGoat()

From Lollipop was introduced the concept of Device Owner, a sort of super-user with high privileges (not like the system root btw).
As Device Owner you can use methods in the DevicePolicyManager class to take fine-grain control of the configuration, security, and apps on managed devices.
Among the various methods you can find

addUserRestriction(ComponentName admin, String key)

that allow you to set some very interesting restrictions to your app user, for example:

- DISALLOW_ADD_USER: Specifies if a user is disallowed from adding new users and profiles
- DISALLOW_INSTALL_APPS: Specifies if a user is disallowed from installing applications.
- DISALLOW_FACTORY_RESET: Specifies if a user is disallowed from factory resetting from Settings.

… and many more…
If you wanna try I’ve assembled a very simple app-example with all the User Restrictions actually available, you can find it on my github page 🙂

Screen Shot 2016-01-31 at 17.58.06
Moreover there is a restriction kinda strange on the documentation:

- DISALLOW_FUN: Specifies if the user is not allowed to have fun.

Now this mean that someway someone has defined what is “fun” on the device!!
I’m really curious about that, need to try in next days on a device with Marshmallow installed 😉
Oh right, about the post title, UserManager class give you another beautiful method:

boolean isUserAGoat()

Used to determine whether the user making this call is subject to teleportations.
Android Os … so so powerful!

ps: If you want to try the code you need to assign Device Owner privileges to the apps, for doing this you need to be sure that on the device (or simulator) there is no google account active, open a terminal and digit

adb shell

then for assigning the device owner privileges type:

dpm set-device-owner it.paolomoschini.usermanagerrestrictions/it.paolomoschini.usermanagerrestrictions.receiver.MyDeviceAdminReceiver

Trying Vuforia with Android Studio

So you have heard of Augmented Reality (AR) and all the coolness you can do with it, you wanna try right?
There are a lot of AR engines out there but one of the best you can put the “dirty” hands on is Qualcomm Vuforia.
First of all you need to create an account on the developer page, after that you can login and go to the “Download” section.

20151117_img0
As you can see the SDK is available for Android, iOS and Unity, please notice also on the submenu items “Samples” and “Tools” we’re going to use them a bit later.
Proceed to download the SDK for Android (at the time of writing is avaible the version 5), unzip the content and take a look inside, the “build” folder is the interesting one,
infact it contains the library Vuforia.jar and the compiled engine libVuforia.so
You have seen the “Sample” directory right but it’s empty, so what?
As the readme.txt reports you need to download the examples from https://developer.vuforia.com/resources/sample-apps but the links is broken … the correct one is https://developer.vuforia.com/downloads/samples
From the above page you need to download, in the “Core Features” section, the Vuforia Sample Core for Android, check the page there are a lot of material here: Digital Eyewear examples (Google Carboard rules!), Advanced Topics, Best Practice and Vuforia Web Services.
Unzip Vuforia Samples, we’ll use the extracted folder as base for our test, open Android Studio and choose “Import project”, select the Vuforia Samples folder, set an Import Destination Directory, keeps all the import options, you have to set Vuforia.jar path edit the field with the location of Vuforia.jar contained in the SDK previously downloaded (Ex /Users/paolo/Downloads/vuforia-sdk-android-5-0-5/build/java/vuforia), click on Finish.
Android Studio should have imported the project, but there are a lot of errors related to unknow classes (Vuforia classes!), these because Vuforia.jar is not in the correct location.

20151117_img6
You need to create a “libs” folder in “app” folder of your project and move Vuforia.jar file from the /your_project_path/VuforiaSampleProject/app/src/main/java/Vuforia.jar to “libs” folder.
Now you need to modify your module build.gradle (not the project one!) file, add these lines at the end:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

Sync the project with gradle, voilà errors are gone!

Build and run the project on your device, you should see something like this

20151117_img1

Try selecting Image Targets … arghhh nothing happens, we have to do 2 more things 😉
Project needs also libVuforia.so, an easy way to import this file in your project is create a zip from the “lib” folder from the Vuforia SDK folder:
20151117_img2
now move lib.zip in the “libs” folder of your project (the one that contains Vuforia.jar), rename lib.zip in lib.jar, recompile and run the project, select Image Targets:
20151117_img3
Ok told you, one last effort, the vuforia App key!

Open Vuforia developer portal page, go in Develop section, and click on Add License Key button, choose a name for the license (Ex. VuforiaSamples), select “Mobile” Device and “Starter – No Charge” License Key, confirm the data, you will receive an email related to Vuforia Application License Key.
Good! Select and copy the license created
20151117_img4
We need to paste the vuforia license in our example code, select SampleApplicationSession.java, find the inner class InitVuforiaTask, inside the method Vuforia.setInitParameters(Activity activity, int flags, String licenseKey) paste your code.

20151117_img7
Recompile & run your project, try for the last time and … fingers crossed, it works!
Ok, we need a marker (an image that is recognized from this sample, for the Image Targets we need Stones, Chips or Tarmac), all these images and others are in “media” folder inside the “Vuforia Samples“.
20151117_img5
Cool! 🙂

Final considerations
Try all the Vuforia samples, move on the advanced ones, you will find a lot to learn and to play with 🙂

Happy coding!

p.s. I’ve uploaded in my github page a Vuforia Samples project for Android studio for testing. Please remember to add the Vuforia license code 😉

0

public static void main(String[] args) {
    System.out.println("Hello World!");
}