Skip to content

Commit

Permalink
Switchin OFF/ON Datawedge via intent APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
NDZL committed Feb 2, 2024
1 parent 41dbbed commit 0899427
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 9 deletions.
30 changes: 29 additions & 1 deletion datawedge-MAUI-SampleApp/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,41 @@
x:Name="lbDisplayBarcodeData"
/>

<Button
<HorizontalStackLayout>
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />

<Label
Text=" "
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />

<Button
x:Name="DwOFF"
Text="DW OFF"
SemanticProperties.Hint="To switch off Datawedge"
Clicked="OnDWOFFClicked"
HorizontalOptions="Center" />

<Label
Text=" "
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />

<Button
x:Name="DwON"
Text="DW ON"
SemanticProperties.Hint="To switch on Datawedge"
Clicked="OnDWONClicked"
HorizontalOptions="Center" />
</HorizontalStackLayout>

</VerticalStackLayout>
</ScrollView>

Expand Down
18 changes: 17 additions & 1 deletion datawedge-MAUI-SampleApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using CommunityToolkit.Mvvm.Messaging;
using Java.Lang;
using System.Security.AccessControl;
using System.Xml.Linq;

namespace datawedge_MAUI_SampleApp;

Expand All @@ -12,7 +15,8 @@ public MainPage()

WeakReferenceMessenger.Default.Register<string>(this, (r, m) =>
{
MainThread.BeginInvokeOnMainThread(() => { lbDisplayBarcodeData.Text += "\n"+m; });
if(m.Length>2)
MainThread.BeginInvokeOnMainThread(() => { lbDisplayBarcodeData.Text += "\n" + m; });
});
}

Expand All @@ -27,5 +31,17 @@ private void OnCounterClicked(object sender, EventArgs e)

SemanticScreenReader.Announce(CounterBtn.Text);
}

private void OnDWOFFClicked(object sender, EventArgs e)
{
WeakReferenceMessenger.Default.Send("11");
WeakReferenceMessenger.Default.Send("SWITCHING OFF DW");
}

private void OnDWONClicked(object sender, EventArgs e)
{
WeakReferenceMessenger.Default.Send("22");
WeakReferenceMessenger.Default.Send("SWITCHING ON DW");
}
}

42 changes: 37 additions & 5 deletions datawedge-MAUI-SampleApp/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Android.Util;
using CommunityToolkit.Mvvm.Messaging;
using datawedge_MAUI_SampleApp.Platforms.Android;
using Java.Lang;
using System.Diagnostics.Metrics;
using System.Security.AccessControl;
using System.Xml.Linq;
Expand All @@ -15,25 +16,55 @@ namespace datawedge_MAUI_SampleApp;
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true)]
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState) {
base.OnCreate(savedInstanceState);
//protected override void OnCreate(Bundle savedInstanceState) {
protected override void OnPostCreate(Bundle savedInstanceState)
{
base.OnPostCreate(savedInstanceState);
RegisterReceivers();




WeakReferenceMessenger.Default.Register<string>(this, (r, li) =>
{
MainThread.BeginInvokeOnMainThread(() => {
if (li == "11")
{
Intent i = new Intent();
i.SetAction("com.symbol.datawedge.api.ACTION");
i.PutExtra("com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN", "DISABLE_PLUGIN");
i.PutExtra("SEND_RESULT", "true");
i.PutExtra("COMMAND_IDENTIFIER", "MY_DISABLE_SCANNER"); //Unique identifier
this.SendBroadcast(i);
}
else if (li=="22") {
Intent i = new Intent();
i.SetAction("com.symbol.datawedge.api.ACTION");
i.PutExtra("com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN", "ENABLE_PLUGIN");
i.PutExtra("SEND_RESULT", "true");
i.PutExtra("COMMAND_IDENTIFIER", "MY_ENABLE_SCANNER"); //Unique identifier
this.SendBroadcast(i);
}

});
});
//showing saved states
try
{
String savedDatetime = savedInstanceState.GetString("time");
string savedDatetime = savedInstanceState.GetString("time");
if (savedDatetime is not null)
WeakReferenceMessenger.Default.Send("Saved DateTime=" + savedDatetime);
}catch(Exception ex) {

}
catch(System.Exception ex) {
WeakReferenceMessenger.Default.Send("No previously saved instance available");
}
}


protected override void OnSaveInstanceState(Bundle outState)
{
String currentDatetime = DateTime.Now.ToString();
string currentDatetime = DateTime.Now.ToString();
outState.PutString("time", currentDatetime);
base.OnSaveInstanceState(outState);
}
Expand All @@ -43,6 +74,7 @@ void RegisterReceivers()
IntentFilter filter = new IntentFilter();
filter.AddCategory("android.intent.category.DEFAULT");
filter.AddAction("com.ndzl.DW");
filter.AddAction("com.zebra.sensors");

Intent regres = RegisterReceiver(new DWIntentReceiver(), filter);
}
Expand Down
4 changes: 4 additions & 0 deletions datawedge-MAUI-SampleApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"Windows Machine": {
"commandName": "MsixPackage",
"nativeDebugging": false
},
"WSL": {
"commandName": "WSL2",
"distributionName": ""
}
}
}
12 changes: 10 additions & 2 deletions datawedge-MAUI-SampleApp/datawedge-MAUI-SampleApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0-maccatalyst;net6.0-android33.0</TargetFrameworks>
<TargetFrameworks>net8.0-android34.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
Expand Down Expand Up @@ -33,6 +33,14 @@
<AndroidPackageFormat>apk</AndroidPackageFormat>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android34.0|AnyCPU'">
<AndroidKeyStore>False</AndroidKeyStore>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android34.0|AnyCPU'">
<AndroidKeyStore>False</AndroidKeyStore>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
Expand All @@ -52,7 +60,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
</ItemGroup>

</Project>

0 comments on commit 0899427

Please sign in to comment.