Introduction and Background
My friend received a Samsung mobile phone few month ago. She liked it yet one thing that it doesn't have is the toolbox for fundamental utilities. One of them is the spotlight application that triggers the gadget to enact or deactivate the electric lamp as required. Android supports you having the Camera API devoured in your application (an electric lamp is given to photographs or recordings and not as a floodlight). Anyway, I was thinking that I ought to get an application from Play Store, correct? No! Despite the fact that it would give me an answer for my spotlight issue, shouldn't something be said about the barrage of ads I had to experience, or the hazy UI of the application? So I figured I should manufacture an application for her to have the capacity to trigger the spotlight on or off.
Since I made it for her, why not show you all as well, so you can utilize a similar application, or expand it and share it with me so I can likewise utilize your abilities.
In this article I will talk about Xamarin.Android for Camera API. In spite of the fact that this sort of use is exceptionally essential and straight-forward, at any rate it will furnish you with an extremely fundamental way of utilizing Camera API.
Pre-requisites
You are not required to have a an advanced understanding of Android APIs or how Linux functions, later authorizations and the rest will be discussed in the article. Be that as it may, I will attempt to ensure that I am as clear as an apprentice in this idea would need me to be.
Step 1
Create/ open your Android solution in Visual Studio or Xamarin Studio. Select Android and from list choose Android Blank App.
Step 2
First of all, in References add a reference Xamarin.Android.Support.v7. AppCompat using NuGet Package Manager, as shown below.
Step 3
After Successful Installation of AppCompat, add an XML File in values Folder with name style. In this file add some Code Theme Colors, as shown below.
(Folder Name: values, File Name: style.xml)
XML Code
- <?xml version="1.0" encoding="utf-8" ?>
- <resources>
- <style name="MyTheme" parent="MyTheme.Base">
- </style>
- <!--Base theme applied no matter what API-->
- <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
- <item name="windowNoTitle">true</item>
- <!--We will be using the toolbar so no need to show ActionBar-->
- <item name="windowActionBar">false</item>
- <!--Set theme color from http://www.google.com/design/spec/style/color.html#color-co-->
- <!--Color Primary is used for default action bar backround-->
- <item name="colorPrimary">#009688</item>
- <!--Color Primary Dark is use for status bar-->
- <item name="colorPrimaryDark">#1976D2</item>
- <!--ColorAccent is used as the default value for
- ColorControlActivated which is used to tint widgts-->
- <item name="colorAccent">#FF4081</item>
- <item name="colorControlHighlight">#FF4081</item>
- <!--You can also set ColorControlNormal ColorControlActivated
- ColorControlHihglight colorSwitchThumbNormal.-->
- </style>
- </resources>
Step 4
Now, add a new Folder in Resources Folder with name values-v21. In values-v21 Folder Add a new XML file with name style and insert some Code for Theme Properties, as shown below.
(Folder Name: values-v21, File Name: style.xml)
XML Code
- <?xml version="1.0" encoding="utf-8" ?>
- <resources>
- <!--
- Base Application theme for API 21+. this theme
- replaces MyTheme from res/style.xml on API 21+ devices-->
- <style name="MyTheme" parent="MyTheme.Base">
- <item name="android:windowContentTransitions">true</item>
- <item name="android:windowAllowEnterTransitionOverlap">true</item>
- <item name="android:windowAllowReturnTransitionOverlap">true</item>
- <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
- <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
- <item name="android:windowTranslucentStatus">true</item>
- </style>
- </resources>
Step 5
In drawable Folder add Two Images with Name light_off and light_on that I attached with article files with name Images.zip.
(Folder Name: drawable)
(Files Name: light_off, light_on)

Step 6
Now add another Folder in Resources Folder with the name raw, and in this Folder Click Button Sound with name sound_click that I attached. With name sound_click.zip you can download from this article files.
(Folder Name: raw)
(Files Name: sound_click)

Step 7
In Main,axml add this Code for ImageView and Toolbar, as shown below.
(Files Name: Main.axml)
XML Code
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:local="http://schemas.android.com/apk/res-auto"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <android.support.v7.widget.Toolbar
- android:layout_margin="10dp"
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="?attr/actionBarSize"
- android:background="?attr/colorPrimary"
- android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
- local:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="center">
- <ImageView
- android:id="@+id/imageView"
- android:layout_gravity="center"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:src="@drawable/power_off" />
- </LinearLayout>
- </LinearLayout>




Tan JuiPosted Mar 10, 2018, 1:50 AM
Hi, I have this error consistently when i try to do step 2. I am running Visual Studio 2017 v15.6.1 Error Could not install package 'Xamarin.Android.Support.v4 21.0.0'. You are trying to install this package into a project that targets 'native,Version=v0.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. 0