Fitgram
FITGRAM (A workout app featuring Huawei Account Kit, Ads Kit and In-App Messaging Kit)
Good day, my partner Kish and I have created a simple workout app called Fitgram which is recommended specifically for beginners. This app consists of 4 weeks training program which focuses on all parts of the body. The training will be for 3 days each week and will take about 30 minutes each day. As beginners, this is the first app that we have created in the android application development field. Thanks to HMS 5 Weeks training, we could learn new things about app development and it’s undeniable that we have gained a good experience by building this app. We happen to get a lot of errors when building this where we don’t have an idea what the error is about and at the worst part we don’t know from where the error is coming. But in the end, after we asked some of the experts including posting questions in the Huawei Developer Forum, we could get some hint and ideas to tackle the errors. After some try and error approach, we managed to correct errors.
Our app used Google Firebase service for the database where we could store user’s data. Besides, we used Huawei Account Kit for user authentication. User can log in using either email or Huawei id. Users can just tap the Login with Huawei button for quick and secure sign-in compared to email login.
Sample code for the account kit is as below:
buttonLogin = (Button) findViewById(R.id.buttonLogInhuawei);
buttonLogin.setOnClickListener(this);@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.buttonLogInhuawei:
AccountAuthParams authParams2 = new
AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM).setIdToken().setAccessToken()
.createParams();
AccountAuthService service2 = AccountAuthManager.getService(Loginpage.this, authParams2);
startActivityForResult(service2.getSignInIntent(), 2222);
break; }}@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); if(requestCode == 2222){
com.huawei.hmf.tasks.Task<AuthAccount> authAccountTask = AccountAuthManager.parseAuthResultFromIntent(data);
if (authAccountTask.isSuccessful()) {
// The sign-in is successful, and the user's ID information and ID token are obtained.
AuthAccount authAccount = authAccountTask.getResult();
Log.i("MainActivity", "idToken:" + authAccount.getIdToken());
// Obtain the ID type (0: HUAWEI ID; 1: AppTouch ID).
Log.i("MainActivity", "accountFlag:" + authAccount.getAccountFlag()); } else {
// The sign-in failed. No processing is required. Logs are recorded for fault locating.
Log.e("MainActivity", "sign in failed : " +((ApiException) authAccountTask.getException()).getStatusCode());
}
Besides, we also integrated Huawei Ads Kits. In order to use Ads Kits, first, we have to apply for merchant service. We only could use Ads Kits after our application is approved. There are many types of ads and we chose banner type ads for our apps. We integrated the kits in a way where the ads will appear during the rest time for users. This will not disturb the user when they doing a workout and at the same time they can view the ads while taking a rest. The sample code of integrating ads kits is as below:
// Initialize the HUAWEI Ads SDK.
HwAds.init(this);
// Obtain BannerView based on the configuration in layout/ad_fragment.xml.
BannerView bottomBannerView = findViewById(R.id.hw_banner_view);
AdParam adParam = new
AdParam.Builder().build();
bottomBannerView.loadAd(adParam);
// Call new BannerView(Context context) to create a BannerView class.
BannerView topBannerView = new
BannerView(this);
topBannerView.setAdId("testw6vs28auh3");
topBannerView.setBannerAdSize(BannerAdSize.BANNER_SIZE_SMART);
topBannerView.loadAd(adParam);
RelativeLayout rootView = findViewById(R.id.root_view);
rootView.addView(topBannerView);
In addition, we also integrated the In-App Messaging kit into our app. By using this kit user will receive the message as a reminder to do the workout. The integration for In-App Messaging is done in the app console.
As we have installed HMS tools in our Android Studio, it was quite easier for us when using HMS tool to integrate the kits rather than manually coding. We faced some errors due to version incompatibility and manage to correct it by changing the versions at build Gradle. It took us roughly 3 weeks to complete this app, even though this app is not perfect, but we are happy that this app could function as to how we planned earlier. We realise there is a lot to learn and a long journey is waiting. Feel free to download our app at Huawei App Gallery and start your workout during this pandemic season. Think Fit Stay Fit!!!