added sample code for Android networking recipes

This commit is contained in:
Nathan Castle 2015-06-29 07:35:46 -04:00
Родитель c0a66a5534
Коммит 6212945695
78 изменённых файлов: 1670 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +0,0 @@
Networking Recipes
===============

Просмотреть файл

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendEmail", "SendEmail\SendEmail.csproj", "{F1CC7D8D-7763-4495-9BCA-EE8A54FABD72}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F1CC7D8D-7763-4495-9BCA-EE8A54FABD72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1CC7D8D-7763-4495-9BCA-EE8A54FABD72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1CC7D8D-7763-4495-9BCA-EE8A54FABD72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1CC7D8D-7763-4495-9BCA-EE8A54FABD72}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = SendEmail\SendEmail.csproj
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,42 @@
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace SendEmail
{
[Activity (Label = "SendEmail", MainLauncher = true)]
public class Activity1 : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);
button.Click += delegate {
var email = new Intent (Android.Content.Intent.ActionSend);
email.PutExtra(Android.Content.Intent.ExtraEmail, new string[]{"person1@xamarin.com", "person2@xamrin.com"});
email.PutExtra(Android.Content.Intent.ExtraCc, new string[]{"person3@xamarin.com"});
email.PutExtra(Android.Content.Intent.ExtraSubject, "Hello Email");
email.PutExtra(Android.Content.Intent.ExtraText, "Hello from Xamarin.Android!");
email.SetType("message/rfc822");
StartActivity(email);
};
}
}
}

Просмотреть файл

@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".
These files will be deployed with you package and will be accessible using Android's
AssetManager, like this:
public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
InputStream input = Assets.Open ("my_asset.txt");
}
}
Additionally, some Android functions will automatically load asset files:
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="SendEmail.SendEmail">
<uses-sdk />
<application android:label="SendEmail">
</application>
</manifest>

Просмотреть файл

@ -0,0 +1,28 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Android.App;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("SendEmail")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("mike_bluestein")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.0")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

Просмотреть файл

@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.
For example, a sample Android app that contains a user interface layout (main.axml),
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
would keep its resources in the "Resources" directory of the application:
Resources/
drawable/
icon.png
layout/
main.axml
values/
strings.xml
In order to get the build system to recognize Android resources, set the build action to
"AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called "R"
(this is an Android convention) that contains the tokens for each one of the resources
included. For example, for the above Resources layout, this is what the R class would expose:
public class R {
public class drawable {
public const int icon = 0x123;
}
public class layout {
public const int main = 0x456;
}
public class strings {
public const int first_string = 0xabc;
public const int second_string = 0xbcd;
}
}
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
to reference the layout/main.axml file, or R.strings.first_string to reference the first
string in the dictionary file values/strings.xml.

Просмотреть файл

@ -0,0 +1,112 @@
#pragma warning disable 1591
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 4.0.30319.17020
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
[assembly: Android.Runtime.ResourceDesignerAttribute("SendEmail.Resource", IsApplication=true)]
namespace SendEmail
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
public partial class Resource
{
static Resource()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
public static void UpdateIdValues()
{
}
public partial class Attribute
{
static Attribute()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Attribute()
{
}
}
public partial class Drawable
{
// aapt resource value: 0x7f020000
public const int Icon = 2130837504;
static Drawable()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Drawable()
{
}
}
public partial class Id
{
// aapt resource value: 0x7f050000
public const int myButton = 2131034112;
static Id()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Id()
{
}
}
public partial class Layout
{
// aapt resource value: 0x7f030000
public const int Main = 2130903040;
static Layout()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Layout()
{
}
}
public partial class String
{
// aapt resource value: 0x7f040001
public const int app_name = 2130968577;
// aapt resource value: 0x7f040000
public const int buttonText = 2130968576;
static String()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private String()
{
}
}
}
}
#pragma warning restore 1591

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.5 KiB

Просмотреть файл

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/buttonText"
/>
</LinearLayout>

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="buttonText">Send an email</string>
<string name="app_name">SendEmail</string>
</resources>

Просмотреть файл

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F1CC7D8D-7763-4495-9BCA-EE8A54FABD72}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>SendEmail</RootNamespace>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidResgenClass>Resource</AndroidResgenClass>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AssemblyName>SendEmail</AssemblyName>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
</ItemGroup>
<ItemGroup>
<Compile Include="Activity1.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Main.axml" />
<AndroidResource Include="Resources\values\Strings.xml" />
<AndroidResource Include="Resources\drawable\Icon.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,3 @@
This is the sample code for the Android recipe for sending email.
[See the recipe at developer.xamarin.com](http://developer.xamarin.com/recipes/android/networking/email/send_an_email)

Просмотреть файл

@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".
These files will be deployed with your package and will be accessible using Android's
AssetManager, like this:
public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
InputStream input = Assets.Open ("my_asset.txt");
}
}
Additionally, some Android functions will automatically load asset files:
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");

Просмотреть файл

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1E7001B0-B735-404F-A8E3-E6197D62C773}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>GetMobileNetworkStrength</RootNamespace>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<AssemblyName>GetMobileNetworkStrength</AssemblyName>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;__MOBILE__;__ANDROID__;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<ConsolePause>false</ConsolePause>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<DefineConstants>__MOBILE__;__ANDROID__;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
</ItemGroup>
<ItemGroup>
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GsmSignalStrengthListener.cs" />
<Compile Include="MainActivity.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Main.axml" />
<AndroidResource Include="Resources\values\Strings.xml" />
<AndroidResource Include="Resources\drawable\Icon.png" />
<AndroidResource Include="Resources\drawable\gsm_signal_strength.xml" />
<AndroidResource Include="Resources\drawable-mdpi\gms_fair_dr.png" />
<AndroidResource Include="Resources\drawable-mdpi\gms_good_dr.png" />
<AndroidResource Include="Resources\drawable-mdpi\gms_none_dr.png" />
<AndroidResource Include="Resources\drawable-mdpi\gms_poor_dr.png" />
<AndroidResource Include="Resources\drawable-hdpi\gms_fair_dr.png" />
<AndroidResource Include="Resources\drawable-hdpi\gms_good_dr.png" />
<AndroidResource Include="Resources\drawable-hdpi\gms_none_dr.png" />
<AndroidResource Include="Resources\drawable-hdpi\gms_poor_dr.png" />
<AndroidResource Include="Resources\drawable-xhdpi\gms_fair_dr.png" />
<AndroidResource Include="Resources\drawable-xhdpi\gms_good_dr.png" />
<AndroidResource Include="Resources\drawable-xhdpi\gms_none_dr.png" />
<AndroidResource Include="Resources\drawable-xhdpi\gms_poor_dr.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup>
<Folder Include="Resources\drawable-mdpi\" />
<Folder Include="Resources\drawable-hdpi\" />
<Folder Include="Resources\drawable-xhdpi\" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetMobileNetworkStrength", "GetMobileNetworkStrength.csproj", "{1E7001B0-B735-404F-A8E3-E6197D62C773}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1E7001B0-B735-404F-A8E3-E6197D62C773}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E7001B0-B735-404F-A8E3-E6197D62C773}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E7001B0-B735-404F-A8E3-E6197D62C773}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E7001B0-B735-404F-A8E3-E6197D62C773}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = GetMobileNetworkStrength.csproj
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,23 @@
using Android.Telephony;
namespace GetMobileNetworkStrength
{
public class GsmSignalStrengthListener : PhoneStateListener
{
public delegate void SignalStrengthChangedDelegate(int strength);
public event SignalStrengthChangedDelegate SignalStrengthChanged;
public override void OnSignalStrengthsChanged(SignalStrength newSignalStrength)
{
if (newSignalStrength.IsGsm)
{
if (SignalStrengthChanged != null)
{
SignalStrengthChanged(newSignalStrength.GsmSignalStrength);
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,55 @@
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Telephony;
using Android.Widget;
namespace GetMobileNetworkStrength
{
[Activity(Label = "GetMobileNetworkStrength", MainLauncher = true)]
public class MainActivity : Activity
{
Button _getGsmSignalStrengthButton;
TelephonyManager _telephonyManager;
GsmSignalStrengthListener _signalStrengthListener;
ImageView _gmsStrengthImageView;
TextView _gmsStrengthTextView;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
// Get a reference to the TelephonyManager and instantiate the GsmSignalStrengthListener.
// These will be used by the Button's OnClick event handler.
_telephonyManager = (TelephonyManager)GetSystemService(Context.TelephonyService);
_signalStrengthListener = new GsmSignalStrengthListener();
_gmsStrengthTextView = FindViewById<TextView>(Resource.Id.textView1);
_gmsStrengthImageView = FindViewById<ImageView>(Resource.Id.imageView1);
_getGsmSignalStrengthButton = FindViewById<Button>(Resource.Id.myButton);
_getGsmSignalStrengthButton.Click += DisplaySignalStrength;
}
void DisplaySignalStrength(object sender, EventArgs e)
{
_telephonyManager.Listen(_signalStrengthListener, PhoneStateListenerFlags.SignalStrengths);
_signalStrengthListener.SignalStrengthChanged += HandleSignalStrengthChanged;
}
void HandleSignalStrengthChanged(int strength)
{
// We want this to be a one-shot thing when the button is pushed. Make sure to unhook everything
_signalStrengthListener.SignalStrengthChanged -= HandleSignalStrengthChanged;
_telephonyManager.Listen(_signalStrengthListener, PhoneStateListenerFlags.None);
// Update the UI with text and an image.
_gmsStrengthImageView.SetImageLevel(strength);
_gmsStrengthTextView.Text = string.Format("GSM Signal Strength ({0}):", strength);
}
}
}

Просмотреть файл

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="GetMobileNetworkStrength.GetMobileNetworkStrength">
<uses-sdk android:targetSdkVersion="21" android:minSdkVersion="21" />
<application android:label="GetMobileNetworkStrength">
</application>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

Просмотреть файл

@ -0,0 +1,22 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Android.App;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("GetMobileNetworkStrength")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.0")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

Просмотреть файл

@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.
For example, a sample Android app that contains a user interface layout (main.axml),
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
would keep its resources in the "Resources" directory of the application:
Resources/
drawable/
icon.png
layout/
main.axml
values/
strings.xml
In order to get the build system to recognize Android resources, set the build action to
"AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called "R"
(this is an Android convention) that contains the tokens for each one of the resources
included. For example, for the above Resources layout, this is what the R class would expose:
public class R {
public class drawable {
public const int icon = 0x123;
}
public class layout {
public const int main = 0x456;
}
public class strings {
public const int first_string = 0xabc;
public const int second_string = 0xbcd;
}
}
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
to reference the layout/main.axml file, or R.strings.first_string to reference the first
string in the dictionary file values/strings.xml.

136
android/networking/gsm_strength/Resources/Resource.designer.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,136 @@
#pragma warning disable 1591
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 4.0.30319.17020
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
[assembly: Android.Runtime.ResourceDesignerAttribute("GetMobileNetworkStrength.Resource", IsApplication=true)]
namespace GetMobileNetworkStrength
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
public partial class Resource
{
static Resource()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
public static void UpdateIdValues()
{
}
public partial class Attribute
{
static Attribute()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Attribute()
{
}
}
public partial class Drawable
{
// aapt resource value: 0x7f020000
public const int gms_fair_dr = 2130837504;
// aapt resource value: 0x7f020001
public const int gms_good_dr = 2130837505;
// aapt resource value: 0x7f020002
public const int gms_none_dr = 2130837506;
// aapt resource value: 0x7f020003
public const int gms_poor_dr = 2130837507;
// aapt resource value: 0x7f020004
public const int gsm_signal_strength = 2130837508;
// aapt resource value: 0x7f020005
public const int Icon = 2130837509;
static Drawable()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Drawable()
{
}
}
public partial class Id
{
// aapt resource value: 0x7f050003
public const int imageView1 = 2131034115;
// aapt resource value: 0x7f050001
public const int linearLayout1 = 2131034113;
// aapt resource value: 0x7f050000
public const int myButton = 2131034112;
// aapt resource value: 0x7f050002
public const int textView1 = 2131034114;
static Id()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Id()
{
}
}
public partial class Layout
{
// aapt resource value: 0x7f030000
public const int Main = 2130903040;
static Layout()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Layout()
{
}
}
public partial class String
{
// aapt resource value: 0x7f040001
public const int app_name = 2130968577;
// aapt resource value: 0x7f040000
public const int hello = 2130968576;
static String()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private String()
{
}
}
}
}
#pragma warning restore 1591

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 290 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 242 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 242 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 295 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 193 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 169 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 169 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 192 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 264 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 217 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 217 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 266 B

Двоичные данные
android/networking/gsm_strength/Resources/drawable/Icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.5 KiB

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/gms_none_dr" android:minLevel="-1" android:maxLevel="0" />
<item android:drawable="@drawable/gms_poor_dr" android:minLevel="1" android:maxLevel="9" />
<item android:drawable="@drawable/gms_fair_dr" android:minLevel="10" android:maxLevel="19" />
<item android:drawable="@drawable/gms_good_dr" android:minLevel="20" android:maxLevel="100" />
</level-list>

Просмотреть файл

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout1"
android:layout_marginTop="15dp">
<TextView
android:text="GSM Signal Strength:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView1"
android:src="@drawable/gsm_signal_strength"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/textView1" />
</RelativeLayout>
</LinearLayout>

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Get GSM Signal Strength</string>
<string name="app_name">GetMobileNetworkStrength</string>
</resources>

Просмотреть файл

@ -0,0 +1,3 @@
This is the sample code for the Android recipe for getting the gsm signal strength.
[See the recipe at developer.xamarin.com](http://developer.xamarin.com/recipes/android/networking/gsm_strength)

Просмотреть файл

@ -0,0 +1,51 @@
namespace NetworkDetection
{
using Android.App;
using Android.Net;
using Android.OS;
using Android.Widget;
[Activity(Label = "NetworkDetection", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
private ImageView _isConnectedImage;
private ImageView _roamingImage;
private ImageView _wifiImage;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
_wifiImage = FindViewById<ImageView>(Resource.Id.wifi_image);
_roamingImage = FindViewById<ImageView>(Resource.Id.roaming_image);
_isConnectedImage = FindViewById<ImageView>(Resource.Id.is_connected_image);
DetectNetwork();
}
private void DetectNetwork()
{
var connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService);
var activeConnection = connectivityManager.ActiveNetworkInfo;
if ((activeConnection != null) && activeConnection.IsConnected)
{
// we are connected to a network.
_isConnectedImage.SetImageResource(Resource.Drawable.green_square);
}
var mobile = connectivityManager.GetNetworkInfo(ConnectivityType.Mobile).GetState();
if (mobile == NetworkInfo.State.Connected)
{
// We are connected via WiFi
_roamingImage.SetImageResource(Resource.Drawable.green_square);
}
var wifiState = connectivityManager.GetNetworkInfo(ConnectivityType.Wifi).GetState();
if (wifiState == NetworkInfo.State.Connected)
{
_wifiImage.SetImageResource(Resource.Drawable.green_square);
}
}
}
}

Просмотреть файл

@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".
These files will be deployed with you package and will be accessible using Android's
AssetManager, like this:
public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
InputStream input = Assets.Open ("my_asset.txt");
}
}
Additionally, some Android functions will automatically load asset files:
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");

Просмотреть файл

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{88D4BEB0-FABE-43C8-B8E1-710D4E50D9C2}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NetworkDetection</RootNamespace>
<AssemblyName>NetworkDetection</AssemblyName>
<FileAlignment>512</FileAlignment>
<AndroidApplication>true</AndroidApplication>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Activity1.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Layout\Main.axml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Values\Strings.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Drawable\Icon.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable-hdpi\green_square.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable-hdpi\red_square.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable-ldpi\green_square.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable-ldpi\red_square.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable-mdpi\green_square.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable-mdpi\red_square.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable-xhdpi\green_square.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable-xhdpi\red_square.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Drawable\green_square.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Drawable\red_square.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkDetection", "NetworkDetection.csproj", "{88D4BEB0-FABE-43C8-B8E1-710D4E50D9C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{88D4BEB0-FABE-43C8-B8E1-710D4E50D9C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88D4BEB0-FABE-43C8-B8E1-710D4E50D9C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88D4BEB0-FABE-43C8-B8E1-710D4E50D9C2}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{88D4BEB0-FABE-43C8-B8E1-710D4E50D9C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88D4BEB0-FABE-43C8-B8E1-710D4E50D9C2}.Release|Any CPU.Build.0 = Release|Any CPU
{88D4BEB0-FABE-43C8-B8E1-710D4E50D9C2}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="NetworkDetection.NetworkDetection">
<uses-sdk />
<application android:label="NetworkDetection">
</application>
</manifest>

Просмотреть файл

@ -0,0 +1,40 @@
using System.Reflection;
using System.Runtime.InteropServices;
using Android;
using Android.App;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NetworkDetection")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NetworkDetection")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a557ce8c-9dbe-4b93-8fc4-95ffc126cf14")]
// Version information for an assembly consists of the following four values:
// Major Version
// Minor Version
// Build Number
// Revision
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
// Add some common permissions, these can be removed if not needed
[assembly: UsesPermission(Manifest.Permission.Internet)]
[assembly: UsesPermission(Manifest.Permission.AccessNetworkState)]

Просмотреть файл

@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.
For example, a sample Android app that contains a user interface layout (Main.xml),
an internationalization string table (Strings.xml) and some icons (drawable/Icon.png)
would keep its resources in the "Resources" directory of the application:
Resources/
Drawable/
Icon.png
Layout/
Main.axml
Values/
Strings.xml
In order to get the build system to recognize Android resources, the build action should be set
to "AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called
"Resource" that contains the tokens for each one of the resources included. For example,
for the above Resources layout, this is what the Resource class would expose:
public class Resource {
public class Drawable {
public const int Icon = 0x123;
}
public class Layout {
public const int Main = 0x456;
}
public class String {
public const int FirstString = 0xabc;
public const int SecondString = 0xbcd;
}
}
You would then use Resource.Drawable.Icon to reference the Drawable/Icon.png file, or
Resource.Layout.Main to reference the Layout/Main.axml file, or Resource.String.FirstString
to reference the first string in the dictionary file Values/Strings.xml.

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.0 KiB

Двоичный файл не отображается.

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.5 KiB

Просмотреть файл

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="fill_parent"
p1:layout_height="fill_parent"
p1:id="@+id/tableLayout1">
<TableRow
p1:id="@+id/tableRow0"
>
<TextView
p1:text="Is Connected?"
p1:textAppearance="?android:attr/textAppearanceMedium"
p1:layout_column="0"
p1:layout_gravity="center_vertical"
p1:layout_weight="2" />
<ImageView
p1:src="@drawable/red_square"
p1:layout_column="1"
p1:layout_weight="1"
p1:id="@+id/is_connected_image" />
</TableRow>
<TableRow
p1:id="@+id/tableRow1"
>
<TextView
p1:text="WiFi"
p1:textAppearance="?android:attr/textAppearanceMedium"
p1:layout_column="0"
p1:layout_gravity="center_vertical"
p1:layout_weight="2" />
<ImageView
p1:src="@drawable/red_square"
p1:layout_column="1"
p1:layout_weight="1"
p1:id="@+id/wifi_image" />
</TableRow>
<TableRow
p1:id="@+id/tableRow2"
>
<TextView
p1:text="Roaming"
p1:textAppearance="?android:attr/textAppearanceMedium"
p1:layout_column="0"
p1:layout_gravity="center_vertical"
p1:layout_weight="2" />
<ImageView
p1:src="@drawable/red_square"
p1:layout_column="1"
p1:layout_weight="1"
p1:id="@+id/roaming_image" />
</TableRow>
</TableLayout>

Просмотреть файл

@ -0,0 +1,136 @@
#pragma warning disable 1591
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 4.0.30319.17020
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
[assembly: Android.Runtime.ResourceDesignerAttribute("NetworkDetection.Resource", IsApplication=true)]
namespace NetworkDetection
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
public partial class Resource
{
static Resource()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
public static void UpdateIdValues()
{
}
public partial class Attribute
{
static Attribute()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Attribute()
{
}
}
public partial class Drawable
{
// aapt resource value: 0x7f020000
public const int green_square = 2130837504;
// aapt resource value: 0x7f020001
public const int Icon = 2130837505;
// aapt resource value: 0x7f020002
public const int red_square = 2130837506;
static Drawable()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Drawable()
{
}
}
public partial class Id
{
// aapt resource value: 0x7f050002
public const int is_connected_image = 2131034114;
// aapt resource value: 0x7f050006
public const int roaming_image = 2131034118;
// aapt resource value: 0x7f050000
public const int tableLayout1 = 2131034112;
// aapt resource value: 0x7f050001
public const int tableRow0 = 2131034113;
// aapt resource value: 0x7f050003
public const int tableRow1 = 2131034115;
// aapt resource value: 0x7f050005
public const int tableRow2 = 2131034117;
// aapt resource value: 0x7f050004
public const int wifi_image = 2131034116;
static Id()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Id()
{
}
}
public partial class Layout
{
// aapt resource value: 0x7f030000
public const int Main = 2130903040;
static Layout()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Layout()
{
}
}
public partial class String
{
// aapt resource value: 0x7f040001
public const int ApplicationName = 2130968577;
// aapt resource value: 0x7f040000
public const int Hello = 2130968576;
static String()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private String()
{
}
}
}
}
#pragma warning restore 1591

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Hello">Hello World, Click Me!</string>
<string name="ApplicationName">NetworkDetection</string>
</resources>

Двоичный файл не отображается.

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.2 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.3 KiB

Двоичный файл не отображается.

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.6 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.8 KiB

Двоичный файл не отображается.

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.5 KiB

Двоичный файл не отображается.

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 6.7 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 6.9 KiB

Просмотреть файл

@ -0,0 +1,3 @@
This is the sample code for the Android recipe for detecting the current network state.
[See the recipe at developer.xamarin.com](http://developer.xamarin.com/recipes/android/networking/networkinfo/detect_network_connection)

Просмотреть файл

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendSMS", "SendSMS\SendSMS.csproj", "{BBCF9534-94F3-4B1F-A098-A2DE555C0FA0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BBCF9534-94F3-4B1F-A098-A2DE555C0FA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBCF9534-94F3-4B1F-A098-A2DE555C0FA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBCF9534-94F3-4B1F-A098-A2DE555C0FA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBCF9534-94F3-4B1F-A098-A2DE555C0FA0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = SendSMS\SendSMS.csproj
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,41 @@
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Telephony;
namespace SendSMS
{
[Activity (Label = "SendSMS", MainLauncher = true)]
public class Activity1 : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
var sendSMS = FindViewById<Button> (Resource.Id.sendSMS);
sendSMS.Click += (sender, e) => {
SmsManager.Default.SendTextMessage ("1234567890", null, "hello from Xamarin.Android", null, null);
};
var sendSMSIntent = FindViewById<Button> (Resource.Id.sendSMSIntent);
sendSMSIntent.Click += (sender, e) => {
var smsUri = Android.Net.Uri.Parse("smsto:1234567890");
var smsIntent = new Intent (Intent.ActionSendto, smsUri);
smsIntent.PutExtra ("sms_body", "hello from Xamarin.Android");
StartActivity (smsIntent);
};
}
}
}

Просмотреть файл

@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".
These files will be deployed with you package and will be accessible using Android's
AssetManager, like this:
public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
InputStream input = Assets.Open ("my_asset.txt");
}
}
Additionally, some Android functions will automatically load asset files:
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="SendSMS.SendSMS">
<application android:label="SendSMS">
</application>
<uses-sdk />
<uses-permission android:name="android.permission.SEND_SMS" />
</manifest>

Просмотреть файл

@ -0,0 +1,28 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Android.App;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("SendSMS")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("mike_bluestein")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.0")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

Просмотреть файл

@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.
For example, a sample Android app that contains a user interface layout (main.axml),
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
would keep its resources in the "Resources" directory of the application:
Resources/
drawable/
icon.png
layout/
main.axml
values/
strings.xml
In order to get the build system to recognize Android resources, set the build action to
"AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called "R"
(this is an Android convention) that contains the tokens for each one of the resources
included. For example, for the above Resources layout, this is what the R class would expose:
public class R {
public class drawable {
public const int icon = 0x123;
}
public class layout {
public const int main = 0x456;
}
public class strings {
public const int first_string = 0xabc;
public const int second_string = 0xbcd;
}
}
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
to reference the layout/main.axml file, or R.strings.first_string to reference the first
string in the dictionary file values/strings.xml.

118
android/networking/sms/send_an_sms/SendSMS/Resources/Resource.designer.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,118 @@
#pragma warning disable 1591
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 4.0.30319.17020
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
[assembly: Android.Runtime.ResourceDesignerAttribute("SendSMS.Resource", IsApplication=true)]
namespace SendSMS
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
public partial class Resource
{
static Resource()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
public static void UpdateIdValues()
{
}
public partial class Attribute
{
static Attribute()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Attribute()
{
}
}
public partial class Drawable
{
// aapt resource value: 0x7f020000
public const int Icon = 2130837504;
static Drawable()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Drawable()
{
}
}
public partial class Id
{
// aapt resource value: 0x7f050000
public const int sendSMS = 2131034112;
// aapt resource value: 0x7f050001
public const int sendSMSIntent = 2131034113;
static Id()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Id()
{
}
}
public partial class Layout
{
// aapt resource value: 0x7f030000
public const int Main = 2130903040;
static Layout()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Layout()
{
}
}
public partial class String
{
// aapt resource value: 0x7f040002
public const int app_name = 2130968578;
// aapt resource value: 0x7f040001
public const int sendSMSIntentTitle = 2130968577;
// aapt resource value: 0x7f040000
public const int sendSMSTitle = 2130968576;
static String()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private String()
{
}
}
}
}
#pragma warning restore 1591

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.5 KiB

Просмотреть файл

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/sendSMS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sendSMSTitle"
/>
<Button
android:id="@+id/sendSMSIntent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sendSMSIntentTitle"
/>
</LinearLayout>

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="sendSMSTitle">Send SMS</string>
<string name="sendSMSIntentTitle">Send SMS using Intent</string>
<string name="app_name">SendSMS</string>
</resources>

Просмотреть файл

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BBCF9534-94F3-4B1F-A098-A2DE555C0FA0}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>SendSMS</RootNamespace>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidResgenClass>Resource</AndroidResgenClass>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AssemblyName>SendSMS</AssemblyName>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
</ItemGroup>
<ItemGroup>
<Compile Include="Activity1.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Main.axml" />
<AndroidResource Include="Resources\values\Strings.xml" />
<AndroidResource Include="Resources\drawable\Icon.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,3 @@
This is the sample code for the Android recipe for sending an SMS message.
[See the recipe at developer.xamarin.com](http://developer.xamarin.com/recipes/android/networking/sms/send_an_sms)