learntodroid.com Ads.txt file

<!DOCTYPE html>
<html lang="en-US">
<head>
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-149159950-1"></script>
<script>window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());


gtag('config', 'UA-149159950-1');</script>

<script data-ad-client="ca-pub-7029809784556010" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="/wp-content/uploads/2020/05/40x40_new.png">
<link rel="profile" href="https://gmpg.org/xfn/11">

<title>Learn to Droid &#8211; Your Ultimate Resource for Android App Development</title>
<meta name="robots" content="max-image-preview:large">
<link rel="alternate" type="application/rss+xml" title="Learn to Droid &raquo; Feed" href="/feed/">
<link rel="alternate" type="application/rss+xml" title="Learn to Droid &raquo; Comments Feed" href="/comments/feed/">
<script type="text/javascript">
/* <![CDATA[ */
window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/svg\/","svgExt":".svg","source":{"concatemoji":"\/wp-includes\/js\/wp-emoji-release.min.js?ver=6.4.3"}};
/*! This file is auto-generated */
!function(i,n){var o,s,e;function c(e){try{var t={supportTests:e,timestamp:(new Date).valueOf()};sessionStorage.setItem(o,JSON.stringify(t))}catch(e){}}function p(e,t,n){e.clearRect(0,0,e.canvas.width,e.canvas.height),e.fillText(t,0,0);var t=new Uint32Array(e.getImageData(0,0,e.canvas.width,e.canvas.height).data),r=(e.clearRect(0,0,e.canvas.width,e.canvas.height),e.fillText(n,0,0),new Uint32Array(e.getImageData(0,0,e.canvas.width,e.canvas.height).data));return t.every(function(e,t){return e===r[t]})}function u(e,t,n){switch(t){case"flag":return n(e,"🏳️‍⚧️","🏳️​⚧️")?!1:!n(e,"🇺🇳","🇺​🇳")&&!n(e,"🏴󠁧󠁢󠁥󠁮󠁧󠁿","🏴​󠁧​󠁢​󠁥​󠁮​󠁧​󠁿");case"emoji":return!n(e,"🫱🏻‍🫲🏿","🫱🏻​🫲🏿")}return!1}function f(e,t,n){var r="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?new OffscreenCanvas(300,150):i.createElement("canvas"),a=r.getContext("2d",{willReadFrequently:!0}),o=(a.textBaseline="top",a.font="600 32px Arial",{});return e.forEach(function(e){o[e]=t(a,e,n)}),o}function t(e){var t=i.createElement("script");t.src=e,t.defer=!0,i.head.appendChild(t)}"undefined"!=typeof Promise&&(o="wpEmojiSettingsSupports",s=["flag","emoji"],n.supports={everything:!0,everythingExceptFlag:!0},e=new Promise(function(e){i.addEventListener("DOMContentLoaded",e,{once:!0})}),new Promise(function(t){var n=function(){try{var e=JSON.parse(sessionStorage.getItem(o));if("object"==typeof e&&"number"==typeof e.timestamp&&(new Date).valueOf()<e.timestamp+604800&&"object"==typeof e.supportTests)return e.supportTests}catch(e){}return null}();if(!n){if("undefined"!=typeof Worker&&"undefined"!=typeof OffscreenCanvas&&"undefined"!=typeof URL&&URL.createObjectURL&&"undefined"!=typeof Blob)try{var e="postMessage("+f.toString()+"("+[JSON.stringify(s),u.toString(),p.toString()].join(",")+"));",r=new Blob([e],{type:"text/javascript"}),a=new Worker(URL.createObjectURL(r),{name:"wpTestEmojiSupports"});return void(a.onmessage=function(e){c(n=e.data),a.terminate(),t(n)})}catch(e){}c(n=f(s,u,p))}t(n)}).then(function(e){for(var t in e)n.supports[t]=e[t],n.supports.everything=n.supports.everything&&n.supports[t],"flag"!==t&&(n.supports.everythingExceptFlag=n.supports.everythingExceptFlag&&n.supports[t]);n.supports.everythingExceptFlag=n.supports.everythingExceptFlag&&!n.supports.flag,n.DOMReady=!1,n.readyCallback=function(){n.DOMReady=!0}}).then(function(){return e}).then(function(){var e;n.supports.everything||(n.readyCallback(),(e=n.source||{}).concatemoji?t(e.concatemoji):e.wpemoji&&e.twemoji&&(t(e.twemoji),t(e.wpemoji)))}))}((window,document),window._wpemojiSettings);
/* ]]> */
</script>
<style id="wp-emoji-styles-inline-css" type="text/css">img.wp-smiley, img.emoji {
display: inline !important;
border: none !important;
box-shadow: none !important;
height: 1em !important;
width: 1em !important;
margin: 0 0.07em !important;
vertical-align: -0.1em !important;
background: none !important;
padding: 0 !important;
}</style>
<link rel="stylesheet" id="wp-block-library-css" href="/wp-includes/css/dist/block-library/style.min.css?ver=6.4.3" type="text/css" media="all">
<link rel="stylesheet" id="nfd-wonder-blocks-utilities-css" href="/wp-content/plugins/bluehost-wordpress-plugin/vendor/newfold-labs/wp-module-patterns/assets/build/utilities.css?ver=0.1.14" type="text/css" media="all">
<style id="classic-theme-styles-inline-css" type="text/css">/*! This file is auto-generated */
.wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none}</style>
<style id="global-styles-inline-css" type="text/css">body{--wp--preset--color--black: #000000;--wp--preset--color--cyan-bluish-gray: #abb8c3;--wp--preset--color--white: #ffffff;--wp--preset--color--pale-pink: #f78da7;--wp--preset--color--vivid-red: #cf2e2e;--wp--preset--color--luminous-vivid-orange: #ff6900;--wp--preset--color--luminous-vivid-amber: #fcb900;--wp--preset--color--light-green-cyan: #7bdcb5;--wp--preset--color--vivid-green-cyan: #00d084;--wp--preset--color--pale-cyan-blue: #8ed1fc;--wp--preset--color--vivid-cyan-blue: #0693e3;--wp--preset--color--vivid-purple: #9b51e0;--wp--preset--gradient--vivid-cyan-blue-to-vivid-purple: linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%);--wp--preset--gradient--light-green-cyan-to-vivid-green-cyan: linear-gradient(135deg,rgb(122,220,180) 0%,rgb(0,208,130) 100%);--wp--preset--gradient--luminous-vivid-amber-to-luminous-vivid-orange: linear-gradient(135deg,rgba(252,185,0,1) 0%,rgba(255,105,0,1) 100%);--wp--preset--gradient--luminous-vivid-orange-to-vivid-red: linear-gradient(135deg,rgba(255,105,0,1) 0%,rgb(207,46,46) 100%);--wp--preset--gradient--very-light-gray-to-cyan-bluish-gray: linear-gradient(135deg,rgb(238,238,238) 0%,rgb(169,184,195) 100%);--wp--preset--gradient--cool-to-warm-spectrum: linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%);--wp--preset--gradient--blush-light-purple: linear-gradient(135deg,rgb(255,206,236) 0%,rgb(152,150,240) 100%);--wp--preset--gradient--blush-bordeaux: linear-gradient(135deg,rgb(254,205,165) 0%,rgb(254,45,45) 50%,rgb(107,0,62) 100%);--wp--preset--gradient--luminous-dusk: linear-gradient(135deg,rgb(255,203,112) 0%,rgb(199,81,192) 50%,rgb(65,88,208) 100%);--wp--preset--gradient--pale-ocean: linear-gradient(135deg,rgb(255,245,203) 0%,rgb(182,227,212) 50%,rgb(51,167,181) 100%);--wp--preset--gradient--electric-grass: linear-gradient(135deg,rgb(202,248,128) 0%,rgb(113,206,126) 100%);--wp--preset--gradient--midnight: linear-gradient(135deg,rgb(2,3,129) 0%,rgb(40,116,252) 100%);--wp--preset--font-size--small: 13px;--wp--preset--font-size--medium: 20px;--wp--preset--font-size--large: 36px;--wp--preset--font-size--x-large: 42px;--wp--preset--spacing--20: 0.44rem;--wp--preset--spacing--30: 0.67rem;--wp--preset--spacing--40: 1rem;--wp--preset--spacing--50: 1.5rem;--wp--preset--spacing--60: 2.25rem;--wp--preset--spacing--70: 3.38rem;--wp--preset--spacing--80: 5.06rem;--wp--preset--shadow--natural: 6px 6px 9px rgba(0, 0, 0, 0.2);--wp--preset--shadow--deep: 12px 12px 50px rgba(0, 0, 0, 0.4);--wp--preset--shadow--sharp: 6px 6px 0px rgba(0, 0, 0, 0.2);--wp--preset--shadow--outlined: 6px 6px 0px -3px rgba(255, 255, 255, 1), 6px 6px rgba(0, 0, 0, 1);--wp--preset--shadow--crisp: 6px 6px 0px rgba(0, 0, 0, 1);}:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){max-width: var(--wp--style--global--content-size);margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignwide{max-width: var(--wp--style--global--wide-size);}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}:where(.wp-block-columns.is-layout-flex){gap: 2em;}:where(.wp-block-columns.is-layout-grid){gap: 2em;}:where(.wp-block-post-template.is-layout-flex){gap: 1.25em;}:where(.wp-block-post-template.is-layout-grid){gap: 1.25em;}.has-black-color{color: var(--wp--preset--color--black) !important;}.has-cyan-bluish-gray-color{color: var(--wp--preset--color--cyan-bluish-gray) !important;}.has-white-color{color: var(--wp--preset--color--white) !important;}.has-pale-pink-color{color: var(--wp--preset--color--pale-pink) !important;}.has-vivid-red-color{color: var(--wp--preset--color--vivid-red) !important;}.has-luminous-vivid-orange-color{color: var(--wp--preset--color--luminous-vivid-orange) !important;}.has-luminous-vivid-amber-color{color: var(--wp--preset--color--luminous-vivid-amber) !important;}.has-light-green-cyan-color{color: var(--wp--preset--color--light-green-cyan) !important;}.has-vivid-green-cyan-color{color: var(--wp--preset--color--vivid-green-cyan) !important;}.has-pale-cyan-blue-color{color: var(--wp--preset--color--pale-cyan-blue) !important;}.has-vivid-cyan-blue-color{color: var(--wp--preset--color--vivid-cyan-blue) !important;}.has-vivid-purple-color{color: var(--wp--preset--color--vivid-purple) !important;}.has-black-background-color{background-color: var(--wp--preset--color--black) !important;}.has-cyan-bluish-gray-background-color{background-color: var(--wp--preset--color--cyan-bluish-gray) !important;}.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}.has-pale-pink-background-color{background-color: var(--wp--preset--color--pale-pink) !important;}.has-vivid-red-background-color{background-color: var(--wp--preset--color--vivid-red) !important;}.has-luminous-vivid-orange-background-color{background-color: var(--wp--preset--color--luminous-vivid-orange) !important;}.has-luminous-vivid-amber-background-color{background-color: var(--wp--preset--color--luminous-vivid-amber) !important;}.has-light-green-cyan-background-color{background-color: var(--wp--preset--color--light-green-cyan) !important;}.has-vivid-green-cyan-background-color{background-color: var(--wp--preset--color--vivid-green-cyan) !important;}.has-pale-cyan-blue-background-color{background-color: var(--wp--preset--color--pale-cyan-blue) !important;}.has-vivid-cyan-blue-background-color{background-color: var(--wp--preset--color--vivid-cyan-blue) !important;}.has-vivid-purple-background-color{background-color: var(--wp--preset--color--vivid-purple) !important;}.has-black-border-color{border-color: var(--wp--preset--color--black) !important;}.has-cyan-bluish-gray-border-color{border-color: var(--wp--preset--color--cyan-bluish-gray) !important;}.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}.has-pale-pink-border-color{border-color: var(--wp--preset--color--pale-pink) !important;}.has-vivid-red-border-color{border-color: var(--wp--preset--color--vivid-red) !important;}.has-luminous-vivid-orange-border-color{border-color: var(--wp--preset--color--luminous-vivid-orange) !important;}.has-luminous-vivid-amber-border-color{border-color: var(--wp--preset--color--luminous-vivid-amber) !important;}.has-light-green-cyan-border-color{border-color: var(--wp--preset--color--light-green-cyan) !important;}.has-vivid-green-cyan-border-color{border-color: var(--wp--preset--color--vivid-green-cyan) !important;}.has-pale-cyan-blue-border-color{border-color: var(--wp--preset--color--pale-cyan-blue) !important;}.has-vivid-cyan-blue-border-color{border-color: var(--wp--preset--color--vivid-cyan-blue) !important;}.has-vivid-purple-border-color{border-color: var(--wp--preset--color--vivid-purple) !important;}.has-vivid-cyan-blue-to-vivid-purple-gradient-background{background: var(--wp--preset--gradient--vivid-cyan-blue-to-vivid-purple) !important;}.has-light-green-cyan-to-vivid-green-cyan-gradient-background{background: var(--wp--preset--gradient--light-green-cyan-to-vivid-green-cyan) !important;}.has-luminous-vivid-amber-to-luminous-vivid-orange-gradient-background{background: var(--wp--preset--gradient--luminous-vivid-amber-to-luminous-vivid-orange) !important;}.has-luminous-vivid-orange-to-vivid-red-gradient-background{background: var(--wp--preset--gradient--luminous-vivid-orange-to-vivid-red) !important;}.has-very-light-gray-to-cyan-bluish-gray-gradient-background{background: var(--wp--preset--gradient--very-light-gray-to-cyan-bluish-gray) !important;}.has-cool-to-warm-spectrum-gradient-background{background: var(--wp--preset--gradient--cool-to-warm-spectrum) !important;}.has-blush-light-purple-gradient-background{background: var(--wp--preset--gradient--blush-light-purple) !important;}.has-blush-bordeaux-gradient-background{background: var(--wp--preset--gradient--blush-bordeaux) !important;}.has-luminous-dusk-gradient-background{background: var(--wp--preset--gradient--luminous-dusk) !important;}.has-pale-ocean-gradient-background{background: var(--wp--preset--gradient--pale-ocean) !important;}.has-electric-grass-gradient-background{background: var(--wp--preset--gradient--electric-grass) !important;}.has-midnight-gradient-background{background: var(--wp--preset--gradient--midnight) !important;}.has-small-font-size{font-size: var(--wp--preset--font-size--small) !important;}.has-medium-font-size{font-size: var(--wp--preset--font-size--medium) !important;}.has-large-font-size{font-size: var(--wp--preset--font-size--large) !important;}.has-x-large-font-size{font-size: var(--wp--preset--font-size--x-large) !important;}
.wp-block-navigation a:where(:not(.wp-element-button)){color: inherit;}
:where(.wp-block-post-template.is-layout-flex){gap: 1.25em;}:where(.wp-block-post-template.is-layout-grid){gap: 1.25em;}
:where(.wp-block-columns.is-layout-flex){gap: 2em;}:where(.wp-block-columns.is-layout-grid){gap: 2em;}
.wp-block-pullquote{font-size: 1.5em;line-height: 1.6;}</style>
<link rel="stylesheet" id="lazyload-video-css-css" href="/wp-content/plugins/lazy-load-for-videos/public/css/lazyload-shared.css?ver=2.18.3" type="text/css" media="all">
<style id="lazyload-video-css-inline-css" type="text/css">.entry-content a.lazy-load-youtube, a.lazy-load-youtube, .lazy-load-vimeo{ background-size: cover; }.titletext.youtube { display: none; }.lazy-load-div:before { content: "\25B6"; text-shadow: 0px 0px 60px rgba(0,0,0,0.8); }</style>
<link rel="stylesheet" id="defer-income-school-style-css" href="/wp-content/themes/acabado/css/main.css?ver=6.4.3" type="text/css" media="all">
<link rel="stylesheet" id="defer-style-min-width768-css" href="/wp-content/themes/acabado/css/min-width768.css?ver=6.4.3" type="text/css" media="(min-width: 768px)">
<link rel="stylesheet" id="defer-style-min-width960-css" href="/wp-content/themes/acabado/css/min-width960.css?ver=6.4.3" type="text/css" media="(min-width: 960px)">
<link rel="stylesheet" id="defer-style-min-width1200-css" href="/wp-content/themes/acabado/css/min-width1200.css?ver=6.4.3" type="text/css" media="(min-width: 1200px)">
<style id="custom-style-inline-css" type="text/css">.search-wrapper #search-icon{background:url("/wp-content/themes/acabado/img/search-icon.png") center/cover no-repeat #fff;}.share-container .email-btn:before{background:url("/wp-content/themes/acabado/img/envelope.svg") center/cover no-repeat;}.share-container .print-btn:before{background:url("/wp-content/themes/acabado/img/print-icon.svg") center/cover no-repeat;}.externallinkimage{background-image:url("/wp-content/themes/acabado/img/extlink.png")}</style>
<script type="text/javascript" async defer src="/wp-content/plugins/bluehost-wordpress-plugin/vendor/newfold-labs/wp-module-patterns/assets/build/utilities.js?ver=0.1.14" id="nfd-wonder-blocks-utilities-js"></script>
<script type="text/javascript" async defer src="/wp-includes/js/jquery/jquery.min.js?ver=3.7.1" id="jquery-core-js"></script>
<link rel="https://api.w.org/" href="/wp-json/">
<link rel="alternate" type="application/json" href="/wp-json/wp/v2/pages/6">
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="/xmlrpc.php?rsd">
<meta name="generator" content="WordPress 6.4.3">
<link rel="canonical" href="/">
<link rel="shortlink" href="/">
<link rel="alternate" type="application/json+oembed" href="/wp-json/oembed/1.0/embed?url=%2F">
<link rel="alternate" type="text/xml+oembed" href="/wp-json/oembed/1.0/embed?url=%2F#038;format=xml">
<meta name="description" content="Your Ultimate Resource for Android App Development">
<meta name="category" content="homepage">
<style>#nfd-site-status {
align-items: center;
background-color: #F8F8F8;
border-radius: 2px;
border-style: solid;
border-width: 1px;
color: #333333;
display: flex;
font-weight: 500;
gap: 2px;
height: 22px;
margin-top: 4px;
padding: 0 14px;
}

#wpadminbar #wp-admin-bar-site-status .ab-item{
height:22px;
}

#nfd-site-status[data-coming-soon="true"] {
border-color: var(--Dark-Red, #C71919);
}

#nfd-site-status[data-coming-soon="false"] {
border-color: var(--A11y-GRN, #278224);
}

#nfd-site-status span {
display: none;
text-transform: uppercase;
font-weight: 500;
}

#nfd-site-status[data-coming-soon="true"] #nfd-site-status-coming-soon {
color: var(--Dark-Red, #C71919);
display: inline-block;
}

#nfd-site-status[data-coming-soon="false"] #nfd-site-status-live {
color: var(--A11y-GRN, #278224);
display: inline-block;
}</style>
<link rel="preconnect" href="https://fonts.gstatic.com/">
<link rel="preload" href="https://fonts.googleapis.com/css2?family=Libre+Franklin:wght@400;800&family=Roboto+Condensed&display=swap" as="style" onload="this.onload=null;this.rel='stylesheet'">
<script type="text/javascript" src="/wp-includes/js/jquery/jquery.js?ver=1.12.4-wp"></script>
<!-- Fonts Plugin CSS - https://fontsplugin.com/ -->
<style></style>
<!-- Fonts Plugin CSS -->

</head>


<body class="home page-template-default page page-id-6">
<div id="page" class="site">
<a class="skip-link screen-reader-text" href="#content">Skip to content</a>


<header id="masthead" class="site-header desktop-toggle">
<div class="inner-wrap">
<div class="hamburger-wrapper desktop">
<button class="hamburger hamburger--squeeze menu-toggle" type="button" aria-label="Menu" aria-controls="primary-menu" aria-expanded="false">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
<span class="label">MENU</span>
</button>
</div>
<div class="site-branding">
<a href="/" class="custom-logo-link" rel="home" itemprop="url"><img width="300" height="300" src="/wp-content/uploads/2020/05/Learn-to-Droid-480-300x300.png" class="attachment-medium size-medium" alt="Learn to Droid Logo" decoding="async" fetchpriority="high" srcset="/wp-content/uploads/2020/05/Learn-to-Droid-480-300x300.png 300w, /wp-content/uploads/2020/05/Learn-to-Droid-480-150x150.png 150w, /wp-content/uploads/2020/05/Learn-to-Droid-480.png 480w" sizes="(max-width: 300px) 100vw, 300px"></a>
<!-- <h1 class="site-title"><a tabindex="-1" href="" rel="home"></a></h1> -->
<!-- <p class="site-title"><a tabindex="-1" href="" rel="home"></a></p> -->
</div>
<!-- .site-branding -->
<div class="search-wrapper">
<a href="#open" id="search-icon" style="background: url(/wp-content/themes/acabado/img/search-icon.png) center/cover no-repeat #fff;"><span class="sr-only">Search</span></a>
<div class="search-form-wrapper">
<form role="search" method="get" class="search-form" action="http://10.0.0.14:32769/">
<style>.search-wrapper.search-active .search-field {
width: 200px;
display: inline-block;
vertical-align: top;
}
.search-wrapper button[type="submit"] {
display: inline-block;
vertical-align: top;
top: -35px;
position: relative;
background-color: transparent;
height: 30px;
width: 30px;
padding: 0;
margin: 0;
background-image: url("/wp-content/themes/acabado/img/search-icon.png");
background-position: center;
background-repeat: no-repeat;
background-size: contain;
}
.search-wrapper.search-active button[type="submit"] {
display: inline-block !important;
}</style>
<label for="s">
<span class="screen-reader-text">Search for:</span>
</label>
<input type="search" id="search-field" class="search-field" placeholder="Search &hellip;" value="" name="s">
<button type="submit" class="search-submit" style="display:none;"><span class="screen-reader-text"></span></button>
</form>
</div> </div>
</div>

<nav id="site-navigation" class="main-navigation">
<!-- <button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"></button> -->
<div class="menu-primary-container"><ul id="primary-menu" class="inner-wrap">
<li id="menu-item-461" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-461"><a href="/category/android-development/">Android Development</a></li>
<li id="menu-item-3905" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3905"><a href="/category/testing/">Testing</a></li>
<li id="menu-item-3906" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3906"><a href="/category/create-an-app-from-scratch/">Create an App From Scratch</a></li>
<li id="menu-item-3904" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3904"><a href="/category/jetpack/">Jetpack</a></li>
<li id="menu-item-3903" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3903"><a href="/category/development-tools/">Development Tools</a></li>
<li id="menu-item-3907" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3907"><a href="/category/android-game-development/">Android Game Development</a></li>
<li id="menu-item-307" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-307"><a href="/about-us/">About Us</a></li>
</ul></div> </nav><!-- #site-navigation -->
</header><!-- #masthead -->

<div id="content" class="site-content">

<div id="primary" class="content-area">

<main id="main" class="site-main">
<section class="articles-wrapper">
<h2 class="section-header-text">Recent Posts</h2>
<article class="article-card horizontal no-thumb">
<div class="copy-container">
<header>
<p><a href="/generating-random-numbers-in-kotlin-for-android/">Generating Random Numbers in Kotlin for Android</a></p>
</header>
<div class="excerpt">
<p>Randomness is required in a wide variety of different Android applications. For example, if you wanted your Android app to roll a die, flip a coin, or draw a card from a shuffled deck of cards, you...</p>
<div class="button-container"><a rel="nofollow" class="button reverse" href="/generating-random-numbers-in-kotlin-for-android/" aria-label="View Post: Generating Random Numbers in Kotlin for Android">View Post</a></div> </div>
<!-- <a class="button reverse" rel="nofollow" itemprop="mainEntityOfPage" href="">Continue Reading</a> -->
</div>
<!-- <meta itemprop="thumbnailUrl" src="--><!--">-->
<!-- <meta itemprop="image" src="--><!--">-->
<!-- <span itemprop="publisher" itemscope itemtype="http://schema.org/Organization">-->
<!-- <meta itemprop="name" content="--><!--">-->
<!-- </span>-->
<!-- <meta itemprop="logo" src="--><!--">-->
<!-- <meta itemprop="headline" content="--><!--">-->
<!-- <meta itemprop="author" content="--><!--">-->
<!-- <meta itemprop="datePublished" content="--><!--">-->
<!-- <meta itemprop="dateModified" content="--><!--">-->


</article>


<script type="application/ld+json">{"@context":"http:\/\/schema.org\/","@type":"BlogPosting","name":"Generating Random Numbers in Kotlin for Android","url":"\/generating-random-numbers-in-kotlin-for-android\/","articleBody":"Randomness is required in a wide variety of different Android applications. For example, if you wanted your Android app to roll a die, flip a coin, or draw a card from a shuffled deck of cards, you will need some form of random number generation to achieve this.\n\n\n\nKotlin makes it really easy to generate random numbers to use in your Android app.\n\n\n\nTo generate a random integer within a range of two numbers, you can define an IntRange and then invoke the random() function on the IntRange which will return a random integer that falls within the range.\n\n\n\nFor example, if you wanted to generate a random integer between 1 and 10, you would use the following code.\n\n\n\nvar randomInteger = (1..10).random()\n\n\n\nIn the blog post below I will take you through some other ways to generate randomness in your Android app using Kotlin.\n\n\n\nI will include code examples written in Kotlin that cover:\n\n\n\n\nHow to generate a random integer (using a simulated dice roll as an example)\n\n\n\nHow to generate a list of random integers (in just one line of code)\n\n\n\nHow to generate a random double (in just one line of code)\n\n\n\nHow to select a random item from a list (using a coin flip as an example) \n\n\n\nHow to shuffle a list in random order (using a playing cards deck as an example)\n\n\n\n\nAll of the code shared in this tutorial is available on GitHub in the link below.\n\n\n\nhttps:\/\/github.com\/learntodroid\/RandomNumbersKotlinAndroid\n\n\n\nHow to Generate a Random Integer in Kotlin\n\n\n\nI will include some of the code shared in the introduction of this post for generating a random integer to use in an Android app that simulates rolling a 6-sided dice.\n\n\n\nSimple Dice Rolling Android App\n\n\n\nFor the random number generation, I will create a Kotlin object called RandomSingleton that will be used as a singleton, meaning that only one instance of the object can be created and used throughout the app.\n\n\n\nRandomSingleton will include a function called randomInteger that has two Int params which are the from and to values to be used for the range of the random number.\n\n\n\nThen I will create an IntRange using those from and to numbers and call the random() function and return the random integer provided.\n\n\n\n\n\nIn the MainActivity, I will use a Jetpack Compose Composable function to display a Text element showing the rolled number and a Button to roll the dice\n\n\n\nWhen the Button is clicked it will use the randomInteger function on the RandomSingleton passing the from and to values as 1 and 6 respectively which will return the number of a random dice roll.\n\n\n\nThe app will also display a Toast message with the random number after it has been rolled.\n\n\n\n\n\nHow to Generate a List of Random Numbers in Kotlin\n\n\n\nIn Kotlin, you can generate a list of random numbers between two numbers by using the random() function on an IntRange along with the map function.\n\n\n\nSee the code excerpt from the RandomSingleton object below containing the function listOfRandomNumbers which shows how to accomplish this in just one line of code.\n\n\n\n\n\nTo make use of the listOfRandomNumbers function in your MainActivity, see the code sample below that contains a Composable function called RandomList that takes in the size of the list and minimum and maximum values for the random numbers.\n\n\n\n\n\nIt displays the list of generated random numbers using the listOfRandomNumbers function from the RandomSingleton object inside a Text element with a Button displayed underneath. When the Button is clicked it will re-generate and show the random numbers.\n\n\n\n\n\n\n\nHow to Generate a Random Double in Kotlin\n\n\n\nIn Kotlin, you can use the nextDouble function on the Random class to generate a random Double that falls within the range of two numbers.\n\n\n\nThe nextDouble function takes two parameters both of the type Double.\n\n\n\nThe random Double that is generated by the nextDouble function will be greater than or equal to the first parameter and will be less than the second parameter.\n\n\n\nI have updated the RandomSingleton object to include a function for generating a random Double called randomDouble.\n\n\n\n\n\nTo use the randomDouble function in the RandomSingleton object in the Android app, see a code excerpt below from the MainActivity class.\n\n\n\n\n\n\n\n\n\nHow to Select a Random Item from a List in Kotlin\n\n\n\nIn Kotlin, to retrieve a random item from a List all you need to do is call the random() function on a list and it will return a random item.\n\n\n\nI have updated the RandomSingleton object to include a function called randomStringFromList that takes a List of Strings as a parameter and will return a random item from that list using the random() function.\n\n\n\n\n\nThis can be used in the MainActivity class with the following code excerpt.\n\n\n\n\n\nIn the MainActivity we are using the randomStringFromList function on the RandomSingleton object by passing a List of the two faces of a coin (heads and tails) then retrieving the random result, simulating a random coin flip.\n\n\n\nThe result of the coin flip is shown in a Text element and the user can flip the coin again by clicking the Button.\n\n\n\nSimple Coin Flipping Android App\n\n\n\nHow to Shuffle a List in Random Order in Kotlin\n\n\n\nIn Kotlin, to randomize the order of a list, you can call the shuffle() function on a list.\n\n\n\nI have updated the RandomSingleton object to include a function called shuffleListOfStrings that takes a MutableList of Strings as a parameter and will return the MutableList of Strings in a random order once it has been shuffled using the shuffle() function.\n\n\n\n\n\nThis can be used in the MainActivity class with the following code excerpt.\n\n\n\n\n\nThe code above uses the shuffleListOfStrings function on the RandomSingleton object to take in a MutableList of Strings which are made up of a list of playing cards that need to be shuffled.\n\n\n\nThe implementation for the Deck class is also provided below.\n\n\n\n\n\nSimple Playing Cards Shuffling Android App","headline":"Generating Random Numbers in Kotlin for Android","author":{"@type":"Person","name":"Jarrod Lilkendey","url":""},"datePublished":"2023-01-18","mainEntityOfPage":"False","dateModified":"January 18, 2023","image":{"@type":"ImageObject","url":"","height":0,"width":0},"publisher":{"@context":"http:\/\/schema.org\/","@type":"Organization","name":"Learn to Droid","logo":{"@type":"ImageObject","url":"\/wp-content\/uploads\/2020\/05\/Learn-to-Droid-480-300x300.png","height":600,"width":60}}}</script>

<article class="article-card horizontal no-thumb">
<div class="copy-container">
<header>
<p><a href="/how-to-create-a-pie-chart-in-an-android-app-with-mpandroidchart/">How to Create a Pie Chart in an Android App with MPAndroidChart</a></p>
</header>
<div class="excerpt">
<p>https://www.youtube.com/watch?v=S3zqxVoIUig




All of the code samples in this post are available on GitHub.



Code Samples



Project Level Build.Gradle File





App Level Build.Gradle...</p>
<div class="button-container"><a rel="nofollow" class="button reverse" href="/how-to-create-a-pie-chart-in-an-android-app-with-mpandroidchart/" aria-label="View Post: How to Create a Pie Chart in an Android App with MPAndroidChart">View Post</a></div> </div>
<!-- <a class="button reverse" rel="nofollow" itemprop="mainEntityOfPage" href="">Continue Reading</a> -->
</div>
<!-- <meta itemprop="thumbnailUrl" src="--><!--">-->
<!-- <meta itemprop="image" src="--><!--">-->
<!-- <span itemprop="publisher" itemscope itemtype="http://schema.org/Organization">-->
<!-- <meta itemprop="name" content="--><!--">-->
<!-- </span>-->
<!-- <meta itemprop="logo" src="--><!--">-->
<!-- <meta itemprop="headline" content="--><!--">-->
<!-- <meta itemprop="author" content="--><!--">-->
<!-- <meta itemprop="datePublished" content="--><!--">-->
<!-- <meta itemprop="dateModified" content="--><!--">-->


</article>


<script type="application/ld+json">{"@context":"http:\/\/schema.org\/","@type":"BlogPosting","name":"How to Create a Pie Chart in an Android App with MPAndroidChart","url":"\/how-to-create-a-pie-chart-in-an-android-app-with-mpandroidchart\/","articleBody":"https:\/\/www.youtube.com\/watch?v=S3zqxVoIUig\n\n\n\n\nAll of the code samples in this post are available on GitHub.\n\n\n\nCode Samples\n\n\n\nProject Level Build.Gradle File\n\n\n\n\n\nApp Level Build.Gradle File\n\n\n\n\n\nActivity Layout Resource File\n\n\n\n\n\nMain Activity Class\n\n\n\n\n\nLinks\n\n\n\nMPAndroidChart on GitHub\n\n\n\nMPAndroidChart Documentation\n\n\n\nRelated Posts\n\n\n\n\n\/how-to-display-a-line-chart-in-your-android-app\/\n\n\n\n\n\n\/how-to-display-a-bar-chart-in-your-android-app\/","headline":"How to Create a Pie Chart in an Android App with MPAndroidChart","author":{"@type":"Person","name":"Jarrod Lilkendey","url":""},"datePublished":"2021-01-10","mainEntityOfPage":"False","dateModified":"January 10, 2021","image":{"@type":"ImageObject","url":"","height":0,"width":0},"publisher":{"@context":"http:\/\/schema.org\/","@type":"Organization","name":"Learn to Droid","logo":{"@type":"ImageObject","url":"\/wp-content\/uploads\/2020\/05\/Learn-to-Droid-480-300x300.png","height":600,"width":60}}}</script>

<article class="article-card horizontal no-thumb">
<div class="copy-container">
<header>
<p><a href="/how-to-create-a-bmi-calculator-android-app/">How to Create a BMI Calculator Android App</a></p>
</header>
<div class="excerpt">
<p>As a part of the series for creating apps from scratch, I have put together a tutorial on how to build a BMI calculator app for Android.



In this tutorial, we will build a BMI calculator app for...</p>
<div class="button-container"><a rel="nofollow" class="button reverse" href="/how-to-create-a-bmi-calculator-android-app/" aria-label="View Post: How to Create a BMI Calculator Android App">View Post</a></div> </div>
<!-- <a class="button reverse" rel="nofollow" itemprop="mainEntityOfPage" href="">Continue Reading</a> -->
</div>
<!-- <meta itemprop="thumbnailUrl" src="--><!--">-->
<!-- <meta itemprop="image" src="--><!--">-->
<!-- <span itemprop="publisher" itemscope itemtype="http://schema.org/Organization">-->
<!-- <meta itemprop="name" content="--><!--">-->
<!-- </span>-->
<!-- <meta itemprop="logo" src="--><!--">-->
<!-- <meta itemprop="headline" content="--><!--">-->
<!-- <meta itemprop="author" content="--><!--">-->
<!-- <meta itemprop="datePublished" content="--><!--">-->
<!-- <meta itemprop="dateModified" content="--><!--">-->


</article>


<script type="application/ld+json">{"@context":"http:\/\/schema.org\/","@type":"BlogPosting","name":"How to Create a BMI Calculator Android App","url":"\/how-to-create-a-bmi-calculator-android-app\/","articleBody":"As a part of the series for creating apps from scratch, I have put together a tutorial on how to build a BMI calculator app for Android.\n\n\n\nIn this tutorial, we will build a BMI calculator app for Android that:\n\n\n\nCaptures weight and height with EditText widgetsContains a class that uses the Singleton Pattern and contains the calculation logic for BMIUses a ToggleButton to support calculation of BMI with both the metric and imperial measurement systemsDisplays the calculated BMI and categorization of the BMI inside a CardView widget\n\n\n\nAll of the code samples shared in this post are available in GitHub.\n\n\n\nCreating a BMI Calculator Android App Tutorial\n\n\n\nIn this tutorial, we will be creating an Android app that calculates Body Mass Index (BMI) based height and weight entered by the user.\n\n\n\nWe will support both the metric unit system and the imperial unit system for calculating the BMI which allows the user to enter weight in either kilograms or pounds and the height in centimeters or feet and inches.\n\n\n\nSee the sample screenshots below for the Android app we will build.\n\n\n\n\n\n\n\nCreating a New Android Project\n\n\n\nWe will start this tutorial for building a BMI calculator by creating a brand new project in Android Studio.\n\n\n\nOpen Android Studio and follow the wizard for creating a new Android project. Select the \"Blank Activity\" project template and provide a project name, set the package name then select \"Finish\" to create the Android project.\n\n\n\n\n\n\n\nRemoving the Action Bar\n\n\n\nOnce the Android project has been created, open the styles.xml resource file in the \/app\/src\/main\/res\/values directory and update the parent attribute on the style element to value \"Theme.AppCompat.Light.NoActionBar\" to remove the Action Bar from the Activity.\n\n\n\nSee a sample of the styles.xml resource file that has removed the Action Bar below.\n\n\n\n\n\nSetting up the Activity Layout Resource\n\n\n\nWe will be using a single Activity for the BMI calculator app.\n\n\n\nIn the layout resource file for this Activity activity_main.xml, we will add the following user interface elements inside a LinearLayout with a vertical orientation.\n\n\n\n\n\nFirst, we will add a TextView inside the LinearLayout, that will display the title of the app as \"BMI Calculator\". We will center the TextView horizontally by setting the \"android:gravity\" attribute to \"center_horizontally\".\n\n\n\n\n\nThen, we will add a ToggleButton that we will use for toggling between the metric system and the imperial system of measurements for weight and height. We will default it to the metric system by setting the \"android:checked\" attribute value to \"true\" and setting the \"android:textOn\" attribute value to \"Metric Units\" and \"android:textOff\" to \"Imperial Units\".\n\n\n\n\n\nNext, we will add LinearLayout with a horizontal orientation and we will place two CardView widgets that will sit next to each other. These CardView widgets will be used for populating the height and weight information.\n\n\n\nBoth will the following attribute values populated to give the the CardView widgets rounded corners with a margin in between:\n\n\n\n\"android:layout_margin\" set to \"6dp\"\"app:cardElevation\" set to \"6dp\"\"app:cardCornerRadius\" set to \"6dp\"\n\n\n\nThe CardView on the left side will contain the height information. There will be TextView with the text of \"Height\" centered inside the CardView. \n\n\n\nUnderneath the TextView there will be an EditText for capturing the height in centimeters which only accepts decimal numbers via the attribute value of \"android:inputType\" set to \"numberDecimal\".\n\n\n\nThere will also be a LinearLayout with a horizontal orientation containing two EditText widgets for capturing the height in feet and inches.\n\n\n\nLater inside the Main Activity class, we will control the display of these EditText widgets based on whether the user has chosen to use the metric measurement system or the imperial system using the ToggleButton.\n\n\n\nThe CardView on the right side will contain the weight information. There will be TextView with the text of \"Weight\" centered inside the CardView.\n\n\n\nUnderneath that TextView there will be two EditText widgets that also only accept decimal numbers that will be used for capturing the weight in kilograms or in pounds.\n\n\n\n\n\nNext, we will add a Button with the label of \"Calculate\" which when selected will calculate the BMI and display the results underneath.\n\n\n\n\n\nFor that last part of the Activity layout we will add some UI elements for displaying the calculated BMI results.\n\n\n\nWe will add a CardView widget that will take up the full width of the screen.\n\n\n\nInside this CardView, we will show a TextView with the text of \"BMI\" centered inside the CardView.\n\n\n\nUnderneath this TextView, we will add another TextView that will be used for displaying the calculated BMI value.\n\n\n\nThen finally, we will have one more TextView that will display the category of the BMI calculated. These categories include \"Underweight\", \"Healthy Weight\", \"Overweight\" and \"Obese\".\n\n\n\n\n\nImplement a Class for Calculating BMI\n\n\n\nIn this section of the tutorial, we will create a new class that will contain methods used for calculating BMI in both imperial and metric units.\n\n\n\nWe will be creating this new class to separate the logic from calculating the BMI outside of the MainActivity logic that will be used for setting up the user interface and responding to events that occur in the UI.\n\n\n\nWe will give this new class the name \"BMICalcUtil\" and we will follow a singleton pattern where we will initialize a single instance of the BMICalcUtil and assign it to a class variable. We will then use a getter method called getInstance to retrieve this BMICalcUtil instance from within the MainActivity class.\n\n\n\nWe will add three more methods to the BMICalcUtil class.\n\n\n\nTwo of these methods will be used for calculating the BMI in the metric and the imperial unit system using the formulas below.\n\n\n\nSource: Vertex42.com\n\n\n\nThe third method will be used for classifying the BMI value as either \"Underweight\", \"Healthy Weight\", \"Overweight\" and \"Obese\" based on the table below.\n\n\n\nBMICategoryLess than 18.5UnderweightGreater than or equal to 18.5 and less than 25 Healthy WeightGreater than or equal to 25 and less than 30OverweightGreater than or equal to 30Obese\n\n\n\nSee a code sample of the BMICalcUtil class below.\n\n\n\n\n\nSetting up the Main Activity Class to Calculate and Display BMI Results\n\n\n\nIn this last section of the tutorial, we will update the MainActivity class to retrieve height and weight measurements entered by the user and to interact with the BMICalcUtil class to calculate then display the BMI results.\n\n\n\nIn the onCreate method, we will use the findViewById method to initialize class variables for the various UI elements we have added to the Activity layout resource.\n\n\n\nThese UI elements include:\n\n\n\nEditText widgets for capturing the weight and height measurements in both measurement systemsA ToggleButton for switching between the metric and imperial unit systemA Button for calculating the BMI resultsA CardView widget that will contain two TextView widgets for displaying the BMI result and category\n\n\n\nThen, in the onCreate method we will enable the metric system by default by setting the inMetricUnits boolean class variable to true.\n\n\n\nAfter that, we will invoke the updateInputsVisibility method we will add to the MainActivity class that is responsible for ensuring the correct EditText widgets are displayed on screen based on the measurement system that is being used.\n\n\n\nAlso in the onCreate method, we will hide the CardView widget used for displaying the BMI results by using the setVisibility method and passing the View.GONE value as a paramater.\n\n\n\nThen, we will set OnClickListeners to the Button used for calculating the BMI results and the ToggleButton for switching measurement systems.\n\n\n\nInside the OnClickListener for the ToggleButton in the onClick method we will toggle the value for the inMetricUnits boolean variable then call the updateInputsVisibility method to display the relevant EditText widgets on screen.\n\n\n\nIn the onClick method for the OnClickListener on the Button used for calculating the BMI results we will first check which measurement system is being used.\n\n\n\nThen we will check that those EditText widgets that relate to the selected measurement system are not blank. If any of the applicable EditText widgets are blank a Toast message will be shown to the user advising them to populate the weight and height information.\n\n\n\nAfter that, the values from the EditText widgets will be passed the BMICalcUtil by invoking either the calculateBMIMetric or calculateBMIImperial methods.\n\n\n\nThe BMI result will then be provided as a parameter to the displayBMI method which will show the BMI results CardView and update the TextView widgets inside the CardView with the BMI and the category.\n\n\n\nSee a code sample of the MainActivity class below.","headline":"How to Create a BMI Calculator Android App","author":{"@type":"Person","name":"Jarrod Lilkendey","url":""},"datePublished":"2021-01-08","mainEntityOfPage":"False","dateModified":"January 8, 2021","image":{"@type":"ImageObject","url":"","height":0,"width":0},"publisher":{"@context":"http:\/\/schema.org\/","@type":"Organization","name":"Learn to Droid","logo":{"@type":"ImageObject","url":"\/wp-content\/uploads\/2020\/05\/Learn-to-Droid-480-300x300.png","height":600,"width":60}}}</script>

<article class="article-card horizontal no-thumb">
<div class="copy-container">
<header>
<p><a href="/how-to-add-a-gradient-background-to-an-android-app/">How to Add a Gradient Background to an Android App</a></p>
</header>
<div class="excerpt">
<p>Adding a gradient as a background color to your an Android app can add extra interest and style and provide a great user experience.



In this post, I will walk you through the steps of how to add a...</p>
<div class="button-container"><a rel="nofollow" class="button reverse" href="/how-to-add-a-gradient-background-to-an-android-app/" aria-label="View Post: How to Add a Gradient Background to an Android App">View Post</a></div> </div>
<!-- <a class="button reverse" rel="nofollow" itemprop="mainEntityOfPage" href="">Continue Reading</a> -->
</div>
<!-- <meta itemprop="thumbnailUrl" src="--><!--">-->
<!-- <meta itemprop="image" src="--><!--">-->
<!-- <span itemprop="publisher" itemscope itemtype="http://schema.org/Organization">-->
<!-- <meta itemprop="name" content="--><!--">-->
<!-- </span>-->
<!-- <meta itemprop="logo" src="--><!--">-->
<!-- <meta itemprop="headline" content="--><!--">-->
<!-- <meta itemprop="author" content="--><!--">-->
<!-- <meta itemprop="datePublished" content="--><!--">-->
<!-- <meta itemprop="dateModified" content="--><!--">-->


</article>


<script type="application/ld+json">{"@context":"http:\/\/schema.org\/","@type":"BlogPosting","name":"How to Add a Gradient Background to an Android App","url":"\/how-to-add-a-gradient-background-to-an-android-app\/","articleBody":"Adding a gradient as a background color to your an Android app can add extra interest and style and provide a great user experience.\n\n\n\nIn this post, I will walk you through the steps of how to add a gradient background to your Android app including code samples.\n\n\n\nTo add a gradient background to your Android app, you need to do the following.\n\n\n\nCreate a drawable resource with a selector root elementAdd an item, shape, and gradient element to the drawable resourceOn the gradient element, set the type of gradient to use and provide the start and end colorsSet the background attribute on the layout resource of your fragment or activity to use the drawable resource\n\n\n\nCreating a Gradient Background in Android using a Drawable Resource\n\n\n\nIn this section of this post, I will go through step by step of how to create a gradient background in Android using a drawable resource.\n\n\n\nCreate a Drawable Resource with a Selector Root Element\n\n\n\nFirst, we will create a new drawable resource we will use for defining the gradient.\n\n\n\nSwitch your project in Android Studio into Project mode and navigate into the \/app\/src\/main\/res\/drawable folder. Right click on the \"drawable\" directory, hover over the \"New\" item and select the \"Drawable Resource File\" item.\n\n\n\n\n\n\n\nThen the \"New Drawable Resource File\" dialog will appear. Provide a file name for the drawable resource file you will use for the gradient background and set the root element to \"selector\". Then press the \"OK\" button to create the drawable resource file.\n\n\n\n\n\n\n\nFor drawable resources in Android, the selector element allows you to define child item elements that are selected based on a particular state. For example, a button could have different child items with different visual characteristics depending on whether the button is currently selected, focused, or pressed.\n\n\n\nYou should end up with a drawable resource file that contains a single selector element.\n\n\n\n\n\nAdding an Item, Shape, and Gradient Element to the Drawable Resource\n\n\n\nNext, we will make some minor changes the drawable resource file we created in the previous step for the gradient background.\n\n\n\nWithin the selector element, we will add a single item element. Each option to be selected from a selector is represented by an item element. We will only create a single item element as we do not need to change the appearance of the gradient based on a particular state.\n\n\n\nWithin the item element, we will add a shape element. The shape element can be used to define different shapes such as rectangles, lines, ovals and rings. It allows you to customize the appearance of the shape by changing characteristics such as the corners, setting a gradient, adding padding, setting the width and height sizes, setting a solid fill color and changing the outline of the shape using the stroke element.\n\n\n\nWithin the shape element, we will add a gradient element which we will configure in the next step to define the appearance of the gradient we will use for the background.\n\n\n\nSee a code sample below of a drawable resource file containing the selector, item, shape and gradient elements.\n\n\n\n\n\nConfiguring the Gradient Element in the Drawable Resource\n\n\n\nIn this part of the tutorial, we will add attributes to the gradient element in the drawable resource we created for the gradient background to configure the appearance of the gradient.\n\n\n\nThis will involve selecting the pattern of gradient we want to use, setting the colors of the gradient, and setting the positioning, direction, and size of the gradient.\n\n\n\nSetting the Gradient Pattern\n\n\n\nThere are three gradient pattern options to choose from in Android.\n\n\n\nLinearRadialSweep\n\n\n\nThe gradient pattern is defined on the gradient element by adding the android:type attribute and setting the value to either \"linear\", \"radial\" or \"sweep\".\n\n\n\nThe linear gradient is the default gradient.\n\n\n\nSee a sample screenshot of a linear gradient used for a gradient background in Android below.\n\n\n\nandroid:type is set to \"linear\"\n\n\n\nSample drawable resource code for the linear gradient pattern.\n\n\n\n\n\nThe radial gradient allows you to define a circular center color of the gradient using the start color attribute. The size of the circle can be defined using the gradient radius attribute.\n\n\n\nSee a sample screenshot of a radial gradient used for a gradient background in Android below.\n\n\n\nandroid:type is set to \"radial\"\n\n\n\nSample drawable resource code for the radial gradient pattern.\n\n\n\n\n\nThe sweep gradient offers a sweeping line gradient.\n\n\n\nSee a sample screenshot of a sweep gradient used for a gradient background in Android below.\n\n\n\nandroid:type is set to \"sweep\"\n\n\n\nSample drawable resource code for the sweep gradient pattern.\n\n\n\n\n\nSetting the Gradient Colors\n\n\n\nThere are up to three colors that can be defined on a gradient.\n\n\n\nStart color which is defined using the android:startColor attributeEnd color which is defined using the android:endColor attributeCenter color which is defined using the android:centerColor attribute\n\n\n\nThese colors are set as attributes on the gradient element and the value can either be a hexidemical value representing a color e.g. \"#FFFFFF\" for the color white or they can be set using a color resource.\n\n\n\nUsing a color resource is a good method to use as it allows you to define all the colors you use across your Android app in a single location inside the colors.xml resource file in the \/app\/src\/main\/res\/values directory to simplify any color branding changes you want to make to your Android app in the future.\n\n\n\nSee a sample colors resource file below containing three colors.\n\n\n\n\n\nSee a screenshot below of a linear gradient with the start, end and center colors defined.\n\n\n\n\n\n\n\nThis linear gradient with start, center and end colors was created using the following code.\n\n\n\n\n\nIt is also worth mentioning there are some great free tools available on the internet that can help you find contrasting colors that are pleasant to look at to use for gradients.\n\n\n\nTwo tools I like are UI Gradients and Web Gradients.\n\n\n\nScreenshot from UI Gradients\n\n\n\nScreenshot from Web Gradients\n\n\n\nSetting the Positioning, Direction, and Size of the Gradient\n\n\n\nThe center position of the gradient can be changed using the android:centerX and android:centerY attributes. The value of the centerX and centerY attributes is a relative position defined as a Float value ranging from 0 to 1.0.\n\n\n\nThe angle of the gradient can be set using the android:angle attribute using the Integer value representing the angle in degrees. This value must be a multiple of 45. A value of 0, which is the default value, represents an angle of left to right, a value of 90 represents an angle of bottom to top.\n\n\n\nIn the case of a radial gradient pattern, the size of the circle in the gradient can be changed using the android:gradientRadius attribute which will accept a Float value.\n\n\n\nSetting Background Attribute to use the Drawable Resource\n\n\n\nNow that we have finished creating the gradient in the drawable resource file, we will need to update the layout resource file for our Activity or Fragment to the drawable resource for the background.\n\n\n\nIn your layout resource file for your Activity or Fragment, locate the root layout whether that is a LinearLayout, RelativeLayout, ConstraintLayout, or something else, and set the android:background attribute on the layout to the drawable resource we created.\n\n\n\nSee a code sample for setting a drawable resource as a background for a ConstraintLayout for the main activity inside the activity layout resource file.\n\n\n\n\n\nBonus: A Great Tool to Automate the Creation of Gradient Backgrounds in Android\n\n\n\nAs I was putting together this tutorial I found a free tool that can speed up this process for generating gradient backgrounds for Android apps.\n\n\n\nThere is a free to use code generator tool available on the internet called Angry Tools that can be used to generate the code for the drawable resource containing the gradient using the user interface.\n\n\n\nAngry Tools - Code Generator for Gradient Drawable Resources in Android","headline":"How to Add a Gradient Background to an Android App","author":{"@type":"Person","name":"Jarrod Lilkendey","url":""},"datePublished":"2021-01-03","mainEntityOfPage":"False","dateModified":"January 3, 2021","image":{"@type":"ImageObject","url":"","height":0,"width":0},"publisher":{"@context":"http:\/\/schema.org\/","@type":"Organization","name":"Learn to Droid","logo":{"@type":"ImageObject","url":"\/wp-content\/uploads\/2020\/05\/Learn-to-Droid-480-300x300.png","height":600,"width":60}}}</script>

<article class="article-card horizontal no-thumb">
<div class="copy-container">
<header>
<p><a href="/how-to-use-ibms-watson-speech-to-text-service-in-an-android-app/">How to Use IBM’s Watson Speech to Text Service in an Android App</a></p>
</header>
<div class="excerpt">
<p>There are a number of different speech to text APIs that exist today. I experiment with IBM's Watson Speech to Text service to see how easy it is to integrate with an Android app and the accuracy of...</p>
<div class="button-container"><a rel="nofollow" class="button reverse" href="/how-to-use-ibms-watson-speech-to-text-service-in-an-android-app/" aria-label="View Post: How to Use IBM’s Watson Speech to Text Service in an Android App">View Post</a></div> </div>
<!-- <a class="button reverse" rel="nofollow" itemprop="mainEntityOfPage" href="">Continue Reading</a> -->
</div>
<!-- <meta itemprop="thumbnailUrl" src="--><!--">-->
<!-- <meta itemprop="image" src="--><!--">-->
<!-- <span itemprop="publisher" itemscope itemtype="http://schema.org/Organization">-->
<!-- <meta itemprop="name" content="--><!--">-->
<!-- </span>-->
<!-- <meta itemprop="logo" src="--><!--">-->
<!-- <meta itemprop="headline" content="--><!--">-->
<!-- <meta itemprop="author" content="--><!--">-->
<!-- <meta itemprop="datePublished" content="--><!--">-->
<!-- <meta itemprop="dateModified" content="--><!--">-->


</article>


<script type="application/ld+json">{"@context":"http:\/\/schema.org\/","@type":"BlogPosting","name":"How to Use IBM’s Watson Speech to Text Service in an Android App","url":"\/how-to-use-ibms-watson-speech-to-text-service-in-an-android-app\/","articleBody":"There are a number of different speech to text APIs that exist today. I experiment with IBM's Watson Speech to Text service to see how easy it is to integrate with an Android app and the accuracy of the transcription results.\n\n\n\nI have done some research and created a sample Android app that demonstrates how to integrate with IBM's Watson Speech to Text service in Android. I have put together a step by step guide on how to accomplish this.\n\n\n\nTo use IBM Watson's Speech to Text service in an Android app you will need to:\n\n\n\nCreate an IBM Cloud AccountEnable the Speech to Text service and obtain your API KeyAdd the IBM Watson SDK to your Android project with GradleRequest INTERNET and RECORD_AUDIO permissions in the Manifest fileMake a runtime request in the Activity class for access to the RECORD_AUDIO permissionUse the MediaRecorder API to make an audio recording of your speechConvert audio recording to MP3 format using the FFMPEG libraryProvide the audio recording in an MP3 format to the Speech to Text APIRetrieve the response containing the converted text and display the text in a RecyclerView\n\n\n\nIn this tutorial, I will walk you through each of these steps in detail and provide code samples embedded in this blog post that are also available for free on GitHub.\n\n\n\nI have also created a video of this tutorial that is available on YouTube which I have embedded below.\n\n\n\n\nhttps:\/\/www.youtube.com\/watch?v=JUJCp0Nxnc0\n\n\n\n\nAndroid Watson Speech to Text Tutorial\n\n\n\nCreating an IBM Cloud Account\n\n\n\nIn order to use IBM's Watson Text to Speech service, you will need to create an IBM Cloud account.\n\n\n\nNavigate to the IBM Cloud account registration form in a web browser and fill out account information with an email address and password.\n\n\n\nThen you will need to verify your email address using a code sent via email.\n\n\n\nAfter that you will need to enter some personal information for your account, then you can select the \"Create account\" button.\n\n\n\n\n\n\n\nEnabling Speech to Text and Obtaining API Key\n\n\n\nNow that you have created an IBM Cloud account, what you will need to do next is create a Speech to Text resource you can use against your account.\n\n\n\nIn the IBM Cloud home screen, select the \"Create resource\" button in the top right section of the screen.\n\n\n\n\n\n\n\nAfter that, go into the \"Services\" section.\n\n\n\n\n\n\n\nThen, search for \"Speech to Text\" in the service catalogue and select the \"Speech to Text\" result.\n\n\n\n\n\n\n\nThen, you can pick the region your service will be based in. We will want to use the Lite Plan for our Speech to Text service, which currently allows you to perform 500 minutes a month of speech to text for free.\n\n\n\nWhen you are ready to create the service, select the \"Create\" button.\n\n\n\n\n\n\n\nOnce the service has been created, go into the Manage section and note the API key and the base URL of the URL shown in this screen which we will copy over to our Android app in a subsequent step.\n\n\n\n\n\n\n\nRetrieve Gradle Dependencies\n\n\n\nIn this section of the tutorial, we will create a new Android project in Android Studio, then we will retrieve the dependencies required to use IBM's Watson Speech to Text service in our Android app using Gradle.\n\n\n\nOnce you have created a new Android project, open the app level build.gradle file where we make some changes.\n\n\n\nIn the dependencies section of the app level build.gradle file, we will add two dependencies. The first for the IBM Watson SDK and the second for the mobile FFMPEG library. \n\n\n\nThe IBM Watson SDK will be used to interact with the Watson Speech to Text service. The mobile FFMPEG library is required to convert the audio recording we will make of our speech into an MP3 format that can be consumed by the Watson speech to text service.\n\n\n\nIn addition to this, we will a line in the defaultConfig section to enable multi dex.\n\n\n\nAlso in order to use the mobile FFMPEG library in your Android app, you will also need to set the minSdkVersion to at least version 24.\n\n\n\nSee the sample app level build.gradle file below.\n\n\n\n\n\nRequest Permissions in the Manifest\n\n\n\nIn this section of the tutorial, we will request access to two permissions in the Android app's manifest file.\n\n\n\nIn the app's manifest file we will need to add the INTERNET permission as we will invoke the Speech to Text service over the Internet.\n\n\n\nWe will also need to add the RECORD_AUDIO permission as we will be using the device's microphone to record and audio clip which we will provide to the Speech to Text service to translate it into text.\n\n\n\nSee the sample app manifest file containing the INTERNET and RECORD_AUDIO permission below.\n\n\n\n\n\nRequest Audio Recording Run Time Permission\n\n\n\nIn Android, the RECORD_AUDIO permission is considered a dangerous permission, which means you will need to make a run time request inside your Activity class to prompt the user to provide their consent to use the device's microphone.\n\n\n\nSee the code sample below for the MainActivity class requesting the RECORD_AUDIO permission at run time.\n\n\n\n\n\nRecord Speech using MediaRecorder API\n\n\n\nIn this section of the tutorial, we will use Android's MediaRecorder API to create an audio recording of our speech from the microphone on the device that we will provide to the Speech to Text service to convert.\n\n\n\nBefore we implement the audio recording functionality into our Android app, we will need to update the Activity layout resource with some additional widgets.\n\n\n\nWe will include a Button which will be used to trigger the audio recordingWe will add a RecyclerView to present the text from the converted speech along with a confidence intervalFor this RecyclerView, we will also add a TextView as a label called \"Results\"\n\n\n\n\n\n\n\nCheck out the Activity layout resource file used for the MainActivity below.\n\n\n\n\n\nNext, we will update the Main Activity class and add a new method which record audio from the device's microphone when the \"START RECORDING\" Button is selected.\n\n\n\nWe will give this method the name \"startRecording\". At the start of the method, we will create a file name for the file to be used to record the audio and another file name for the file which will contain the audio converted into MP3 format. We will use a random UUID and provide a path inside internal storage for the recorded and convert files.\n\n\n\nNext, we will use the MediaRecorder API to record audio into a file with the 3GPP file format.\n\n\n\nWe will need to create a new MediaRecorder object then perform the following actions to start recording audio:\n\n\n\nInvoke the setAudioSource method passing the MediaRecorder.AudioSource.MIC parameter to record audio from the device's microphoneInvoke the setOutputFormat method passing the MediaRecorder.OutputFormat.THREE_GPP parameter to use the 3GPP file formatInvoke the setAudioEncoder method passing the MediaRecorder.AudioEncoder.AMR_NB parameter to use the Adaptive Multi-Rate audio codec for audio encodingInvoke the setOutputFile method passing the recorded file pathInvoke the prepare method to up MediaRecorder to record audioInvoke the start method to start recording audio\n\n\n\nSee a code sample of the MainActivity class below, containing the startRecording method for recording audio using the device microphone in the 3GPP file format.\n\n\n\n\n\nIf you would like to learn more about recording audio in Android, check out the following post I wrote on this topic below.\n\n\n\n\n\/how-to-record-audio-in-android-programmatically\/\n\n\n\n\nConvert Audio Recording to MP3 using FFMPEG\n\n\n\nThe Watson Speech to Text API doesn't support audio files in the 3GPP format. The MediaRecorder API for Android doesn't support recording audio into an MP3 format. As covered in the previous step, we recorded the audio of the speech into the 3GPP file format which has the extension \".3gp\".\n\n\n\nTo get around this restriction with the Watson Speech to Text API we will convert the audio recording from the 3GPP file format into MP3 format before sending it using the FFMPEG library.\n\n\n\nIn our Android project, we will configure the \"START RECORDING\" Button to toggle to \"CONVERT SPEECH\" while the audio recording is in progress, then we will toggle back to \"START RECORDING\" if the audio is not currently recording.\n\n\n\nIf the Button is selected while the audio recording is in progress a new Thread will be created and started which will be used for converting the audio file into MP3 format.\n\n\n\nWe will create a new method speech convertSpeech where we will use FFMPEG to convert the audio file into the MP3 format.\n\n\n\nFirst, in the convertSpeech method, we will stop recording the audio and set up the MediaRecorder for reuse later by calling the stop method, the reset method then the release method on the MediaRecorder.\n\n\n\nAfter that, we will execute a FFMPEG command using the libmp3lame MP3 encoder with the file names of the recorded file and the converted file which will convert the audio file into the MP3 format.\n\n\n\nWe will then check the return code provided to the FFMPEG command above and log if the command was successful, canceled or if there was an error.\n\n\n\nIn the next section of this tutorial, we will invoke the Watson Speech to Text API if the return code from the FFMPEG command was successful.\n\n\n\n\n\nProvide the Audio Recording to the Speech to Text API\n\n\n\nIn this section of the tutorial, we will invoke the Speech to Text API via the Watson SDK passing the audio file in MP3 format that we want to convert into text.\n\n\n\nIn the MainActivity class, we will create two String constants at the start of the class containing the API key and the URL for interacting with the Speech to Text service.\n\n\n\nInside the convertSpeech method, if the return code from the FFMPEG command to convert the audio file to MP3 format is successful, we will add some additional code the call the Watson Speech to Text API.\n\n\n\nBefore we can invoke the Speech To Text API, we will need to create an IamAuthenticator object passing the API key as a parameter.\n\n\n\nThen we will need to create a SpeechToText object passing the IamAuthenticator as a parameter. On the SpeechToText object we will also need to invoke the setServiceUrl method passing the base URL of the Watson Speech to Text service.\n\n\n\nThen, we will need to construct an object containing RecognizeOptions using the builder.\n\n\n\nWe will use the audio method on the builder to set the path to the converted audio fileWe will use the contentType method on the builder to use the MP3 format by passing the value HttpMediaType.AUDIO_MP3Then we will use the model method on the builder and provide the value of \"en-AU_NarrowbandModel\"\n\n\n\nThen we will invoke the build method on the builder.\n\n\n\nTo get a JSON string of the results from the Speech to Text API, we will create a SpeechRecognitionResults object and assign it to value retrieved from the API.\n\n\n\nTo call the API, we will use the SpeechToText object and call the recognize method passing in the Recognize options, then we will call the execute method and finally we will call the getResult method.\n\n\n\n\n\nRetrieve Speech to Text Response and Display Inside a RecyclerView\n\n\n\nIn this last section of the tutorial, we will create a RecyclerAdapter and parse the JSON string containing the transcription results from the Speech To Text API to display inside a RecyclerView.\n\n\n\nFirst, we will create a Result model to be used inside the RecyclerView. Each Result will contain a String of the transcription and a double representing the confidence of the transcription.\n\n\n\nSee the sample class for the Result below.\n\n\n\n\n\nNext, we will create an item layout to be used for each Result displayed in the RecyclerView. The item layout will be made up of two TextViews inside a horizontally oriented LinearLayout with the transcription on the left side and the confidence value on the right side.\n\n\n\nSee the sample item layout resource file for the Result below.\n\n\n\n\n\nAfter that, we will create a custom RecyclerAdapter and Recycler ViewHolder to be used with the Results from the Speech to Text API.\n\n\n\nSee the sample RecyclerAdapter below.\n\n\n\n\n\nFinally, we will update the MainActivity class inside the convertSpeech method to parse the JSON string and provide a List of Result objects to the RecyclerAdapter we created above.\n\n\n\nSee the sample MainActivity class below.\n\n\n\n\n\nAll of the code shared in this tutorial is available on GitHub at the following link.\n\n\n\nhttps:\/\/github.com\/learntodroid\/AndroidIBMSpeechToText","headline":"How to Use IBM’s Watson Speech to Text Service in an Android App","author":{"@type":"Person","name":"Jarrod Lilkendey","url":""},"datePublished":"2020-10-25","mainEntityOfPage":"False","dateModified":"October 25, 2020","image":{"@type":"ImageObject","url":"","height":0,"width":0},"publisher":{"@context":"http:\/\/schema.org\/","@type":"Organization","name":"Learn to Droid","logo":{"@type":"ImageObject","url":"\/wp-content\/uploads\/2020\/05\/Learn-to-Droid-480-300x300.png","height":600,"width":60}}}</script>

<article class="article-card horizontal no-thumb">
<div class="copy-container">
<header>
<p><a href="/how-to-use-ibms-watson-text-to-speech-service-in-an-android-app/">How to Use IBM&#8217;s Watson Text to Speech Service in an Android App</a></p>
</header>
<div class="excerpt">
<p>I was playing around with a demo I found online that uses the Watson Text to Speech platform from IBM and I was really impressed with the quality of speech that was generated.



Following that, I...</p>
<div class="button-container"><a rel="nofollow" class="button reverse" href="/how-to-use-ibms-watson-text-to-speech-service-in-an-android-app/" aria-label="View Post: How to Use IBM&#8217;s Watson Text to Speech Service in an Android App">View Post</a></div> </div>
<!-- <a class="button reverse" rel="nofollow" itemprop="mainEntityOfPage" href="">Continue Reading</a> -->
</div>
<!-- <meta itemprop="thumbnailUrl" src="--><!--">-->
<!-- <meta itemprop="image" src="--><!--">-->
<!-- <span itemprop="publisher" itemscope itemtype="http://schema.org/Organization">-->
<!-- <meta itemprop="name" content="--><!--">-->
<!-- </span>-->
<!-- <meta itemprop="logo" src="--><!--">-->
<!-- <meta itemprop="headline" content="--><!--">-->
<!-- <meta itemprop="author" content="--><!--">-->
<!-- <meta itemprop="datePublished" content="--><!--">-->
<!-- <meta itemprop="dateModified" content="--><!--">-->


</article>


<script type="application/ld+json">{"@context":"http:\/\/schema.org\/","@type":"BlogPosting","name":"How to Use IBM’s Watson Text to Speech Service in an Android App","url":"\/how-to-use-ibms-watson-text-to-speech-service-in-an-android-app\/","articleBody":"I was playing around with a demo I found online that uses the Watson Text to Speech platform from IBM and I was really impressed with the quality of speech that was generated.\n\n\n\nFollowing that, I did some research on how I could integrate the Watson Text to Speech service with an Android app and I have put together a step by step guide on how to accomplish this.\n\n\n\nTo use IBM Watson's Text to Speech service in an Android app you will need to:\n\n\n\nCreate an IBM Cloud AccountEnable the Text to Speech Service and Obtain your API KeyAdd the IBM Watson SDK to your Android project with Gradle and Enable the INTERNET permission in the Manifest fileProvide the Text and the Voice to use to the IBM Watson Text to Speech Service using the SDKRetrieve the Response Containing an Audio File and Save it into Internal StoragePlay the Audio file using the Android MediaPlayer API\n\n\n\nIn this tutorial, I will walk you through each of these steps in detail and provide code samples embedded in this blog post that are also available for free on GitHub.\n\n\n\nI have also created a video of this tutorial that is available on YouTube which I have embedded below.\n\n\n\n\nhttps:\/\/www.youtube.com\/watch?v=DU5Wu-5L1h4\n\n\n\n\nAndroid Watson Text to Speech Tutorial\n\n\n\nCreating an IBM Cloud Account\n\n\n\nIn order to use IBM's Watson Text to Speech service, you will need to create an IBM Cloud account.\n\n\n\nNavigate to the IBM Cloud account registration form in a web browser and fill out account information with an email address and password.\n\n\n\nThen you will need to verify your email address using a code sent via email.\n\n\n\nAfter that you will need to enter some personal information for your account, then you can select the \"Create account\" button.\n\n\n\n\n\n\n\nEnabling Text to Speech and Obtaining API Key\n\n\n\nNow that you have created an IBM Cloud account, what you will need to do next is create a Text to Speech resource you can use against your account.\n\n\n\nIn the IBM Cloud home screen, select the \"Create resource\" button in the top right section of the screen.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nAfter that, go into the \"Services\" section and search for \"Text to Speech\" in the service catalogue.\n\n\n\n\n\n\n\nSelect the \"Text to Speech\" service, from there you are able to pick the region your service will be based in. We will want to use the Lite Plan for our Text to Speech service, which currently allows you to perform text to speech on up to 10,000 characters for free per month.\n\n\n\nWhen you are ready to create the service, select the \"Create\" button.\n\n\n\n\n\n\n\nOnce the service has been created, go into the Manage section and note the API key and the base URL of the URL shown in this screen which we will copy over to our Android app in a subsequent step.\n\n\n\n\n\n\n\nRetrieve Gradle Dependencies and Manifest Updates\n\n\n\nIn this section of the tutorial, we will create a new Android project in Android Studio, then we will make changes to the app manifest file and the app level build.gradle file.\n\n\n\nOnce you have created a new Android project, open the app level build.gradle file where we make two changes.\n\n\n\nIn the dependencies section of the app level build.gradle file, we will add a new line to retrieve the IBM Watson dependency.\n\n\n\nIn addition to this, we will a line in the defaultConfig section to enable multi dex.\n\n\n\nSee the sample app level build.gradle file below.\n\n\n\n\n\nIn the app's manifest file we will need to add the INTERNET permission as we will invoke the Text to Speech service over the Internet.\n\n\n\nSee the sample app manifest file containing the INTERNET permission below.\n\n\n\n\n\nInvoke the Watson Text to Speech Service Passing the Text and the Selected Voice\n\n\n\nIn this section of the tutorial, we will invoke the Text to Speech API via the Watson SDK passing the text we want to convert to speech and the voice that we have chosen.\n\n\n\nIn the layout resource for the MainActivity, we will add an EditText that will contain the text we want to convert to speech along with a Button which when selected will invoke the Text to Speech service.\n\n\n\nIn the MainActivity class, we will create two constants at the start of the class containing the API key and the URL for interacting with the Text to Speeech service.\n\n\n\nIn the onCreate method, we will set up variables for the EditText and the Button. For the Button we will add an OnClickListener.\n\n\n\nInside the onClick method in the OnClickListener, we will instantiate a new Thread passing a new Runnable.\n\n\n\nInside the Runnable in the run method, we will retrieve the text we want to convert to speech from the EditText and check that it has been populated.\n\n\n\nIf there is text populated, we will then invoke a new method we will create for interacting with the Watson Text to Speech service called createSoundFile where we will pass the text and a voice to use as parameters.\n\n\n\nBefore we can invoke the Text To Speech service, we will need to create an IamAuthenticator object passing the API key as a parameter.\n\n\n\nFrom there we can create a TextToSpeech object passing the IamAuthenticator object as a parameter. For the TextToSpeech object we will need to invoke the setServiceUrl method passing the base URL of our Watson Text To Speech Service available in the IBM Cloud console.\n\n\n\nThen, we will need to construct an object containing SynthesizeOptions using the builder. With the builder we will set the text we want to use, we will provide to format of the audio file we want to receive as \"audio\/mp3\" and we will give the voice option we want to use.\n\n\n\nAfter that, we can invoke the Text To Speech service by calling the synthesize method on the TextToSpeech object passing the SynthesizeOptions as a parameter and invoking the execute method.\n\n\n\nAfter the Thread has been instantiated, we will execute it using the start method on the Thread.\n\n\n\nSee the code sample for the MainActivity class below.\n\n\n\n\n\nSave the Audio File Containing Speech into Internal Storage\n\n\n\nIn this step of the tutorial, we will save the audio file we receive in the response from the Text to Speech service containing the speech into internal storage.\n\n\n\nI had added some lines to the createSoundFile method which opens an InputStream on the result retrieved from the Text to Speech service.\n\n\n\nFrom there a new file is created is internal storage where we will write the contents of the response using a byte array with a predefined buffer size.\n\n\n\nSee the code sample for the MainActivity class below.\n\n\n\n\n\nPlay the Audio File Containing Speech using the Android MediaPlayer API\n\n\n\nNext, we will create a new method to play the sound file containing the speech once it is retrieved from the Text to Speech service.\n\n\n\nWe will create a new method called playSoundFile which will take a String parameter containing the name of the file in internal storage that contains speech.\n\n\n\nIn the playSoundFile method, we will create a reference to the File in internal storage by creating a File object passing the internal storage files directory along with the name of the file.\n\n\n\nUsing the File object, we will retrieve the Uri of the File which can be consumed by the MediaPlayer API.\n\n\n\nNext, we will create a new MediaPlayer object, we will configure the MediaPlayer object to play audio by invoking the setAudioAttributes method or the setAudioStreamType method depending on the Android SDK version.\n\n\n\nAfter that, the Uri of the audio file will be provided to the MediaPlayer using the setDataSource method passing the Uri as a parameter.\n\n\n\nThen, we will call the setOnPreparedListener method on the MediaPlayer and create a new OnPreparedListener which invokes the start media on the MediaPlayer in the onPrepared method.\n\n\n\nAfter that, we will invoke the prepareAsync method on the MediaPlayer to play the audio file.\n\n\n\nThen finally, the playSoundFile method is added in the run method after the createSoundFile method is called inside the OnClickListener added to the Button.\n\n\n\nSee the code sample for the MainActivity class below.","headline":"How to Use IBM’s Watson Text to Speech Service in an Android App","author":{"@type":"Person","name":"Jarrod Lilkendey","url":""},"datePublished":"2020-09-27","mainEntityOfPage":"False","dateModified":"October 9, 2020","image":{"@type":"ImageObject","url":"","height":0,"width":0},"publisher":{"@context":"http:\/\/schema.org\/","@type":"Organization","name":"Learn to Droid","logo":{"@type":"ImageObject","url":"\/wp-content\/uploads\/2020\/05\/Learn-to-Droid-480-300x300.png","height":600,"width":60}}}</script>
<nav class="pagination-wrapper" aria-label="article pagination">
<span aria-current="page" class="page-numbers current"><span class="screen-reader-text">Page </span>1</span>
<a class="page-numbers" href="/?page_num=2#038;simply_static_page=1"><span class="screen-reader-text">Page </span>2</a>
<a class="page-numbers" href="/?page_num=3#038;simply_static_page=1"><span class="screen-reader-text">Page </span>3</a>
<span class="page-numbers dots">&hellip;</span>
<a class="page-numbers" href="/?page_num=8#038;simply_static_page=1"><span class="screen-reader-text">Page </span>8</a>
<a class="next page-numbers" href="/?page_num=2#038;simply_static_page=1">NEXT &raquo;</a></nav>
</section>
</main><!-- #main -->

<aside id="secondary" class="widget-area">
<div class="about-wrapper">
<h2 class="widget-title">About Us</h2> <p class="about-copy">LearnToDroid is an online resource focused on providing quality content that helps our readers learn how to design, create and market outstanding apps for Android.</p>
<button onclick="window.location.href='http://10.0.0.14:32769/about-us/';">Read More</button>
<!-- <div class="button-wrapper"><a class="button" href=""></a></div> -->
</div>
<section id="text-2" class="widget widget_text"><h2 class="widget-title">Social Accounts</h2> <div class="textwidget">
<p><a href="https://github.com/learntodroid" target="_blank" rel="noopener"><img decoding="async" class="alignnone wp-image-4454 size-full" src="/wp-content/uploads/2020/08/iconfinder_29_939731.png" alt="" width="64" height="64"></a> <a href="https://www.youtube.com/channel/UCHb-uOTkX7f6gZh0jj2c5zQ/" target="_blank" rel="noopener"><img decoding="async" class="alignnone wp-image-4452 size-full" src="/wp-content/uploads/2020/08/iconfinder_6_939754.png" alt="" width="64" height="64"></a> <a href="https://www.facebook.com/learntodroid" target="_blank" rel="noopener"><img decoding="async" class="alignnone wp-image-4451 size-full" src="/wp-content/uploads/2020/08/iconfinder_3_939757.png" alt="" width="64" height="64"></a> <a href="https://twitter.com/learntodroid1" target="_blank" rel="noopener"><img decoding="async" class="alignnone wp-image-4453 size-full" src="/wp-content/uploads/2020/08/iconfinder_4_939755.png" alt="" width="64" height="64"></a></p>
</div>
</section><section id="custom_html-2" class="widget_text widget widget_custom_html"><div class="textwidget custom-html-widget">
<!-- Ezoic - sidebar_floating_1 - sidebar_floating_1 -->
<div id="ezoic-pub-ad-placeholder-108"> </div>
<!-- End Ezoic - sidebar_floating_1 - sidebar_floating_1 -->
</div></section></aside><!-- #secondary -->

</div>
<!-- #primary -->


</div>
<!-- #content -->

<footer id="colophon" class="site-footer">
<div class="inner-wrap">
<div class="site-info">
&copy; 2024 Copyright Learn to Droid </div>
<!-- .site-info -->
<div class="footer-ad">
<p><!-- Ezoic - bottom_of_page - bottom_of_page --></p>
<div id="ezoic-pub-ad-placeholder-103"> </div>
<p><!-- End Ezoic - bottom_of_page - bottom_of_page --></p>
</div>
</div>
</footer><!-- #colophon -->
</div>
<!-- #page -->

<script type="text/javascript" async defer src="/wp-content/plugins/lazy-load-for-videos/public/js/lazyload-shared.js?ver=2.18.3" id="lazyload-video-js-js"></script>
<script type="text/javascript" id="lazyload-youtube-js-js-before">
/* <![CDATA[ */
window.llvConfig=window.llvConfig||{};window.llvConfig.youtube={"colour":"red","buttonstyle":"","controls":true,"loadpolicy":true,"thumbnailquality":"0","preroll":"","postroll":"","overlaytext":"","loadthumbnail":true,"cookies":false,"callback":"<!--YOUTUBE_CALLBACK-->"};
/* ]]> */
</script>
<script type="text/javascript" async defer src="/wp-content/plugins/lazy-load-for-videos/public/js/lazyload-youtube.js?ver=2.18.3" id="lazyload-youtube-js-js"></script>
<script type="text/javascript" id="lazyload-vimeo-js-js-before">
/* <![CDATA[ */
window.llvConfig=window.llvConfig||{};window.llvConfig.vimeo={"buttonstyle":"","playercolour":"","preroll":"","postroll":"","show_title":false,"overlaytext":"","loadthumbnail":true,"thumbnailquality":false,"cookies":false,"callback":"<!--VIMEO_CALLBACK-->"};
/* ]]> */
</script>
<script type="text/javascript" async defer src="/wp-content/plugins/lazy-load-for-videos/public/js/lazyload-vimeo.js?ver=2.18.3" id="lazyload-vimeo-js-js"></script>
<script type="text/javascript" async defer src="/wp-content/themes/acabado/js/app.min.js?ver=1.0.10" id="income-school-js-js"></script>
<script type="text/javascript" id="q2w3_fixed_widget-js-extra">
/* <![CDATA[ */
var q2w3_sidebar_options = [{"sidebar":"sidebar-1","use_sticky_position":false,"margin_top":0,"margin_bottom":0,"stop_elements_selectors":"","screen_max_width":0,"screen_max_height":0,"widgets":["#custom_html-2"]}];
/* ]]> */
</script>
<script type="text/javascript" async defer src="/wp-content/plugins/q2w3-fixed-widget/js/frontend.min.js?ver=6.2.3" id="q2w3_fixed_widget-js"></script>
<div style="display: none"></div>
</body>
</html>

Ads.Txt Alerts - A trading name of Red Volcano Limited

Waterloo Buildings, Second Floor Rear, 53 London Road, Southampton, Hampshire, United Kingdom, SO15 2AD

© Red Volcano 2020. All Rights Reserved.