Android Development Tips - Ep #6 - Network Inspection using Chucker
Misplaced Lens Cap
Xuebing Du

taylor price

todays bird
h
$LAYYYTER

Product Placement

ellievsbear
2025 on Tumblr: Trends That Defined the Year

pixel skylines

JBB: An Artblog!
NASA

Love Begins

oozey mess
cherry valley forever
we're not kids anymore.
seen from United States
seen from United States

seen from Dominican Republic
seen from United Kingdom

seen from United Kingdom

seen from United States

seen from United Kingdom
seen from United States

seen from France
seen from United States

seen from United States

seen from United Kingdom

seen from United States
seen from United States

seen from Colombia

seen from Spain
seen from Germany
seen from United States

seen from United States
seen from China
@probelalkhan
Android Development Tips - Ep #6 - Network Inspection using Chucker

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
#1 Android Notification Tutorial - Introduction
Here is the second part of Firestore Android Tutorial. This time we will fetch back the stored data from Cloud Firestore.
Comment on the video for any kind of query. And stay tuned for the next update. Thank You
Here is the 29th video of Build a Wallpaper App in Android Series
You will learn a lot of things here: -> Downloading an Bitmap from URL -> Saving the Bitmap to Phone Storage as a File -> Asking for Storage Permission -> Opening the image
Our app is finished with this video. Now we just need to integrate AdMob Ads in the App and then we can publish it to play store.
Small decos, like changing icon also remaining.
PS: Don't forget to SHARE it with your friends. Thank You :)
#21 Build a Wallpaper App in Android - Wallpapers Activity

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Here is another very important tutorial if you want to work with Firebase Realtime Database.
In this tutorial we will learn, how we can implement some common SQL queries in Firebase Realtime Database.
PS: Don't forget to SHARE. And also TAG your friends. Thank You :)
Here is the first video on Android ProjectIn this video we will perform the following tasks-> Project Creation and Basic Setup-> Designing and Implementing Splash ScreenPS: Don't forget to SHARE :)
New Post has been published on Simplified Coding
New Post has been published on https://www.simplifiedcoding.net/how-to-search-location-in-google-map-in-android/
How to Search Location in Google Map in Android?
Hi, guys here is another useful tutorial. You might require searching locations on google map. We already learned about integrating google maps in our application in some previous posts. In this post, we will learn “How to Search Location in Google Map in Android?”
Before moving ahead, let me tell you what exactly we are going to do. So we will display map, the user can search a location on the map, and then we will show the marker at the searched location on the map.
Contents
1 Creating a new Android Project
1.1 Getting an API Key
1.2 Using the PlaceAutoCompleteFragment for Searching Location
1.2.1 Adding PlaceAutoCompleteFragment Dependency
1.2.2 Adding PlaceAutoCompleteFragment in Activity
1.2.3 Enabling Places API
1.3 Searching the Location
2 Search Location in Google Map Source Code
Creating a new Android Project
As always we will create a new project. So open Android Studio and create a project with Google Maps Activity.
When you create a project or activity with Google Maps Activity Template, a file named google_maps_api.xml is created. Inside this file you need to define the API Key to work with maps.
Getting an API Key
To get the API Key go to this link. And then click on GET A KEY.
(adsbygoogle = window.adsbygoogle || []).push();
You need to paste the key inside string tag that is created inside the file google_maps_api.xml. You can find this file inside app->res->values
Now you can run your application and you will see the Google Map in your Activity.
Using the PlaceAutoCompleteFragment for Searching Location
Adding PlaceAutoCompleteFragment Dependency
Go to your app level build.gradle file and make sure the following dependencies are added.
dependencies implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' //these two lines should be added implementation 'com.google.android.gms:play-services-maps:12.0.1' implementation 'com.google.android.gms:play-services-places:12.0.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
Adding PlaceAutoCompleteFragment in Activity
Now come inside the file activity_maps.xml which is created while creating the project. You need to modify your code as shown below.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="net.simplifiedcoding.locationsearchexample.MapsActivity"> <fragment android:id="@+id/place_autocomplete_fragment" android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" android:layout_width="match_parent" android:layout_height="wrap_content" /> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/place_autocomplete_fragment" /> </RelativeLayout>
Enabling Places API
You also need to enable Google Places API to make it work. So go to this link.
You need to do the same thing, click on GET A KEY on the top, and then select the same project that you selected while creating the API Key for Google Map. It will enable Google Places API and will give you another KEY. You can use this key as well, but it is not necessary as we already have the key.
Searching the Location
Now go to MapsActivity.java and here you will find the below code that is available by default.
package net.simplifiedcoding.locationsearchexample; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MapsActivity extends FragmentActivity implements OnMapReadyCallback private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); @Override public void onMapReady(GoogleMap googleMap) mMap = googleMap; LatLng sydney = new LatLng(-34, 151); mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
You need to add the following code at the end of onCreate() method.
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment); autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() @Override public void onPlaceSelected(Place place) mMap.clear(); mMap.addMarker(new MarkerOptions().position(place.getLatLng()).title(place.getName().toString())); mMap.moveCamera(CameraUpdateFactory.newLatLng(place.getLatLng())); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(), 12.0f)); @Override public void onError(Status status) );
Now thats it, run your application.
As you can see it is working absolutely fine.
Search Location in Google Map Source Code
If you are having any kind of problem then you can try my source code from this GitHub repository.
How to Search Location in Google Map in Android Source Code
So thats all for this tutorial friends. I hope you found this helpful. For any query, you can leave your comments. Thank You 🙂
Android is improving the notifications with every updates. From android noughat we got Direct Reply Notification. You have already seen this in feature in WhatsApp. Now we can directly reply to the notifications. Lets learn we can do the same in our android project.
New Post has been published on Simplified Coding
New Post has been published on https://www.simplifiedcoding.net/direct-reply-notification-android/
Direct Reply Notification in Android like WhatsApp Tutorial
(adsbygoogle = window.adsbygoogle || []).push();
Hey guys, here is another useful tutorial. Today we will learn about Direct Reply Notification in Android. You might have seen this feature already in the very popular messaging app WhatsApp. Now we can directly reply to WhatsApp messages without even opening WhatsApp.
So if you are searching how you can implement this feature in your Android Project then, this is what we will be learning in this tutorial. So let’s begin.
Contents
1 Creating a new Android Studio Project
1.1 Creating Interface
1.2 Defining Constants
1.3 Creating Notification Channel
1.4 Adding Click Listener to Button
1.5 Building Direct Reply Notification
1.6 Creating a Notification Action Handler
1.7 Displaying Direct Reply Notification
1.8 Download Source Code
Creating a new Android Studio Project
As always let’s do this thing in a new Android Studio Project. So for my Direct Reply Notifications I’ve already created a project named DirectReplyNotification.
Creating Interface
Here we have nothing much to do. We will create only a simple button and pressing that button will create a notification. As this post is only for an example so we are not going to cover about push notifications here. We will only see how Direct Reply Notification works. If you want to learn about push notification you can check Firebase Cloud Messaging Tutorial here.
So come inside activity_main.xml and create a button here.
<?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" tools:context="net.simplifiedlabs.directreplynotification.MainActivity"> <Button android:id="@+id/buttonCreateNotification" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="Create Notification" /> </RelativeLayout>
The above xml will generate the following design.
Direct Reply Notification Example
Defining Constants
For this project we need some constants values, like CHANNEL_ID, CHANNEL_NAME etc. So, first define all the Constant values inside MainActivity.java.
public class MainActivity extends AppCompatActivity { public static final String NOTIFICATION_REPLY = "NotificationReply"; public static final String CHANNNEL_ID = "SimplifiedCodingChannel"; public static final String CHANNEL_NAME = "SimplifiedCodingChannel"; public static final String CHANNEL_DESC = "This is a channel for Simplified Coding Notifications"; public static final String KEY_INTENT_MORE = "keyintentmore"; public static final String KEY_INTENT_HELP = "keyintenthelp"; public static final int REQUEST_CODE_MORE = 100; public static final int REQUEST_CODE_HELP = 101; public static final int NOTIFICATION_ID = 200;
Creating Notification Channel
So, from Android Nougat, creating a notification channel is compulsory for displaying notifications. Inside onCreate(), we will check if the device version is Android N or greater we will create a notification channel.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel mChannel = new NotificationChannel(CHANNNEL_ID, CHANNEL_NAME, importance); mChannel.setDescription(CHANNEL_DESC); mChannel.enableLights(true); mChannel.setLightColor(Color.RED); mChannel.enableVibration(true); mChannel.setVibrationPattern(new long[]100, 200, 300, 400, 500, 400, 300, 200, 400); mNotificationManager.createNotificationChannel(mChannel);
Adding Click Listener to Button
Now, we will attach an OnClickListener to the Button. So inside onCreate() write the following lines of code.
findViewById(R.id.buttonCreateNotification).setOnClickListener(new View.OnClickListener() @Override public void onClick(View v) displayNotification(); );
Inside onClick() we are firing a method named displayNotification(). So we need to define this method inside MainActivity.
public void displayNotification()
Inside this method, we will build the notification.
Building Direct Reply Notification
Now lets define the displayNotification() method to display our Direct Reply Notification.
public void displayNotification() //Pending intent for a notification button named More PendingIntent morePendingIntent = PendingIntent.getBroadcast( MainActivity.this, REQUEST_CODE_MORE, new Intent(MainActivity.this, NotificationReceiver.class) .putExtra(KEY_INTENT_MORE, REQUEST_CODE_MORE), PendingIntent.FLAG_UPDATE_CURRENT ); //Pending intent for a notification button help PendingIntent helpPendingIntent = PendingIntent.getBroadcast( MainActivity.this, REQUEST_CODE_HELP, new Intent(MainActivity.this, NotificationReceiver.class) .putExtra(KEY_INTENT_HELP, REQUEST_CODE_HELP), PendingIntent.FLAG_UPDATE_CURRENT ); //We need this object for getting direct input from notification RemoteInput remoteInput = new RemoteInput.Builder(NOTIFICATION_REPLY) .setLabel("Please enter your name") .build(); //For the remote input we need this action object NotificationCompat.Action action = new NotificationCompat.Action.Builder(android.R.drawable.ic_delete, "Reply Now...", helpPendingIntent) .addRemoteInput(remoteInput) .build(); //Creating the notifiction builder object NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNNEL_ID) .setSmallIcon(android.R.drawable.ic_dialog_email) .setContentTitle("Hey this is Simplified Coding...") .setContentText("Please share your name with us") .setAutoCancel(true) .setContentIntent(helpPendingIntent) .addAction(action) .addAction(android.R.drawable.ic_menu_compass, "More", morePendingIntent) .addAction(android.R.drawable.ic_menu_directions, "Help", helpPendingIntent); //finally displaying the notification NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Right now you will see error on NotificationReceiver.class, as we haven’t created it yet.
Creating a Notification Action Handler
Now, finally we need to handle the input, and other buttons in the notification. For this we will create a Broadcast Receiver.
Create a class named NotificationReceiver and write the following code.
package net.simplifiedlabs.directreplynotification; import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NotificationCompat; import android.support.v4.app.RemoteInput; import android.widget.Toast; /** * Created by Belal on 2/27/2018. */ public class NotificationReceiver extends BroadcastReceiver @Override public void onReceive(Context context, Intent intent) //getting the remote input bundle from intent Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); //if there is some input if (remoteInput != null) //getting the input value CharSequence name = remoteInput.getCharSequence(MainActivity.NOTIFICATION_REPLY); //updating the notification with the input value NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, MainActivity.CHANNNEL_ID) .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle("Hey Thanks, " + name); NotificationManager notificationManager = (NotificationManager) context. getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(MainActivity.NOTIFICATION_ID, mBuilder.build()); //if help button is clicked if (intent.getIntExtra(MainActivity.KEY_INTENT_HELP, -1) == MainActivity.REQUEST_CODE_HELP) Toast.makeText(context, "You Clicked Help", Toast.LENGTH_LONG).show(); //if more button is clicked if (intent.getIntExtra(MainActivity.KEY_INTENT_MORE, -1) == MainActivity.REQUEST_CODE_MORE) Toast.makeText(context, "You Clicked More", Toast.LENGTH_LONG).show();
We also need to define this receiver inside our AndroidManifest.xml file. So write the following xml code inside the <application> tag.
<receiver android:name=".NotificationReceiver" android:enabled="true" android:exported="false"></receiver>
Displaying Direct Reply Notification
Now, we have everything, and to display the notification, we just need to play the application and then hit on the Create Notification Button.
Android Direct Reply Notification
Bingo! it is working absolutely fine.
Download Source Code
Now, if you still having some issues, you can check my GitHub Repository for this project from the link given below.
Android Direct Reply Notification Example Source Code
So, that’s all for this Direct Reply Notification Example friends. If you are having any confusions regarding this tutorial, feel free to leave your comments. And if you think the post is helpful please SHARE it with your friends. Thank You 🙂

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
#1 TypeScript Tutorial for Beginners - Introduction
Learn to -> create a Bottom Navigation View-> design it-> put menus in it and -> switch the screens when the navigation menus are clicked. Please don't forget to SUBSCRIBE to my channel if you haven't already SUBSCRIBED. Thank You :)
Here is a complete step by step guide about using Bottom Navigation in your Android Application. In this Bottom Navigation Android Example we will learn how to add a Bottom Navigation View, how to switch fragments when the Navigation Menus are clicked.
New Post has been published on Simplified Coding
New Post has been published on https://www.simplifiedcoding.net/bottom-navigation-android-example/
Bottom Navigation Android Example using Fragments
In Android, there are many options for making navigation easy in your application for the user. Bottom Navigation Bar is one of them. Bottom Navigation Bar always stays at the bottom of your application and provides navigation between the views of your application. So in this Bottom Navigation Android Example, we will see how we combine the Bottom Navigation and Fragments.
Contents
1 Android Bottom Navigation
2 Using Bottom Navigation in Android
3 Bottom Navigation Android Example
3.1 Defining Colors and Strings
3.2 Customizing Bottom Navigation View
3.3 Creating Fragments
3.3.1 Creating Layout Resource Files
3.3.2 Creating Fragments
3.4 Switching Fragments
4 Bottom Navigation Android Example Source Code
Android Bottom Navigation
Below you can see a Bottom Navigation.
Bottom Navigation Android
I guess many of you are already aware with this component, or you might have seen this thing in some applications. We use Bottom Navigation When we have at least 3 top level navigation views.
Using Bottom Navigation in Android
It is very easy, you can create a Bottom Navigation Activity in your project by following ways.
#1 you just need to use <android.support.design.widget.BottomNavigationView />, if you want to do it in XML.
#2 Android Studio also have a predefined template for creating BottomNavigationView, when you create a new Activity you can select Bottom Navigation Activity, as shown in the image.
Bottom Navigation Android Activity
#3 While creating an Android Project you can select Bottom Navigation Activity from the template.
Bottom Navigation Android Activity from Templates
Bottom Navigation Android Example
Now lets see everything in an Android Project.
Defining Colors and Strings
I have created a project named BottomNavigationExample using a Bottom Navigation Activity. You can choose Empty Activity, it will not make any difference.
Now first, we will define the colors. You can change the colors to anything you want. So define the following in your colors.xml.
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#278be3</color> <color name="colorPrimaryDark">#0f5998</color> <color name="colorAccent">#4075a2</color> <color name="colorNavIcon">#dae9f6</color> <color name="colorNavText">#01294b</color> </resources>
Now come to strings.xml and define the following strings.
<resources> <string name="app_name">Bottom Navigation Android Example</string> <string name="title_home">Home</string> <string name="title_dashboard">Dashboard</string> <string name="title_notifications">Notifications</string> <string name="title_profile">Profile</string> </resources>
Customizing Bottom Navigation View
Now come to activity_main.xml and modify it as shown below.
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.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:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="net.simplifiedcoding.bottomnavigationexample.MainActivity"> <FrameLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="56dp" android:text="@string/title_home" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" /> <android.support.design.widget.BottomNavigationView android:id="@+id/navigation" android:layout_width="0dp" android:layout_height="wrap_content" android:background="@color/colorPrimary" app:itemIconTint="@color/colorNavIcon" app:itemTextColor="@color/colorNavText" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:menu="@menu/navigation" /> </android.support.constraint.ConstraintLayout>
Remember for <android.support.design.widget.BottomNavigationView />we can use the following properties
app:itemIconTint : for defining the Item Icon color.
app:itemTextColor : for defining the Item Text Color.
android:background : for defining the Bottom Navigation View background.
app:menu : for defining the menu that we need to display in the Bottom Navigation View.
Now, if you created the project using Bottom Navigation Activity template, a menu file named navigation.xml is created by default inside the menu folder. If it is not created you can create it manually as well. Here we define all the menu items that we need to display in the Bottom Navigation Bar.
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/navigation_home" android:icon="@drawable/ic_home_black_24dp" android:title="@string/title_home" /> <item android:id="@+id/navigation_dashboard" android:icon="@drawable/ic_dashboard_black_24dp" android:title="@string/title_dashboard" /> <item android:id="@+id/navigation_notifications" android:icon="@drawable/ic_notifications_black_24dp" android:title="@string/title_notifications" /> <item android:id="@+id/navigation_profile" android:icon="@drawable/ic_profile_black_24dp" android:title="@string/title_profile" /> </menu>
So, the above codes will produce the following Layout for our Main Activity.
Bottom Navigation Android Activity
If you have used the predefined template for creating Bottom Navigation View, then you will have some codes in the MainActivity.java by default. We will remove those codes and change the MainActivity as shown below, so that we can learn everything.
package net.simplifiedcoding.bottomnavigationexample; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; public class MainActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
Creating Fragments
For each of the view we need to create a layout resource file and a fragment class to inflate the view. As we have 4 different views to be switched we need to create 4 layout resource files and 4 java classes. Every class and resource file is almost the same as we don’t have anything other than a simple TextView in the screens.
Creating Layout Resource Files
Create fragment_home.xml, fragment_dashboard.xml, fragment_notifications.xml and fragment_profile.xml.
All the files will have the following code in it.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="Home" android:textAppearance="@style/Base.TextAppearance.AppCompat.Large" /> </RelativeLayout>
Don’t forget to change the text value of the TextView in each file.
Creating Fragments
Now create java classes named, HomeFragment.java, DashboardFragment.java, NotificationsFragment.java and ProfileFragment.java.
Each file will contain the following code in it.
package net.simplifiedcoding.bottomnavigationexample; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; /** * Created by Belal on 1/23/2018. */ public class HomeFragment extends Fragment @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) //just change the fragment_dashboard //with the fragment you want to inflate //like if the class is HomeFragment it should have R.layout.home_fragment //if it is DashboardFragment it should have R.layout.fragment_dashboard return inflater.inflate(R.layout.fragment_home, null);
Don’t forget to change the layout resource id (R.layout.file_name) with the layout that you want to display for the fragment.
Switching Fragments
Now we will switch the screens or fragments when the bottom navigation menu is clicked. We also need to load some fragment initially which is HomeFragment in this case.
First we will create a method to switch the fragment. I have created the following method named loadFragment() which is taking Fragment is an object.
private boolean loadFragment(Fragment fragment) //switching fragment if (fragment != null) getSupportFragmentManager() .beginTransaction() .replace(R.id.fragment_container, fragment) .commit(); return true; return false;
We will call the above method inside onCreate() to load the default fragment on starting.
@Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //loading the default fragment loadFragment(new HomeFragment()); //getting bottom navigation view and attaching the listener BottomNavigationView navigation = findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(this);
In onCreate() we also defined the BottomNavigationView object. We initialized it using findViewById() method and we attached the listener to detect the Navigation Item Selection.
Now, we need to implement OnNavigationItemSelectedListener interface in the activity class.
//implement the interface OnNavigationItemSelectedListener in your activity class public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {
With the above interface we will get method, and it will be called whenever we will tap on an option from the Bottom Navigation View.
@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) return true;
In the above method we will switch the fragments.
@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) Fragment fragment = null; switch (item.getItemId()) case R.id.navigation_home: fragment = new HomeFragment(); break; case R.id.navigation_dashboard: fragment = new DashboardFragment(); break; case R.id.navigation_notifications: fragment = new NotificationsFragment(); break; case R.id.navigation_profile: fragment = new ProfileFragment(); break; return loadFragment(fragment);
So, the final code that we have for the MainActivity.java is.
package net.simplifiedcoding.bottomnavigationexample; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; //implement the interface OnNavigationItemSelectedListener in your activity class public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener @Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //loading the default fragment loadFragment(new HomeFragment()); //getting bottom navigation view and attaching the listener BottomNavigationView navigation = findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(this); @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) Fragment fragment = null; switch (item.getItemId()) case R.id.navigation_home: fragment = new HomeFragment(); break; case R.id.navigation_dashboard: fragment = new DashboardFragment(); break; case R.id.navigation_notifications: fragment = new NotificationsFragment(); break; case R.id.navigation_profile: fragment = new ProfileFragment(); break; return loadFragment(fragment); private boolean loadFragment(Fragment fragment) //switching fragment if (fragment != null) getSupportFragmentManager() .beginTransaction() .replace(R.id.fragment_container, fragment) .commit(); return true; return false;
Now, you can try running the application.
Bottom Navigation Android Example
As you can see it is working absolutely fine.
Now you can design your fragments as you want, you can create some complex User Interface there, you can fetch some data from network to display it using a RecyclerView. Check the Dynamic RecyclerView Tutorial.
Bottom Navigation Android Example Source Code
If you are having any kind of problem creating Bottom Navigation, then here is my source code for you.
Bottom Navigation Android Source Code Download
So that’s all for this Bottom Navigation Android Tutorial friends. I hope the post helped you to learn about Bottom Navigation. If it was helpful to you, then please give me a SHARE. Thank You 🙂
(adsbygoogle = window.adsbygoogle || []).push();
New Post has been published on Simplified Coding
New Post has been published on https://www.simplifiedcoding.net/paytm-integration-android-example/
Paytm Integration in Android Example - Accepting Payments with Paytm
Paytm is the most popular mobile wallet and payment method used in India. So I thought to publish a Paytm Integration in Android Example. In this post, we will learn how can we add a Pay with Paytm method in our android application. There is the official documentation about integrating Paytm at PayWithPaytm/Developer but that is very confusing, and if you are a newbie then you can face troubles. Here I will show you every step in detailed explanation so you can easily integrate Paytm payments in your application.
Contents
1 Getting Credentials from Paytm
2 How to Integrate Paytm Payment into Android Application?
3 Paytm Integration in Android Example
3.1 Configuring the Paytm Checksum Kit
3.2 Integrating Paytm Payment in Android Project
3.2.1 Creating a New Project
3.2.2 Adding Paytm SDK
3.2.3 Adding Permissions and Paytm Activity
3.2.4 Adding Retrofit and Gson
3.2.5 Defining Constants
3.2.6 Creating User Interface
3.2.7 Creating Retrofit Models and Interface
3.2.7.1 Creating Models
3.2.7.2 Creating Retrofit API Interface
4 Paytm Integration in Android Example – Source Code
Getting Credentials from Paytm
The first step is getting credential from Paytm. Paytm provides it to all the merchants. So you need to signup as a merchant in Paytm. But the problem is it takes time, and you need to submit some docs like GST, Bank Account details. But you do not need to worry as the developer can get sandbox access for development purposes.
Go to this link and sign in with your Paytm account.
You do not need to submit any details after Signup just click on Sandbox Access link as shown in the below image.
Paytm Sandbox
Now you will see your Sandbox Credential.
Sandbox Credential
You are going to use the above credentials. Now lets integrate the Paytm Payment.
How to Integrate Paytm Payment into Android Application?
Let’s first understand how we add Paytm Payment in our Application. We need to perform these two steps.
Generate CHECKSUM on our server.
Accept Payment with Paytm SDK.
We need to generate the Checksum on our server, so the process requires some server-side implementation as well. And here on the server side, I am going to use PHP with Xampp Server.
And for sending Request from android side I will be using Retrofit.
(adsbygoogle = window.adsbygoogle || []).push();
Paytm Integration in Android Example
Configuring the Paytm Checksum Kit
Now let’s start the real process. We will start with the server-side implementation.
Open XAMPP Server and Start the Server. (Skip this step if you are using a live server).
Then download the Paytm App Checksum Kit. And paste it to your server’s root directory. (For XAMPP it is c:/xampp/htdocs by default)
Paytm PHP Checksum Kit
I have renamed the folder to only paytm to make it short and simple.
Inside the folder we have a file named generateChecksum.php and we need to use it for generating checksum.
But first we need to put our Paytm Merchant Key in the configuration.
Go to config_paytm.php (it is inside the lib folder paytm/lib/config_paytm.php), and put your Paytm Merchant Key.
<?php //Change the value of PAYTM_MERCHANT_KEY constant with details received from Paytm. define('PAYTM_MERCHANT_KEY', 'YOUR_MERCHANT_KEY_HERE'); ?>
That’s it for the server side implementation, we just need to route to generateChecksum.php file. So it is localhost/paytm/generateChecksum.php.
But remember using localhost will not work you need to find the IP. You can see it using the ipconfig command, and if you are using a live server, then you can use the URL with your domain.
Now, let’s move ahead by creating an Android Studio Project.
Integrating Paytm Payment in Android Project
Creating a New Project
First, we will create a new Android Studio Project. I have create a project named PaytmPaymentSample with an Empty Activity.
Adding Paytm SDK
Now download the Paytm SDK. Inside the SDK you will find a file named PGSDK_V2.1.jar. We need to add this file in our project dependencies.
So first on the project explorer select Project.
Then inside app/lib paste the PGSDK_V2.1.jar that we downloaded.
Now click on File->Project Structure.
Now from the top tabs go to dependency, and from the right green plus icon select jar dependency.
Now select the jar from the lib folder that you added, and hit ok.
That’s it the Paytm SDK is added.
Adding Permissions and Paytm Activity
We need to add INTERNET and ACCESS_NETWORK_STATE permission, and PaytmPGActivity (The activity comes with the Paytm SDK that we already added).
So open AndroidManifest.xml and modify it as below.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="simplifiedcoding.net.paytmpaymentsample"> <!-- the following two permissions are needed --> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <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> <!-- Add this activity to your manifest it comes with the Paytm SDK --> <activity android:name="com.paytm.pgsdk.PaytmPGActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation|keyboard"/> </application> </manifest>
Adding Retrofit and Gson
As I told you above that, we are going to use the Retrofit Library for sending network request. So for this, we need to Add Retrofit and Gson.
Come inside your app level build.gradle file and add both libraries.
compile 'com.squareup.retrofit2:retrofit:2.2.0' compile 'com.squareup.retrofit2:converter-gson:2.2.0'
Defining Constants
Now, we will define all the required constants in a separate class. For this create a new class named Constants.java and define the following inside.
Remember you need to change the first 3 values according to the Paytm Credentials you got.
package simplifiedcoding.net.paytmpaymentsample; /** * Created by Belal on 1/10/2018. */ public class Constants public static final String M_ID = "xxxxxxxx"; //Paytm Merchand Id we got it in paytm credentials public static final String CHANNEL_ID = "WEB"; //Paytm Channel Id, got it in paytm credentials public static final String INDUSTRY_TYPE_ID = "Retail"; //Paytm industry type got it in paytm credential public static final String WEBSITE = "APP_STAGING"; public static final String CALLBACK_URL = "https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp";
Creating User Interface
Now we will create a very Simple User Interface. So come inside activity_main.xml and write the following code.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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:padding="8dp" tools:context="simplifiedcoding.net.paytmpaymentsample.MainActivity"> <ImageView android:id="@+id/imageView" android:layout_width="120dp" android:layout_height="90dp" android:background="@drawable/macbook_air" android:padding="4dp" /> <TextView android:id="@+id/textViewTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_toRightOf="@id/imageView" android:text="Apple MacBook Air Core i5 5th Gen - (8 GB/128 GB SSD/Mac OS Sierra)" android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" android:textColor="#000000" /> <TextView android:id="@+id/textViewShortDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/textViewTitle" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_toRightOf="@id/imageView" android:text="13.3 Inch, 256 GB" android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" /> <TextView android:id="@+id/textViewRating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/textViewShortDesc" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_toRightOf="@id/imageView" android:background="@color/colorPrimary" android:paddingLeft="15dp" android:paddingRight="15dp" android:text="4.7" android:textAppearance="@style/Base.TextAppearance.AppCompat.Small.Inverse" android:textStyle="bold" /> <TextView android:id="@+id/textViewPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/textViewRating" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_toRightOf="@id/imageView" android:text="10.00" android:textAppearance="@style/Base.TextAppearance.AppCompat.Large" android:textStyle="bold" /> <Button android:id="@+id/buttonBuy" android:layout_toRightOf="@id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/textViewPrice" android:text="Buy" /> </RelativeLayout>
The above code will generate the following layout.
Make sure you add an image named macbook_air in the drawable folder. Or if the name of your image is different, then change it in the ImageView of your layout.
Creating Retrofit Models and Interface
Creating Models
We need two classes one is for CHECKSUM and other is for storing Paytm payment details.
First create a class named Checksum.java and write the following code.
package simplifiedcoding.net.paytmpaymentsample; import com.google.gson.annotations.SerializedName; /** * Created by Belal on 1/10/2018. */ public class Checksum @SerializedName("CHECKSUMHASH") private String checksumHash; @SerializedName("ORDER_ID") private String orderId; @SerializedName("payt_STATUS") private String paytStatus; public Checksum(String checksumHash, String orderId, String paytStatus) this.checksumHash = checksumHash; this.orderId = orderId; this.paytStatus = paytStatus; public String getChecksumHash() return checksumHash; public String getOrderId() return orderId; public String getPaytStatus() return paytStatus;
Now create Paytm.java and write the following code.
package simplifiedcoding.net.paytmpaymentsample; import android.util.Log; import com.google.gson.annotations.SerializedName; import java.util.UUID; /** * Created by Belal on 1/10/2018. */ public class Paytm @SerializedName("MID") String mId; @SerializedName("ORDER_ID") String orderId; @SerializedName("CUST_ID") String custId; @SerializedName("CHANNEL_ID") String channelId; @SerializedName("TXN_AMOUNT") String txnAmount; @SerializedName("WEBSITE") String website; @SerializedName("CALLBACK_URL") String callBackUrl; @SerializedName("INDUSTRY_TYPE_ID") String industryTypeId; public Paytm(String mId, String channelId, String txnAmount, String website, String callBackUrl, String industryTypeId) this.mId = mId; this.orderId = generateString(); this.custId = generateString(); this.channelId = channelId; this.txnAmount = txnAmount; this.website = website; this.callBackUrl = callBackUrl; this.industryTypeId = industryTypeId; Log.d("orderId", orderId); Log.d("customerId", custId); public String getmId() return mId; public String getOrderId() return orderId; public String getCustId() return custId; public String getChannelId() return channelId; public String getTxnAmount() return txnAmount; public String getWebsite() return website; public String getCallBackUrl() return callBackUrl; public String getIndustryTypeId() return industryTypeId; /* * The following method we are using to generate a random string everytime * As we need a unique customer id and order id everytime * For real scenario you can implement it with your own application logic * */ private String generateString() String uuid = UUID.randomUUID().toString(); return uuid.replaceAll("-", "");
Creating Retrofit API Interface
Create a new interface named Api.java.
package simplifiedcoding.net.paytmpaymentsample; import retrofit2.Call; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.POST; /** * Created by Belal on 1/10/2018. */ public interface Api //this is the URL of the paytm folder that we added in the server //make sure you are using your ip else it will not work String BASE_URL = "http://192.168.101.1/paytm/"; @FormUrlEncoded @POST("generateChecksum.php") Call<Checksum> getChecksum( @Field("MID") String mId, @Field("ORDER_ID") String orderId, @Field("CUST_ID") String custId, @Field("CHANNEL_ID") String channelId, @Field("TXN_AMOUNT") String txnAmount, @Field("WEBSITE") String website, @Field("CALLBACK_URL") String callbackUrl, @Field("INDUSTRY_TYPE_ID") String industryTypeId );
If you don’t know anything about using Retrofit you better go through the Retrofit Tutorial first.
Now come to MainActivity.java and write the following code to complete our project.
package simplifiedcoding.net.paytmpaymentsample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.TextView; import android.widget.Toast; import com.paytm.pgsdk.PaytmOrder; import com.paytm.pgsdk.PaytmPGService; import com.paytm.pgsdk.PaytmPaymentTransactionCallback; import java.util.HashMap; import java.util.Map; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; //implementing PaytmPaymentTransactionCallback to track the payment result. public class MainActivity extends AppCompatActivity implements PaytmPaymentTransactionCallback //the textview in the interface where we have the price TextView textViewPrice; @Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //getting the textview textViewPrice = findViewById(R.id.textViewPrice); //attaching a click listener to the button buy findViewById(R.id.buttonBuy).setOnClickListener(new View.OnClickListener() @Override public void onClick(View view) //calling the method generateCheckSum() which will generate the paytm checksum for payment generateCheckSum(); ); private void generateCheckSum() //getting the tax amount first. String txnAmount = textViewPrice.getText().toString().trim(); //creating a retrofit object. Retrofit retrofit = new Retrofit.Builder() .baseUrl(Api.BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); //creating the retrofit api service Api apiService = retrofit.create(Api.class); //creating paytm object //containing all the values required final Paytm paytm = new Paytm( Constants.M_ID, Constants.CHANNEL_ID, txnAmount, Constants.WEBSITE, Constants.CALLBACK_URL, Constants.INDUSTRY_TYPE_ID ); //creating a call object from the apiService Call<Checksum> call = apiService.getChecksum( paytm.getmId(), paytm.getOrderId(), paytm.getCustId(), paytm.getChannelId(), paytm.getTxnAmount(), paytm.getWebsite(), paytm.getCallBackUrl(), paytm.getIndustryTypeId() ); //making the call to generate checksum call.enqueue(new Callback<Checksum>() @Override public void onResponse(Call<Checksum> call, Response<Checksum> response) //once we get the checksum we will initiailize the payment. //the method is taking the checksum we got and the paytm object as the parameter initializePaytmPayment(response.body().getChecksumHash(), paytm); @Override public void onFailure(Call<Checksum> call, Throwable t) ); private void initializePaytmPayment(String checksumHash, Paytm paytm) //getting paytm service PaytmPGService Service = PaytmPGService.getStagingService(); //use this when using for production //PaytmPGService Service = PaytmPGService.getProductionService(); //creating a hashmap and adding all the values required Map<String, String> paramMap = new HashMap<>(); paramMap.put("MID", Constants.M_ID); paramMap.put("ORDER_ID", paytm.getOrderId()); paramMap.put("CUST_ID", paytm.getCustId()); paramMap.put("CHANNEL_ID", paytm.getChannelId()); paramMap.put("TXN_AMOUNT", paytm.getTxnAmount()); paramMap.put("WEBSITE", paytm.getWebsite()); paramMap.put("CALLBACK_URL", paytm.getCallBackUrl()); paramMap.put("CHECKSUMHASH", checksumHash); paramMap.put("INDUSTRY_TYPE_ID", paytm.getIndustryTypeId()); //creating a paytm order object using the hashmap PaytmOrder order = new PaytmOrder(paramMap); //intializing the paytm service Service.initialize(order, null); //finally starting the payment transaction Service.startPaymentTransaction(this, true, true, this); //all these overriden method is to detect the payment result accordingly @Override public void onTransactionResponse(Bundle bundle) Toast.makeText(this, bundle.toString(), Toast.LENGTH_LONG).show(); @Override public void networkNotAvailable() Toast.makeText(this, "Network error", Toast.LENGTH_LONG).show(); @Override public void clientAuthenticationFailed(String s) Toast.makeText(this, s, Toast.LENGTH_LONG).show(); @Override public void someUIErrorOccurred(String s) Toast.makeText(this, s, Toast.LENGTH_LONG).show(); @Override public void onErrorLoadingWebPage(int i, String s, String s1) Toast.makeText(this, s, Toast.LENGTH_LONG).show(); @Override public void onBackPressedCancelTransaction() Toast.makeText(this, "Back Pressed", Toast.LENGTH_LONG).show(); @Override public void onTransactionCancel(String s, Bundle bundle) Toast.makeText(this, s + bundle.toString(), Toast.LENGTH_LONG).show();
Now you can try running your application.
Paytm Integration in Android Example
Bingo! it is working fine.
Paytm Integration in Android Example – Source Code
If you are having some problem following this example, then you get my source code from my GitHub Repository. The link is given below.
Paytm Integration in Android Example
So that’s all for this Paytm Integration in Android Example friends. I hope you found it useful if you did, please SHARE it with your friends. And if you are having any query regarding this Paytm Integration in Android Example then don’t hesitate in commenting. Thank You 🙂

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
#2 Firebase Cloud Messaging Tutorial for Android - Topic Subscription Me...
#1 Firebase Cloud Messaging Tutorial for Android - Single Device using F...