When we are trying to install apps in mobile some times it shows different kind of messages like “App not installed”. So This time First Uninstall old version. then Install App Manager App (find the link below): https://play.google.com/store/apps/details?id=com.lb.app_manager Then Open the app Click on Apk files the you will find list of apps like below […]
Android Tutorials
Sending FireBase Notification to Android Mobiles

FCM website https://firebase.google.com/docs/cloud-messaging App.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' android { compileSdkVersion 29 buildToolsVersion "29.0.3" defaultConfig { applicationId "com.androindian.fcmtest" minSdkVersion 16 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.firebase:firebase-messaging:17.3.4' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } |
project.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.6.1' classpath 'com.google.gms:google-services:4.2.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } |
FCMNotification.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
package com.androindian.fcmtest; import android.util.Log; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; public class FCMNotification extends FirebaseMessagingService { String TAG; @Override public void onMessageReceived(RemoteMessage remoteMessage) { // ... // TODO(developer): Handle FCM messages here. // Not getting messages here? See why this may be: https://goo.gl/39bRNJ Log.d(TAG, "From: " + remoteMessage.getFrom()); // Check if message contains a data payload. if (remoteMessage.getData().size() > 0) { Log.d(TAG, "Message data payload: " + remoteMessage.getData()); } // Check if message contains a notification payload. if (remoteMessage.getNotification() != null) { Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); } // Also if you intend on generating your own notifications as a result of a received FCM // message, here is where that should be initiated. See sendNotification method below. } @Override public void onNewToken(String token) { Log.d(TAG, "Refreshed token: " + token); // If you want to send messages to this application instance or // manage this apps subscriptions on the server side, send the // Instance ID token to your app server. } } |
Manifest.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.androindian.fcmtest"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name=".FCMNotification"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> </application> </manifest> |
Login Session Using SharedPreferences

Now a days each and every application is having the session management. This is Using Shared preferences we can manage very simple. please check the below Code and video also there. activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?xml version="1.0" encoding="utf-8"?> <layout 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"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello Shared Prefences" android:layout_gravity="center" /> <EditText android:id="@+id/mobile" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="phone" android:hint="Mobile"/> <EditText android:id="@+id/pass" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPassword" android:hint="Password"/> <Button android:id="@+id/save" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Login" /> </LinearLayout> </layout> |
MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
package com.androindian.login; import androidx.appcompat.app.AppCompatActivity; import androidx.databinding.DataBindingUtil; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import com.androindian.login.databinding.ActivityMainBinding; public class MainActivity extends AppCompatActivity { ActivityMainBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding= DataBindingUtil.setContentView(MainActivity.this,R.layout.activity_main); binding.save.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences preferences=getSharedPreferences("Login",MODE_PRIVATE); //edit SharedPreferences.Editor editor=preferences.edit(); //editor.putString("Key","values"); editor.putString("Pass",binding.pass.getText().toString()); editor.putString("Mobile",binding.mobile.getText().toString()); editor.commit(); Intent intent=new Intent(MainActivity.this,Menupage.class); startActivity(intent); } }); } } |
activity_splash.xml
1 2 3 4 5 6 7 8 9 10 |
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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" tools:context=".Splash" android:background="@color/colorPrimary"> </androidx.constraintlayout.widget.ConstraintLayout> |
Splash.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
package com.androindian.login; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; public class Splash extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); new Handler().postDelayed(new Runnable() { @Override public void run() { SharedPreferences preferences=getSharedPreferences("Login",MODE_PRIVATE); String s1=preferences.getString("Pass",null); String s2=preferences.getString("Mobile",null); if(s1==null && s2==null){ Intent intent=new Intent(Splash.this,MainActivity.class); startActivity(intent); finish(); }else { Intent intent=new Intent(Splash.this,Menupage.class); startActivity(intent); finish(); } } },3000); } } |
activity_menu.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version="1.0" encoding="utf-8"?> <layout> <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" tools:context=".Menupage" android:orientation="vertical"> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="logout" /> </LinearLayout> </layout> |
MenuPage.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
package com.androindian.login; import androidx.appcompat.app.AppCompatActivity; import androidx.databinding.DataBindingUtil; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.Toast; import com.androindian.login.databinding.ActivityMenupageBinding; public class Menupage extends AppCompatActivity { ActivityMenupageBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding= DataBindingUtil.setContentView(Menupage.this,R.layout.activity_menupage); SharedPreferences preferences=getSharedPreferences("Login",MODE_PRIVATE); String s1=preferences.getString("Pass",null); String s2=preferences.getString("Mobile",null); Toast.makeText(this, ""+s1+s2, Toast.LENGTH_SHORT).show(); binding.button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences preferences=getSharedPreferences("Login",MODE_PRIVATE); SharedPreferences.Editor editor=preferences.edit(); editor.clear(); editor.commit(); } }); } } |
Output Refer in Youtube Video.
What is AsyncTask in Android?

Android UI Main Thread Android handles input events/tasks with a single User Interface (UI) thread and the thread is called Main thread. Main thread cannot handle concurrent operations as it handles only one event/operation at a time. Concurrent Processing in Android If input events or tasks are not handled concurrently, whole code of an Android […]
Progress Dialog (Circular)

Progress dialog with java. This is predefined and also its deprecated. gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
apply plugin: 'com.android.application' android { compileSdkVersion 29 buildToolsVersion "29.0.3" defaultConfig { applicationId "com.androindian.progress" minSdkVersion 16 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { dataBinding.enabled=true release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } |
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?xml version="1.0" encoding="utf-8"?> <layout> <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" tools:context=".MainActivity" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/circular" android:text="Circular Dialog"></Button> </LinearLayout> </layout> |
MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
package com.androindian.progress; import androidx.appcompat.app.AppCompatActivity; import androidx.databinding.DataBindingUtil; import android.app.ProgressDialog; import android.os.Bundle; import android.view.View; import com.androindian.progress.databinding.ActivityMainBinding; public class MainActivity extends AppCompatActivity { ActivityMainBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding= DataBindingUtil.setContentView(MainActivity.this,R.layout.activity_main); binding.circular.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ProgressDialog progressDialog=new ProgressDialog(MainActivity.this); progressDialog.setTitle("Please Wait"); progressDialog.setMessage("Content Loading"); //progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.show(); } }); } } |
Output
Predefined Dialog

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed. Building an Alert Dialog The AlertDialog class allows you to build a […]
Android – Get battery level and percentage programmatically

activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" tools:context=".MainActivity" android:background="#d5ebfa" > <ProgressBar android:id="@+id/pb" android:layout_width="150dp" android:layout_height="150dp" style="@android:style/Widget.ProgressBar.Horizontal" android:progressDrawable="@drawable/progressbar_states" android:layout_centerInParent="true" /> <TextView android:id="@+id/tv_percentage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25dp" android:textColor="#000" android:layout_centerInParent="true" /> <TextView android:id="@+id/tv_info" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20dp" /> </RelativeLayout> |
in drawable create once xml file to percentage in style progressbar_states.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape android:shape="oval"> <stroke android:width="5dp" android:color="#d0d4d7" /> <solid android:color="#eef2f5"/> </shape> </item> <item android:id="@android:id/progress"> <clip android:clipOrientation="vertical" android:gravity="bottom"> <shape android:shape="oval"> <stroke android:width="5dp" android:color="#ff0001" /> <gradient android:startColor="#7fc97c" android:endColor="#99f396" android:centerColor="#89e386" android:angle="270" android:gradientRadius="50" android:centerY=".50" /> </shape> </clip> </item> </layer-list> |
MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
package com.androindian.battery; import androidx.appcompat.app.AppCompatActivity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; import android.os.Bundle; import android.view.Window; import android.widget.ProgressBar; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private Context mContext; private TextView mTextViewInfo; private TextView mTextViewPercentage; private ProgressBar mProgressBar; private int mProgressStatus = 0; private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE,-1); mTextViewInfo.setText("Battery Scale : " + scale); int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1); mTextViewInfo.setText(mTextViewInfo.getText() + "\nBattery Level : " + level); float percentage = level/ (float) scale; mProgressStatus = (int)((percentage)*100); mTextViewPercentage.setText("" + mProgressStatus + "%"); mTextViewInfo.setText(mTextViewInfo.getText() + "\nPercentage : "+ mProgressStatus + "%"); mProgressBar.setProgress(mProgressStatus); } }; @Override protected void onCreate(Bundle savedInstanceState) { // Request window feature action bar requestWindowFeature(Window.FEATURE_ACTION_BAR); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the application context mContext = getApplicationContext(); IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); mContext.registerReceiver(mBroadcastReceiver,iFilter); mTextViewInfo = (TextView) findViewById(R.id.tv_info); mTextViewPercentage = (TextView) findViewById(R.id.tv_percentage); mProgressBar = (ProgressBar) findViewById(R.id.pb); } } |
output
Runtime permissions

Welcome to android runtime permissions example. With the introduction of Android 6.0 Marshmallow, Google has changed the way permissions are handled by the app. In this tutorial we’ll look into the new android runtime permissions that are introduced and how to handle them. If not handled properly, it can cause application crashes. What are Android […]
How to implement phone number Verification by OTP using Firebase in Android

Hey guys! In this tutorial, I am covering user verification by phone number by sending OTP to the mobile using Firebase authentication. You can use Firebase Authentication to enable a user to sign in to your app by sending an SMS to user’s device which contains a one-time-password. The user then enters this OTP in […]
How to get Current Latitude and longitude in Android

This Android tutorial is to help learn How to get current latitude and longitude in the Android platform. Knowing the current location in an android mobile will pave the way for developing many innovative Android apps to solve people’s daily problem. For developing the location-aware application in android, it needs location providers. I have added […]