~phroa/phone-app

15eef8180a865cc3172d43aef7fc6e4e30372315 — Jack Stratton 3 years ago 89ee0d1
Receive SMS/MMS
3 files changed, 62 insertions(+), 16 deletions(-)

M phms/Properties/AndroidManifest.xml
A phms/SmsReceiver.cs
M phms/phms.csproj
M phms/Properties/AndroidManifest.xml => phms/Properties/AndroidManifest.xml +2 -0
@@ 4,6 4,8 @@
          android:versionName="1.0" 
          package="phms.phms">
  <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
  <uses-permission android:name="android.permission.RECEIVE_SMS" />
  <uses-permission android:name="android.permission.RECEIVE_MMS" />
  <application android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
  </application>
</manifest>

A phms/SmsReceiver.cs => phms/SmsReceiver.cs +43 -0
@@ 0,0 1,43 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Provider;
using Android.Util;

namespace phms
{
    [BroadcastReceiver(Enabled = true, Exported = true)]
    [IntentFilter(new[] {Telephony.Sms.Intents.SmsReceivedAction, Telephony.Sms.Intents.WapPushReceivedAction})]
    // ReSharper disable once UnusedType.Global
    public class SmsReceiver : BroadcastReceiver
    {
        public override void OnReceive(Context context, Intent intent)
        {
            switch (intent.Action)
            {
                case Telephony.Sms.Intents.SmsReceivedAction:
                    Log.Info("xxxxx", $"SMS Received {intent}");
                    var messages = Telephony.Sms.Intents.GetMessagesFromIntent(intent);
                    foreach (var m in messages)
                    {
                        Log.Info("xxxxx",
                            $"sms {m.OriginatingAddress} / {m.DisplayOriginatingAddress} / {m.MessageBody} / {m.DisplayMessageBody}");
                    }
                    break;
                case Telephony.Sms.Intents.WapPushReceivedAction:
                    Log.Info("xxxxx", $"WAP Push Received {intent}");
                    if (intent.Extras != null)
                    {
                        foreach (var key in intent.Extras.KeySet() ?? new List<string>())
                        {
                            Log.Info("xxxxx", $"mms bundle contains key {key}");
                        }
                    }
                    break;
            }
        }
    }
}
\ No newline at end of file

M phms/phms.csproj => phms/phms.csproj +17 -16
@@ 49,34 49,35 @@
        <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
    </PropertyGroup>
    <ItemGroup>
        <Reference Include="System"/>
        <Reference Include="System.Xml"/>
        <Reference Include="System.Core"/>
        <Reference Include="Mono.Android"/>
        <Reference Include="System" />
        <Reference Include="System.Xml" />
        <Reference Include="System.Core" />
        <Reference Include="Mono.Android" />
    </ItemGroup>
    <ItemGroup>
        <Compile Include="MainActivity.cs"/>
        <Compile Include="Resources\Resource.Designer.cs"/>
        <Compile Include="Properties\AssemblyInfo.cs"/>
        <Compile Include="MainActivity.cs" />
        <Compile Include="Resources\Resource.Designer.cs" />
        <Compile Include="Properties\AssemblyInfo.cs" />
        <Compile Include="SmsReceiver.cs" />
    </ItemGroup>
    <ItemGroup>
        <None Include="Resources\AboutResources.txt"/>
        <None Include="Properties\AndroidManifest.xml"/>
        <None Include="Assets\AboutAssets.txt"/>
        <None Include="Resources\AboutResources.txt" />
        <None Include="Properties\AndroidManifest.xml" />
        <None Include="Assets\AboutAssets.txt" />
    </ItemGroup>
    <ItemGroup>
        <AndroidResource Include="Resources\layout\activity_main.axml">
            <SubType>Designer</SubType>
        </AndroidResource>
        <AndroidResource Include="Resources\values\colors.xml"/>
        <AndroidResource Include="Resources\values\ic_launcher_background.xml"/>
        <AndroidResource Include="Resources\values\strings.xml"/>
        <AndroidResource Include="Resources\values\styles.xml"/>
        <AndroidResource Include="Resources\values\colors.xml" />
        <AndroidResource Include="Resources\values\ic_launcher_background.xml" />
        <AndroidResource Include="Resources\values\strings.xml" />
        <AndroidResource Include="Resources\values\styles.xml" />
    </ItemGroup>
    <ItemGroup>
        <PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.3"/>
        <PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.3" />
    </ItemGroup>
    <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets"/>
    <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.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">