Langsung ke konten utama

Postingan

Download file using Okio in Android

Okio is a library that complements java.io and java.nio to make it much easier to access, store, and process your data. Simply Okio is a modern I/O API for Java.  In this post, we will see how to download image or any file using Okio. Okio is component for OkHttp Coding Part Create a new project in Android Studio. Add following dependencies to your  app-level  build.gradle  file. compile 'com.squareup.okhttp3:okhttp:3.6.0' Don't forget to add the following permission in your AndroidManifest.xml <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> Implementation Paste the following code in your Activity and Here, I have kept as MainActivity.java public void downloadImg(View view) { try { Request request = new Request.Builder() .url(imageLink) .build(); new OkHttpClient().newCall(request).enqueue(new Callback() { @Override public void onFail...

Youtube Video link to mp3 file - Library

Library to Download youtube video as mp3 files Created By How to Download Gradle: compile 'com.ajts.androidmads.youtubemp3:youtubemp3:1.0.0' Maven: <dependency> <groupId>com.ajts.androidmads.youtubemp3</groupId> <artifactId>youtubemp3</artifactId> <version>1.0.0</version> <type>pom</type> </dependency> How to use this Library: This Library is used to download mp3 file from youtube video link. new YTubeMp3Service.Builder(MainActivity.this) .setDownloadUrl("https://youtu.be/nZDGC-tXCo0") .setFolderPath(new File(Environment.getExternalStorageDirectory(), "/YTMp3/Downloads").getPath()) .setOnDownloadListener(new YTubeMp3Service.Builder.DownloadListener() { @Override public void onSuccess(String savedPath) { Log.v("exce", savedPath); progressDialog.dismiss(); } @Override public void onDownloadStarted() { ...

SQLite Importer Exporter - Library

A light weight library for exporting and importing sqlite database in android Created By How to Download Gradle: compile 'com.ajts.androidmads.sqliteimpex:library:1.0.0' Maven: <dependency> <groupId>com.ajts.androidmads.sqliteimpex</groupId> <artifactId>library</artifactId> <version>1.0.0</version> <type>pom</type> </dependency> How to use this Library: This Library is used to import SQLite Database from Assets or External path and Export/Backup SQLite Database to external path. SQLiteImporterExporter sqLiteImporterExporter = new SQLiteImporterExporter(getApplicationContext(), db); // Listeners for Import and Export DB sqLiteImporterExporter.setOnImportListener(new SQLiteImporterExporter.ImportListener() { @Override public void onSuccess(String message) { Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); } @Override public void onFailure(Exception exception...

Room Android Architecture

In Google I/O 2017, Google announced about Room Architecture for Android. This Architecture is used to maintain the State of Android Application when the orientation changes. As well as google announced about Room Architecture. Room We have more boiler plates while creating SQLite Database in Android even it is small. Room as a library used to remove the boiler plates like Cursors & Handlers and database can be handled with annotations and model classes. If we remember about Sugar ORM or Active Android , the same approach is dealt with Room.  We don't want to go for any third party libraries, when the official Android libraries give you an equal, or better solution. Life Cycle Activity We have faced the problem mostly as that  to maintain the State of Android Application when the orientation changes. The Life Cycle Activity used to handle the state easily. Coding Part Create a new project in Android Studio. First, Add Google’s maven repository to your project-level build.g...

RecyclerView & ListView in Kotlin

In this tutorial, we will learn how to build ListView and RecyclerView with Custom Adapter in Kotlin. Everybody knows what is Listview and Recyclerview. So, without any introduction about them we will jump into the coding part of the Tutorial. Coding Part Kotlin ListView Example We should follow the same steps to create Activity with associated layout file for example MainActivity.kt with activity_main.xml Create ListView Adapter Create new class and named as MoviesListViewAdapter and paste the following. class MoviesListViewAdapter(private val activity: Activity, moviesList: List ) : BaseAdapter() { private var moviesList = ArrayList () init { this.moviesList = moviesList as ArrayList } override fun getCount(): Int { return moviesList.size } override fun getItem(i: Int): Any { return i } override fun getItemId(i: Int): Long { return i.toLong() } @SuppressLint("InflateParams", "ViewHolder") ...

Kotlin Android Extensions

Kotlin Android Extensions is an important Kotlin plugin that is similar to Butterknife. It will allow to recover views in android. Implementation Add the following plugins in your app level build.gradle file apply plugin:'com.android.application' apply plugin:'kotlin-android' apply plugin:'kotlin-android-extensions' Coding Part Create a new layout file in res folder, name it as activity_main.xml and paste the following codes <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context="com.androidmads.kotlinsample_helloworld.MainActivity"...

Firebase Phone Authentication - Example

Hi Friends. In this tutorial, we will learn how to implement firebase phone authentication with it's origin. Digits is an Simple User Phone Authentication Service to create easy login experience. Now Digits is acquired by Google's Firebase and it provides free service for limited amount of authentication per month. However, if you need to sign in a very high volume of users with phone authentication, you might need to upgrade your pricing plan. See the pricing  page.  You can use Firebase Authentication to sign in a user by sending an SMS message to the user's phone. The user signs in using a one-time code contained in the SMS message. Setup Firebase To setup firebase in your project, read previous post . After setting up, open Authentication sign in method and enable phone authentication method. You should Add SHA Fingerprint in your application. To get SHA Fingerprint use the following Code with Command Prompt in Windows keytool -list -v -keystore "%USERPROFILE%\.and...

Circle Image View using Glide and Picasso in Android

Hello guys, In this tutorial we will learn how to create Circular Image View in Android without using any additional Libraries such as CircleImageView . // This Library is very Popular and Widely used for Circle Image View compile 'de.hdodenhof:circleimageview:2.1.0' Nowadays, Every Android Developers uses Glide  or Picasso Image HTTP Libraries to Image in Image Views. If we uses any additional Libraries to get Circle Shaped Image View may lead to increase the size of an APK. To avoid this, Glide and Picasso provides solution to create Circle Image View. First, we will see how create circle image using Picasso. Circle Transformation using Picasso Download Picasso by Gradle in Android // This Library is created by Square.Inc compile 'com.squareup.picasso:picasso:2.5.2' The following snippet is used to load image into ImageView using Picasso Picasso.with(getApplicationContext()).load("http://i.imgur.com/DvpvklR.png") .placeholder(R.mipmap.ic_launcher) ...

Kotlin - Basics

Hello Guys, we already knew that Google announced Kotlin is a new first class language for Android Development. So, we started the Kotlin series for learning Kotlin for android. We have seen the "Hello World" Program for Android in our previous post.  You can download Intellij idea Commuinty Edition or use Kotlin Online Compiler provided by Intellij In this post, we will learn the basics of kotlin. 1. Hello World The Following Snippet shows the Hello world Program and is similar to Java. fun main(args: Array <string>) { println("Hello, world!") } 2. Variables and Constants The Following Snippet shows the How to use Variables and Constants with Datatype in Kotlin. Variables can be re-assigned  // Variable - Values Can be reassigned var a = 10 a = a + 10 println(a) Constants cannot be re-assigned and if we did will error as "val cannot be reassigned" // Constants - Values cannot reassigned val x = 10 println(x) We can specify the Data types for...

Hello World - Kotlin

Kotlin - Android Programming Language Google officially announced Kotlin as a first class language for Android development at Google I/O 2017. From Android Studio 3.0, Kotlin is included as  Support for Android Studio. In this post, we will start the development of Android Application with Kotlin. To Getting Started, you have to download Android Studio 3.0 Canary 1  or Add the Kotlin plugin in your existing Android Studio. Create Android Project with Kotlin Create new project in Android studio check the Kotlin support and start as usual with Android Studio 3.0.  Android Studio 3.0 But for Android Studio with version less than 3.0, we have install plugin form Plugins menu manually by Selecting File-->Settings-->Plugins-->Browse Repositories--> Search and Select Kotlin. Then Click Install Now inside activity_main.xml create the following UI <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="htt...

Android Place Picker API

Hello guys, today we gonna learn one of the greatest API for android provide by Google is called Place Picker API. This API is used to Pick Place from Google Maps Application without any Map Integration.  The PlacePicker provides a UI dialog that displays an interactive map and a list of nearby places, including places corresponding to geographical addresses and local businesses. Users can choose a place, and your app can then retrieve the details of the selected place.  Project Setup You should follow the steps as proceeded below Step 1 - Get Your SHA1 Key For using Google Places API, We need to know SHA1 Key, which is used in Google Developer Console . You can get your SHA1 Key using Command Prompt. keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android Step 2 - Enable Google Places API in Developer Console Open Google Console Site . Create New Project or You can use your Existing Project. Go to Dashboar...