Friday, July 12, 2019

Google announced all Android app should support 64-bit architectures from Aug 1, 2019. 64-bit CPUs deliver faster, richer experiences for your users. Google Play will continue to support 32-bit apps for now, but as of August 1, 2019 all new apps and updates that include native code must have 64-bit versions as well as 32-bit versions when publishing to Google Play. This ruling applies to apps written in native, Xamarin or apps with links to third-party native libraries.

Android application supports four ABIs that can be selected when building mobile app. You can Select which ABIs your application supports in the project android options properties, if no ABI is specified, “armeabi-v71” is used in release build and As of Xamarin.Android 9.2, armeabi is no longer supported.

You can follow the below steps for select 64-bit android application in the Visual studio and Visual studio mac.

Visual Studio in Windows machine:

Step 1: You can open Visual Studio in the windows machine, right-click on android project and select Properties.

Step 2: Select the Android Options tab and Click the Advanced button and, check the architectures that you want to support.

Visual Studio Mac:

You can open Visual Studio mac in the mac machine and open/ create new project Android project.

Step 1: Right-click on Android project under the Solution Explorer and select Properties.

Step 2: Under the Android Options page check the Packaging properties section and Click the Advanced button and select the architectures that you want to support:

How to check if your device is 32-bit or 64-bit?

You can also check if your phone is 64-bit in android using the app Antutu Benchmark. While this is a benchmarking app, you can just use it to view your device information. Open Antutu Benchmark and click on “info”.

Summary:

The android applications already support 64-bit, no need to do anything, If you haven’t yet, you can change the as per the above steps as soon as possible. I hope this article will help you. Please leave your feedback/query using the comments box, and if you like this article, please share it with your friends.

Tuesday, July 2, 2019

Google is considering the users privacy seriously, it has updated its Google Play Developer Policy which restricting SMS, CALL_LOG access.If your app does not require access to Call Log or SMS permissions, you must remove the permissions from your app's manifest.

For apps requesting access to the SMS or Call Log permissions, the intended and permitted uses include default SMS handling, default phone handling, or Assistant handling capability, you should only access Call Log or SMS permissions when your app falls within permitted uses and only to enable your app’s critical core functionality.

Android App Should read the SMS some specific needs like verify OTP, The Google Play Services has enabled Android SMS Retriever API allows you to access the SMS Messages and verify it via SMS without device permissions.

Verification Message Format:

You need to follow as per Google Policy for construct the verification message and send to the user device, the message should be following format.

Be no longer than 140 bytes

Begin with the prefix <#>

One-time Verification code

Special 11-character hash for you app. That Hash can be generated by the Application. (will explain following steps)

Now we have very good understanding about Google new policy and message format. This article, I will explain the following steps, it will help you to integrate Android OTP verification code auto read using Xamarin Forms.

Create New Xamarin Forms Application.

Add Google Play Services Auth

Create UI Design

Dependency Service

Messaging Center subscribe

ListenToSms Dependency

Broadcast Receiver

Generate Application Hash Key Helper

Demo Application

Create New Xamarin Forms Application

In order to implement Auto read OTP message, let’s start creating a new Xamarin.Forms project using Visual Studio 2019 or VS mac. When accessing Visual Studio 2019 mac for the first time, you will come across a new interface for opening a creating the projects.

Open Visual Studio Mac >>Create New Project or select open recent application.

The available templates will appear on a mac like below. Select Xamarin.Forms application with different mobile platforms.

Add Google Play Service NuGet Package:

After click on Next Button, The Xamairn Project template will generate and load the solutions into the local system. We need to install Xamarin.GooglePlayServices.Auth nuget package to our Android project for SMS Retriever API.

Right click on Android Project >> Add Nuget Package >> Select or Search “Xamarin.GooglePlayServices.Auth”>> Install the Latest version of Google play service.

Create UI Design:

Create simple UI Design with one Entry and Button Control using Xaml in Xamarin Forms library.

DependencyService allows apps to call into platform-specific functionality from shared code. This functionality enables Xamarin.Forms apps to do anything that a native app can do. We need to create a interface design will define how you interact with platform-specific functionality. Here, reading OTP will support only android Platform and IOS will support with Autofill so create DependencyService interface for Listen to sms retriever. Create new class and interface for CommonServices.

Xamarin.Forms MessagingCenter enables different components to communicate without having to know anything about each other besides a simple Message contract. The MessagingCenter is a static class with Subscribe and Send methods that are used throughout the solution.

Subscribe - Listen for messages with a certain signature and perform some action when they are received. Multiple subscribers can be listening for the same message.

Send - Publish a message for listeners to act upon. If no listeners have subscribed then the message is ignored.

Here, we are creating utility for subscribe message listener, it will help for if any new message recived the device notify to the solutions.

The Code Behind add the Subscribe message listener and if any message receive from message app with specific format, it will get notify and read the meesage and assign the OTP value into the Entry Box.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Xamarin.Forms;

using Xamarin.Forms.Xaml;

namespace ReadOTPXamarinAndroid

{

publicpartialclassMainPage : ContentPage

publicMainPage()

InitializeComponent();

this.Subscribe<string>(Events.SmsRecieved, code =>

smSEntry.Text = code;

});

privatevoid ImageButton_OnClicked(object sender, EventArgs e)

CommonServices.ListenToSmsRetriever();

}

ListenToSms Dependency:

Let start create dependency to android project ,if you are not added Xamarin.GooglePlayServices.Auth NuGet package, try to add before going to create Instance.

Get an instance of SmsRetrieverClient, used to start listening for a matching SMS message.

The BroadcastReceiver that will be listening to the broadcasts of the above SmsRetreieverClient.SMS Retriever API has provided us with an intent filter SmsRetriever.SmsRetrievedAction which we will use to register our BroadcastReceiver, which we’re going name as SMSBroadcastReceiver, and implement as following.

We have done code for now; it will go for testing. Before going to demo let we re consider the format of SMS, in that we need to get know about Application Hash key, Ley you follow below step for generate application hash key

Generate Application Hash Key Helper

The hash string is made of your app’s package name and your app’s public key certificate. To generate the hash code, just run the following C# Method to generate hash to be included in your SMS message.

You need to make sure you are generate hash key and append to the OTP message, Without the correct hash, your app won't receive the message callback.

Hash key will generate once per app and stored. Then you can remove this helper class from your code and create new class into the native android project.

You can call the GetAppHashkey method into MainActivity and debug the solution and get the hash key value.

Demo and Download Source Code:

The Application Ready now and you can also download the source code from Github , start the application using Android Emulator and click Phone icon from extended controls and add the message as per follow format with hash key.

Summary

In this article, you learned about Verify OTP Automatically in Android without SMS read permission using Xamarin Forms. I hope this article will help you. Please leave your feedback/query using the comments box, and if you like this article, please share it with your friends.

About Me

Suthahar J is an industry luminary focused on AI, Computer Vision, Bot, Machine Learning, UWP, Azure, Xamarin and Web & Emerging User Experiences. He is a Technical Architect and C# Corner MVP. During his 12 years in the IT industry he has had roles in development, Lead and Architect using different Microsoft technologies on a number of large and complex projects. He is Author of Xamarin Q &A Book and published in Amazon. He is published Xamarin Q & A Bot to the Facebook Messenger, Blog, Skype and Cortana. He also enjoys sharing his passion with other people, thus actively contributing to the community via his presentations, writing technical Article and blogs which helps him becomes a better technology leader. He takes a keen interest in sharing his knowledge and solving readers’ technology-related problems. He is Founder of popular technical blog http://devenvexe.com.He was completed many Microsoft certification and received many awards. Whenever he gets the time he will go nearest orphans and stay with the child sometime and share computer skill.