Provides a full system to help you develop Android applications that have a free version and some commercial unlocking application. There is also the flexibility for implementing multiple features to be unlocked by various unlocker applications.
This whole tutorial assumes we want to create a free application published under the package name com.myapp
and an unlocker application published under the package name com.myapp.unlocker
.
- Create a library project for your application, that will be shared between your free application and the unlocker application. That project should depend on the library project you created in step 1.
- Create an application project for the unlocker. That project should depend on the library project you created in step 2.
- Create an application project for the free app. That project should depend on the library project you created in step 2.
This is the project that will contain the code needed to unlock the features in the free application and also the code that is needed to check if the unlock application is installed or not.
- Copy the
android-unlocker-library-1.0.0.jar
file into the libs folder. - Create a class
Configuration
in the packagecom.myapp.common
. You can take the sample class provided in the sample-common project. Make sure you replace thePACKAGE_NAME
constant with your free application's package name. In our casecom.myapp
. As authority, you can safely use your package name, but you can use anything you want. Just remember to change it accordingly in the UnlockerProvider class constructor and in the manifest file of the unlocker application. - Create an
UnlockerProvider
class in the packagecom.myapp.common.provider
that will handle the authorisations. You can take the sample class provided in the sample-common project. This class should extend theAuthorizationContentProvider
class. This is where you can define how features are made available or not.
That should be it for the code in common for the unlocker and the free application.
That one is easy. In fact the unlocker application is nothing more than some icons and a few lines in the AndroidManifest.xml
file. In that file, we request a permission to access the unlocker's content provider and we will also declare it so that it is available to our free application.
- Add the icons in the drawable folders as usual
- Name your application properly (usually automatically created in the strings.xml file)
- Declare a new permission in the manifest file. You can use the sample declaration from the sample-unlocker project. Just replace the
fr.marvinlabs.samples.unlocker.AUTHORIZATION_PROVIDER
string with your own. In our case, we will name itcom.myapp.AUTHORIZATION_PROVIDER
. - Add the content provider declaration within the
application
tag of the manifest file. You can use the sample declaration from the sample-unlocker project. Just replace thefr.marvinlabs.samples.unlocker.common.provider.SampleUnlockerProvider
string with your own. In our case, we will name itcom.myapp.common.provider.UnlockerProvider
and also replace thefr.marvinlabs.samples.unlocker.AUTHORIZATION_PROVIDER
string with your own. In our case, we will name itcom.myapp.AUTHORIZATION_PROVIDER
.
In the end, your manifest file should look like that:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.unlocker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<permission
android:name="com.myapp.AUTHORIZATION_PROVIDER"
android:protectionLevel="signature" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<provider
android:name="com.myapp.common.provider.UnlockerProvider"
android:authorities="com.myapp"
android:permission="com.myapp.AUTHORIZATION_PROVIDER" />
</application>
</manifest>
This will be where you will want to check if the user has installed the unlocker application. In order for that to work, you will need to:
- Request the permission to use the unlock content provider declared in the unlocker. This is done by adding a uses-permission tag in the
AndroidManifest.xml
file. You can use the sample declaration from the sample-locked project. Just replace the permission name with the one you declared in the unlocker project. In our case, we could add the line<uses-permission android:name="com.myapp.AUTHORIZATION_PROVIDER" />
within the manifest tag. That permission will not show up when the user installs the application because it is not a system-level permission, so no worries.
That's it, now you simply need to check whether the user has installed the unlocker application by using such code:
boolean isAuthorized = UnlockerProvider.getPackageLevelAuthorization(getContentResolver());
v1.0.0 (2013-09-19)
- Library project added
- Packaged as a JAR file
Copyright 2013 Vincent Mimoun-Prat
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- Get some more info and other Android tutorials on our blog: blog.marvinlabs.com
- Get to know what MarvinLabs does on our website: www.marvinlabs.com
- Follow us on social networks: