Monday, January 5, 2015

Disable Camera on Android Devices

I have been going through forums and blogs where developers queried about disabling camera on android devices. Its pretty much easy. Here is how.

You need to use Device Admin privileges to have the rights to disable the camera. Remember that once an app is registered as Device Admin, it can only be uninstalled if the permissions from Device Admin (Settings section on your android device) is given.

1. Make a class (e.g. DevicePolicyActivity) and extend Activity
1.1 . Make another class  (e.g. AndroidDeviceAdminReceiver) and extend DeviceAdminReceiver

2. Make two variables like...

    DevicePolicyManager devicePolicyManager;
    ComponentName demoDeviceAdmin;

3. Initialize the variables above in onCREATE function like....
           devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

        demoDeviceAdmin = new ComponentName(this, AndroidDeviceAdminReceiver.class);

4. Now, add disable camera function against your button press or checkbox function as...

      devicePolicyManager.setCameraDisabled(demoDeviceAdmin, false);

5. Now, add Intent to your class like...

   private void activateDevicePolicyAdmin() {
        Intent intent = new Intent(
                DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                demoDeviceAdmin);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                "Organization Policy ");
        startActivityForResult(intent, ACTIVATION_REQUEST);
    }

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case ACTIVATION_REQUEST:
                if (resultCode == Activity.RESULT_OK) {
                    Log.i(TAG, "Administration enabled!");
                } else {
                    Log.i(TAG, "Administration enable FAILED!");
                }
                return;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

6. Put this in your Android Manifest file (if using Netbeans, its under Important Files section)

        <receiver
            android:name=".AndroidDeviceAdminReceiver"
            android:permission="android.permission.BIND_DEVICE_ADMIN" >
            <intent-filter>

                <!-- This action is required -->
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            </intent-filter>

            <!-- This is required this receiver to become device admin component. -->
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin" />
        </receiver>

7. The XML file (device_admin.xml) must mention the privleges that you want to use...

<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-policies>
               <disable-camera />
        </uses-policies>
</device-admin>


Here is your app for Disabling Camera in 7 easy steps. If you fail to understand any part, m round the corner!


Wednesday, November 12, 2014

Netbeans & Android - Step by Step Tutorial

Recently, I have been given an assignment to develop android application. Since, It was my first time to actually have a taste of it so I googled alot! But in all seriousness, I couldn't get hands on Netbeans and Android tutorial for beginners. So, I am going to help you with whatever I learned these past few days. I will write down steps for now. Pictorial tutorial will be uploaded later.

1) Download & Install Android SDK (Stand-alone version)

Remember, the android SDK only installs the basic tools and nothing for development. You can't even run an emulator after installing SDK. For development and emulator, follow further steps.
 
2) Run SDK Manager. You will come across various APIs and Tools by Android. Download what's your need. Here are the basic options that you can use to start developing.

SDK Manager

3) If you have Netbeans installed. Then go to next step. Else download & install from HERE

4) Start Netbeans. You will be needing NBAndroid package to start android development in Netbeans. There are two steps (online and offline) to get NBAndroid on your machine.
OR

5) Once done, you will now set ANDROID SDK location in Netbeans. Follow this..
  •             Tools -> Options -> Miscellaneous -> Android -> Enter SDK Location -> OK
6) You are now ready for Android Development. Follow these for your new android Project
  •  File -> New Project -> You will find ANDROID in categories -> Select Android Project -> Write Project Name -> Write package name e.g. com.android.test.app -> Write Activity Name (Its your MAIN) -> Select Target -> OK
DONE!!! 

Feel free to comment. I will write about first project in next post.

Saturday, February 22, 2014

[Solved] Signer Cetificate Warning

If you find out warnings related to Signer Certificate that will expire in 6 months and you get worried. Worry not!! Here is what you should do to dust it off!


Right-click project and go to Properties


Uncheck 'Request Unrestricted Access' and Press OK!