Skip to content

Commit 8c4501a

Browse files
Hussein Al-RubayeHussein Al-Rubaye
authored andcommitted
'servicebacground'
1 parent 293f6a0 commit 8c4501a

198 files changed

Lines changed: 3511 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
50.5 KB
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.24720.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BroadcastAService", "BroadcastAService\BroadcastAService.csproj", "{5B7E6E7B-E4BD-42E5-9CF2-1C5DD6A22137}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{5B7E6E7B-E4BD-42E5-9CF2-1C5DD6A22137}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5B7E6E7B-E4BD-42E5-9CF2-1C5DD6A22137}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5B7E6E7B-E4BD-42E5-9CF2-1C5DD6A22137}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{5B7E6E7B-E4BD-42E5-9CF2-1C5DD6A22137}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{5B7E6E7B-E4BD-42E5-9CF2-1C5DD6A22137}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{5B7E6E7B-E4BD-42E5-9CF2-1C5DD6A22137}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with you package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{5B7E6E7B-E4BD-42E5-9CF2-1C5DD6A22137}</ProjectGuid>
9+
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>BroadcastAService</RootNamespace>
13+
<AssemblyName>BroadcastAService</AssemblyName>
14+
<FileAlignment>512</FileAlignment>
15+
<AndroidApplication>true</AndroidApplication>
16+
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
17+
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
18+
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
19+
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
20+
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
23+
<DebugSymbols>true</DebugSymbols>
24+
<DebugType>full</DebugType>
25+
<Optimize>false</Optimize>
26+
<OutputPath>bin\Debug\</OutputPath>
27+
<DefineConstants>DEBUG;TRACE</DefineConstants>
28+
<ErrorReport>prompt</ErrorReport>
29+
<WarningLevel>4</WarningLevel>
30+
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
31+
<AndroidLinkMode>None</AndroidLinkMode>
32+
</PropertyGroup>
33+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
34+
<DebugType>pdbonly</DebugType>
35+
<Optimize>true</Optimize>
36+
<OutputPath>bin\Release\</OutputPath>
37+
<DefineConstants>TRACE</DefineConstants>
38+
<ErrorReport>prompt</ErrorReport>
39+
<WarningLevel>4</WarningLevel>
40+
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
41+
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<Reference Include="AlertCenter.Android">
45+
<HintPath>..\Components\alert-center-1.0.6\lib\android\AlertCenter.Android.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Mono.Android" />
48+
<Reference Include="mscorlib" />
49+
<Reference Include="System" />
50+
<Reference Include="System.Core" />
51+
<Reference Include="System.Data" />
52+
<Reference Include="System.EnterpriseServices" />
53+
<Reference Include="System.Web.Services" />
54+
<Reference Include="System.Xml.Linq" />
55+
<Reference Include="System.Xml" />
56+
</ItemGroup>
57+
<ItemGroup>
58+
<Compile Include="MainActivity.cs" />
59+
<Compile Include="MyReciver.cs" />
60+
<Compile Include="MyServices.cs" />
61+
<Compile Include="Resources\Resource.Designer.cs" />
62+
<Compile Include="Properties\AssemblyInfo.cs" />
63+
</ItemGroup>
64+
<ItemGroup>
65+
<None Include="GettingStarted.Xamarin" />
66+
<None Include="Resources\AboutResources.txt" />
67+
<None Include="Assets\AboutAssets.txt" />
68+
</ItemGroup>
69+
<ItemGroup>
70+
<AndroidResource Include="Resources\layout\Main.axml" />
71+
</ItemGroup>
72+
<ItemGroup>
73+
<AndroidResource Include="Resources\values\Strings.xml" />
74+
</ItemGroup>
75+
<ItemGroup>
76+
<AndroidResource Include="Resources\drawable\Icon.png" />
77+
</ItemGroup>
78+
<ItemGroup>
79+
<None Include="Properties\AndroidManifest.xml">
80+
<SubType>Designer</SubType>
81+
</None>
82+
</ItemGroup>
83+
<ItemGroup>
84+
<XamarinComponentReference Include="alert-center">
85+
<Visible>False</Visible>
86+
<Version>1.0.6</Version>
87+
</XamarinComponentReference>
88+
</ItemGroup>
89+
<ItemGroup>
90+
<WebReferences Include="Web References\" />
91+
</ItemGroup>
92+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
93+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
94+
Other similar extension points exist, see Microsoft.Common.targets.
95+
<Target Name="BeforeBuild">
96+
</Target>
97+
<Target Name="AfterBuild">
98+
</Target>
99+
-->
100+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<AndroidDesignerPreferredDevice>Nexus 4</AndroidDesignerPreferredDevice>
5+
<SelectedDevice>4" JellyBean %284.2%29 HDPI Phone</SelectedDevice>
6+
</PropertyGroup>
7+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<GettingStarted>
2+
<LocalContent>GS\Android\CS\AndroidApp\GettingStarted.html</LocalContent>
3+
<EmbeddedNavigation>false</EmbeddedNavigation>
4+
</GettingStarted>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using Android.App;
3+
using Android.Content;
4+
using Android.Runtime;
5+
using Android.Views;
6+
using Android.Widget;
7+
using Android.OS;
8+
9+
namespace BroadcastAService
10+
{
11+
[Activity(Label = "BroadcastAService", MainLauncher = true, Icon = "@drawable/icon")]
12+
public class MainActivity : Activity
13+
{
14+
int count = 1;
15+
16+
protected override void OnCreate(Bundle bundle)
17+
{
18+
base.OnCreate(bundle);
19+
20+
// Set our view from the "main" layout resource
21+
SetContentView(Resource.Layout.Main);
22+
StartService(new Intent(this,typeof( MyServices)));
23+
// Get our button from the layout resource,
24+
// and attach an event to it
25+
Button button = FindViewById<Button>(Resource.Id.MyButton);
26+
27+
button.Click += delegate {
28+
Intent intent = new Intent();
29+
intent.SetAction("com.alr.text");
30+
intent.PutExtra("MyData", "Data from Activity1");
31+
SendBroadcast(intent);
32+
33+
};
34+
35+
}
36+
37+
38+
}
39+
}
40+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
using Android.App;
7+
using Android.Content;
8+
using Android.OS;
9+
using Android.Runtime;
10+
using Android.Views;
11+
using Android.Widget;
12+
using Android.Telephony;
13+
using Android.Provider;
14+
using Xamarin.Controls;
15+
16+
namespace BroadcastAService
17+
{
18+
19+
[BroadcastReceiver(Exported = true, Label = "SMS Receiver")]
20+
[IntentFilter(new string[] { "android.provider.Telephony.SMS_RECEIVED", "com.alr.text" })]
21+
public class MyReciver : Android.Content.BroadcastReceiver
22+
{
23+
private const string Tag = "SMSBroadcastReceiver";
24+
private const string IntentAction = "android.provider.Telephony.SMS_RECEIVED";
25+
26+
public override void OnReceive(Context context, Intent intent)
27+
{
28+
// Log.Info(Tag, "Intent received: " + intent.Action);
29+
// read the SendBroadcast data
30+
if (intent.Action == "com.alr.text")
31+
{
32+
string text = intent.GetStringExtra("MyData") ?? "Data not available";
33+
Toast.MakeText(context, text, ToastLength.Short).Show();
34+
Intent intents = new Intent(context, typeof(MainActivity));
35+
intents.AddFlags(ActivityFlags.NewTask);
36+
context.StartActivity(intents);
37+
}
38+
//read incomming sms
39+
if (intent.Action == IntentAction)
40+
{
41+
42+
SmsMessage[] messages = Telephony.Sms.Intents.GetMessagesFromIntent(intent);
43+
44+
var sb = new StringBuilder();
45+
46+
for (var i = 0; i < messages.Length; i++)
47+
{
48+
49+
sb.Append(string.Format("SMS From: {0}{1}Body: {2}{1}", messages[i].OriginatingAddress,
50+
System.Environment.NewLine, messages[i].MessageBody));
51+
}
52+
Toast.MakeText(context, sb.ToString(), ToastLength.Short).Show();
53+
}
54+
}
55+
}
56+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
using Android.App;
7+
using Android.Content;
8+
using Android.OS;
9+
using Android.Runtime;
10+
using Android.Views;
11+
using Android.Widget;
12+
using System.Threading.Tasks;
13+
using System.Threading;
14+
15+
namespace BroadcastAService
16+
{
17+
[Service]
18+
class MyServices : IntentService
19+
{
20+
protected override void OnHandleIntent(Intent intent)
21+
{
22+
23+
}
24+
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
25+
{
26+
27+
// countine
28+
new Task(() =>
29+
{
30+
while(true)
31+
{
32+
Thread.Sleep(10000);
33+
Intent intents = new Intent();
34+
intents.SetAction("com.alr.text");
35+
intents.PutExtra("MyData", "Data from service");
36+
SendBroadcast(intents);
37+
38+
39+
}
40+
41+
}).Start();
42+
43+
return StartCommandResult.Sticky;
44+
}
45+
46+
47+
}
48+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="BroadcastAService.BroadcastAService" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
3+
<uses-sdk android:minSdkVersion="16" />
4+
<application android:label="BroadcastAService"></application>
5+
<uses-permission android:name="android.permission.BROADCAST_SMS" />
6+
<uses-permission android:name="android.permission.READ_SMS" />
7+
<uses-permission android:name="android.permission.RECEIVE_SMS" />
8+
<uses-permission android:name="android.permission.INTERNET" />
9+
<receiver android:name=".MyReciver">
10+
<intent-filter android:priority="2147483647">
11+
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
12+
<action android:name="com.alr.text" />
13+
<category android:name="android.intent.category.DEFAULT" />
14+
</intent-filter>
15+
</receiver>
16+
</manifest>

0 commit comments

Comments
 (0)