Android App Development With AndroidCource: June 2018

Saturday, 30 June 2018

Send SMS in android example

Android Device can send and receive messages to or from any other phone that supports Short Message Service (SMS). You have two choices for sending SMS messages: Use an implicit Intent to launch a messaging app with the ACTION_SENDTO intent action. This is the simplest choice for sending messages.Send SMS to Give Permission in Sending SMS to allow Runtime And Input Number And Message to Send SMS.
Sending SMS is use to SMSManager provide to send sms to enter number to sending sms.

Add Permission in AndroidManifest.xml File

 <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />

MainActivity.xml

<?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:orientation="vertical"
    tools:context=".MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:layout_gravity="center_horizontal"
        android:hint="Enter Mobile No"
        android:inputType="phone"
        android:imeOptions="actionNext"
        android:maxLength="10"
        android:id="@+id/et_mobile"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:layout_gravity="center_horizontal"
        android:hint="Enter Your Message"
        android:gravity="top"
        android:imeOptions="actionDone"
        android:id="@+id/et_message"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_gravity="center_horizontal"
        android:text="Send"
        android:id="@+id/btn_send"/>


</LinearLayout>

MainActivity.java

package com.example.bhaumik.sendsms;

import android.app.PendingIntent;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    EditText et_mobile,et_message;
    Button btn_send;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        et_mobile = findViewById(R.id.et_mobile);
        et_message = findViewById(R.id.et_message);
        btn_send = findViewById(R.id.btn_send);

        btn_send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent();
                PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,1,intent,0);

                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage(et_mobile.getText().toString(),null,et_message.getText().toString(),pendingIntent,null);

                Toast.makeText(MainActivity.this, "Message Sent Successfully...", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Send SMS in android

Android Listview RadioButton Example

Listview with radiobutton to use of single selection in listview item.you can not multiple item to selected.it can use single selection and change your radio button color in selection mode.when you can select item to display message show to fire click event in list item to perticular selection position to get item.
Listview to use of custom layout or build in layout.custom layout to use of design in xml file layout and build in layout to already desing available. In this example to use of build in layout of single selection item layout.

MainActivity.xml

<?xml version="1.0" encoding="utf-8"?&gt;
<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"
    tools:context=".MainActivity">

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>
</RelativeLayout>

MainActivity.java

package com.example.bhaumik.listviewradiobutton;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    ListView listView;
    ArrayList<String> list;
    ArrayAdapter adapter;
    String[] version = {"Aestro","Blender","CupCake","Donut","Eclair","Froyo","GingerBread","HoneyComb","IceCream Sandwich",
    "Jelly Bean","Kitkat","Lolipop","Marshmallow","Nought","Oreo"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = findViewById(R.id.list_view);

        list = new ArrayList<>();

        for (int i = 0;i<version.length;i++){

            list.add(version[i]);

        }
        listView.setChoiceMode(listView.CHOICE_MODE_SINGLE);

        adapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_list_item_single_choice,list);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                Toast.makeText(MainActivity.this, "Selected -> " + version[i], Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Listview Single Choice in android Example.,Listview radiobutton in android

Android Phone Calls Example

Android provides Built-in applications for phone calls.How to make Phone Call in android Programmatically.It Can Use to Call Phone in android.

Intent Object Use to make Call in android.It can Use To ACTION_CALL action trigger to automatically phone call function call in android device available function.

ACTION_DIAL action instead of ACTION_CALL, in that case you will have option to modify hardcoded phone number before making a call instead of making a direct call.

Add Permission in AndroidManifest.xml file

 
<uses-permission android:name="android.permission.CALL_PHONE" />

MainActivity.xml

<?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:orientation="vertical"
    tools:context=".MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:hint="Enter Mobile No"
        android:inputType="phone"
        android:imeOptions="actionDone"
        android:maxLength="10"
        android:id="@+id/et_mobile"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_gravity="center_horizontal"
        android:id="@+id/btn_call"
        android:text="Call"/>
</LinearLayout>

MainActivity.java

package com.example.bhaumik.phonecall;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    EditText editText;
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editText = findViewById(R.id.et_mobile);
        button = findViewById(R.id.btn_call);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED){

                    return;
                }

                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:"+ editText.getText().toString()));

                startActivity(intent);
            }
        });
    }
}
Android Phone Call Example

Saturday, 23 June 2018

Snackbar in Android Example

Snackbar is a Simple Message in Display Same as a Toast But it Advance And Change User Display Message in Snackbar.It Can Handle Custom Click Event of Snackbar and Perform Action in Button.Change Background And TextColor And Action button color to change and customization.Snackbar is a display of style.and better than toast message to display in snackbar.

Add Dependancy In App Module build.gradle file

implementation 'com.android.support:design:27.1.1'

MianActivity.xml

<?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:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/btn_default"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Default Snackback"
        android:layout_marginTop="20dp"
        android:textAllCaps="false"
        android:layout_gravity="center_horizontal"
        />

    <Button
        android:id="@+id/btn_custom"
        android:layout_marginTop="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Custom Snackback"
        android:textAllCaps="false"
        android:layout_gravity="center_horizontal"
        />

</LinearLayout>

MainActivity.java

package com.example.com.snackbardemo;

import android.graphics.Color;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

   
    Button btn_default,btn_custom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_default = findViewById(R.id.btn_default);
        btn_custom = findViewById(R.id.btn_custom);

        btn_default.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(btn_default,"This is Default Snackbar",Snackbar.LENGTH_LONG).show();
            }
        });

        btn_custom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

               Snackbar snackbar = Snackbar.make(btn_custom,"This is Custom Snackbar",Snackbar.LENGTH_LONG)
                        .setAction("Close", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                                Toast.makeText(MainActivity.this, "Close Button Click", Toast.LENGTH_SHORT).show();
                            }
                        })
                        .setActionTextColor(Color.GREEN);

                TextView textView = snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
                textView.setTextColor(Color.RED);
                snackbar.show();
            }
        });
    }
}

Press Double Click To Exit App in Android Example


Double Press To Exit in Application to implement onBackPress Event in Activity Lifecycle and maintain to back button in your device to press one click to show Toast message and before retry to click to another 2 second to show toast in single click.when click double press back button to exit this app and does not show Toast when Exited to app screen.

MainActivity.xml

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

MainActivity.java

package com.example.com.doublebacktoexitapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    public long doubleclick;
    public Toast backToast;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    @Override
    public void onBackPressed() {

        if(doubleclick + 2000 > System.currentTimeMillis()){
            backToast.cancel();
            super.onBackPressed();
            return;
        }else{
            backToast = Toast.makeText(MainActivity.this,"Press Back Again To Exit",Toast.LENGTH_SHORT);
            backToast.show();
        }
        doubleclick = System.currentTimeMillis();

    }
}


Monday, 18 June 2018

Circle Button in Android Example

How To Create Circle Button in android example.

Creating Circle Button Style And Implements Ripple Effect When Button is Click to Effect in button and change custom size in button and change custom color.

Add Dependancy in Module Level build.gradle File

compile 'com.github.markushi:circlebutton:1.1'

MainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.bhaumik.circlebutton.MainActivity">

    <at.markushi.ui.CircleButton
        android:layout_width="130dp"
        android:layout_height="130dp"
        app:cb_color="@color/colorAccent"
        app:cb_pressedRingWidth="10dp"
        android:src="@drawable/ic_home"
        android:id="@+id/btn_home"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="160dp"
        android:id="@+id/btn_ripple"
        android:layout_marginTop="10dp"
        android:background="@drawable/ripples"
        android:text="Java"
        android:textColor="#FFF"
        android:textAllCaps="false" />

</RelativeLayout>

MainActivity.java

package com.bhaumik.circlebutton;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import at.markushi.ui.CircleButton;

public class MainActivity extends AppCompatActivity {

    CircleButton btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn = (CircleButton) findViewById(R.id.btn_home);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this,"Home Button Clicked....",Toast.LENGTH_SHORT).show();
            }
        });


    }
}
Circle Button in android example

Sunday, 17 June 2018

Android Import And Use SVG/Vector Image File Example

How to Import SVG/Vector drawable image file in android.

Step 1

Go to res Folder And Right Click To drawable Folder and Select Vector Asset.
SVG Vector Drawable Select in android

Step 2

Click Vector Asset to Open Popup Dialog to Select Top Local file (SVG,PSD).
Select Vector Assets And Open Popup Dialog in android

Step 3

Select SVG File From Your Saved Folder in Your Computer.Set Custom size,opasity and Show Right side Preview In your Selected SVG File
SVG File Select in android

Android Telephony Manager Example

Telephony Manager Example in andoid

Telephony Manager provides access to information about the telephony services on the device.Telephony Services such as subscriber id, sim serial number, phone network type etc. Moreover, you can determine the phone state etc.

Add Permission in AndroidManiFest.xml File

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

MainActivity.xml

<?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"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/tv_details"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="38dp"
        android:layout_marginTop="30dp"
        android:textSize="20dp"
        android:text="Mobile Details:" />

</RelativeLayout>

MainActivity.java

 
package com.example.com.telephonymanager;

import android.Manifest;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = findViewById(R.id.tv_details);

        TelephonyManager device = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {


            return;
        }
        String imei = device.getDeviceId();
        String SimSerialNo = device.getSimSerialNumber();
        String simOperator = device.getSimOperator();
        String NetworkCountryISO=device.getNetworkCountryIso();
        String SIMCountryISO=device.getSimCountryIso();
        String SoftwareVersion=device.getDeviceSoftwareVersion();
        String voiceMailNumber=device.getVoiceMailNumber();

        String text = "Imei : "+ imei + "\n SimSerialNo : " + SimSerialNo + "\n Sim Operator : "
                + simOperator + "\n NetworkCountryISO : " + NetworkCountryISO + 
                "\n SIMCountryISO : " + SIMCountryISO + "\n SoftwareVersion : " + SoftwareVersion +
                "\n voiceMailNumber : " + voiceMailNumber;

        textView.setText(text);

    }
}

Android AutoCompleteTextView Example Tutorial

How To Create AutoCompleteTextView in android

AutoCompleteTextView is a Automatically Show in List when User Write Text and Suggession in list of data it call AutoCompleteTextView.It is Use of Listof Country,City to Use this AutoCompleteTextView.

MainActivity.xml

 

<?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"
    tools:context=".MainActivity">

    <AutoCompleteTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:id="@+id/auto"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:hint="Enter Your Country Name"
        android:layout_marginTop="63dp" />

</RelativeLayout>

MainActivity.java

package com.example.com.autocompletetextview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity {

    AutoCompleteTextView actv;
    ArrayAdapter<String> adapter;
    String[] version = {"Aestro","Blender","CupCake","Donut","Eclair","Froyo","GingerBread","HoneyComb",
    "IceCream Sendwich","JellyBean","Kitkat","Lolipop","Marshmallow","Noghut","Oreo"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        actv = (AutoCompleteTextView)findViewById(R.id.auto);
        adapter = new ArrayAdapter<String>(this,android.R.layout.select_dialog_item,version);
        actv.setAdapter(adapter);
        actv.setThreshold(1);
    }
}

How To Make Splash Screen In Android Example Tutorial

Splash Screen in Android Example Tutorial

Create Splash Screen in Background Thread Processing to Process in Activity some time to display SplashScreen . And Close Screen to thread is Stopped and Main Screen Open.

Example Of Splash Screen

MainActivity.xml

<?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"
    tools:context=".SplashActivity"
    android:background="@drawable/splashnew">

</RelativeLayout>

MainActivity.java

package com.example.com.mobileshopapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        getSupportActionBar().hide();

        Thread thread = new Thread(){

            @Override
            public void run() {

                try {
                    sleep(5000);

                    startActivity(new Intent(SplashActivity.this,MainActivity.class));
                    finish();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.start();
    }
}