Create audio player app in 10 minutes

Create audio player app in 10 minutes

Welcome to hiewpoint, In this post you’ll learn how to use MediaPlayer Api to build a simple audio player app. By creating this app you’ll learn some basic concepts of MediaPlayer Api and AudioManager.
So what’s MediaPlayer and AudioManager? If we want our app to play video and sound then we need to use these two above mentioned.
MediaPlayer: This class is the primary API for playing sound and video.
AudioManager: This class manages audio sources and audio output on a device.Lets get started in building an app with Mediaplayer in android studio.


First setup the project with an empty activity and give it any preferred name.
In the activity_main.xml copy this below code.

Audio player app activity_main.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:orientation="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_green_dark"
        android:onClick="playMe"
        android:text="@string/play"
        tools:text="@string/play" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_red_dark"
        android:onClick="pauseMe"
        android:text="@string/pause"
        tools:text="@string/pause" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="24dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <SeekBar
        android:id="@+id/seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Volume" />

    <SeekBar
        android:id="@+id/timeline"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TimeLine" />
</LinearLayout>

We have a playMe button and PauseMe button. Ofcourse play and pause are essential in any audioplayer app, we also have two seek bar to control the volume and timeline of audio.
Now copy these below lines of code in MainActivity.java

Audio player app MainActivity.java

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.SeekBar;
import java.util.Timer;
import java.util.TimerTask;
MediaPlayer mediaPlayer;
AudioManager audioManager;

public class MainActivity extends AppCompatActivity {
public void playMe(View view){
    mediaPlayer.start();

}

public void pauseMe(View view){

    mediaPlayer.pause();
}



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

    mediaPlayer = MediaPlayer.create(this, R.raw.myaudio);

    //Getting context from Audio Service
    audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    int myMaxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int myCurrentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

    //Setting context values to Seekbar
    SeekBar volumeRocker = (SeekBar) findViewById(R.id.seekBar);
    volumeRocker.setMax(myMaxVolume);
    volumeRocker.setProgress(myCurrentVolume);


    //Set on change listener

    volumeRocker.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });


        //Setting a player timeline

    final SeekBar timeline = (SeekBar) findViewById(R.id.timeline);
    timeline.setMax(mediaPlayer.getDuration());

    new Timer().scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            timeline.setProgress(mediaPlayer.getCurrentPosition());
        }
    }, 0, 1000);


    timeline.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mediaPlayer.seekTo(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

}

}

Conclusion

So basically we first create instance of MediaPlayer and AudioManager and instantiate them in oncreate() as mediaPlayer=MediaPlayer.create(this,R.raw.myAudio);
audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE); here we get the audio service in order to play the audio.

Inside the onClick methods of both the button consists of mediaPlayer.start() to start the audio and mediaPlayer.pause() to pause the audio.

In order to control the volume rocker we need to set current stream and max stream and assigned to two different variables. These two variables are used in seekbar(volume rocker).

volumeRocker.setMax(myMaxVolume);
volumeRocker.setProgress(myCurrentVolume);

To control the volume seekbar ,a seekbarChangeListener is added which listens to the movement of seekbar(volume rocker), inside the onProgressChanged(….) we added this audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);

So that when user slide the seekbar it sets that current value to it.Similar to this seekbar ,another seekbar is created which listens to the timeline of audio and it uses mediaPlayer.seekTo() method to seek the audio wherever user slides.

Output

After implementing the source code in-place and properly, Your app will appear similar to this ! however you can easily edit the background color and button color. For any doubt comment on our post or send us a message on social media to get cleared instantly. Try some more modifications in this audio player app and wait for our next article. Happy coding !

Create audio player app  in 10 minutes

Thank you for reading this post. Follow us on Instagram and Facebook.


To know more tips and tricks you can follow articles on this category :
https://blog.hiewpoint.com/off-topic/

To know about web development and WordPress follow
https://blog.hiewpoint.com/web/

To know about Android development and Android Studio follow
https://blog.hiewpoint.com/android/

Use API in android app in just 7 simple steps

Use API in android app in just 7 simple steps

In this post you will learn about API’s and how to fetch live data from the internet and provide data within your android app.

After following this post ,you would be able to implement any API within your app which would be useful for your large scale application. We will use openweathermap API in this tutorial. So let’s get started but wait do you know what is an API? If not then don’t worry I’ll explain you what is an API and I promise that you will not again search for what is an API?

What is an API

According to Wikipedia ,In computer programming, an application programming interface is a set of subroutine definitions, communication protocols, and tools for building software. In general terms, it is a set of clearly defined methods of communication among various components. A good API makes it easier to develop a computer program by providing all the building blocks, which are then put together by the programmer.

Not yet clear what is an API? We’ll break it down for you.

So basically it is an intermediary software that allows two applications to talk to each other. For example , You want to book your air ticket from indigo. Now you may go to the indigo website and book it. But how many of  us does that? Very rarely we do that. We use third party services like MMT ,Paytm etc.. So developers use this to get data from main server or for much more additional features.

Another example ,You login/signup to different websites that gives various options to you to sign up to their website. That may include Facebook ,google signup etc…

Get your API key

To start using application programming interface services of any organization ,we need to register and get the key from them. In this tutorial we’ll use openweathermap .

Get the API key by registering to openweathermap. The key is a unique identifier to the API provider. Follow the documentation there and get started.

You need to follow the guides properly as you need to understand what the provider provides ,So that you could use it in your application to display live data.

Let’s Code

Open Mainfest.xml and give it a permission to internet service as we are going to use internet service in app.

Copy the below code in activity_mamin.xmlm

<?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"
    android:background="@drawable/winter"
    tools:context="com.example.studio.myweatherapp.MainActivity">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="24dp"
        android:fontFamily="cursive"
        android:text="Get Weather"
        android:textColor="@android:color/background_dark"
        android:textSize="50sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/getCity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Paris"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView2" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="24dp"
        android:background="@color/colorAccent"
        android:paddingBottom="10dp"
        android:paddingLeft="30dp"
        android:paddingRight="30dp"
        android:paddingTop="10dp"
        android:text="Get that"
        android:textColor="@android:color/background_light"
        android:textSize="20sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/getCity" />

    <TextView
        android:id="@+id/result"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="24dp"
        android:text="TextView"
        android:textSize="20sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button"
        tools:layout_editor_absoluteY="234dp" />
</android.support.constraint.ConstraintLayout>

We are going to perform network request using volley library. Why volley? Because its simple and convenient unlike using asynctask request. Using volley we don’t need to worry about UI thread etc..

 In order to perform network request we need some boiler plate codes which performs the request. We need not worry about how that code works as it is a boiler plate code .It’s just needed in order to use volley. So copy these below lines of code in a class and named it as mySingelton.java .

If you are not familiar with volley then I would recommend to first learn about volley. We already have a post on volley ,So have a look on that.

package com.example.studio.myweatherapp;

import android.content.Context;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;


public class MySingleton {

    private static MySingleton mInstance;
    private RequestQueue requestQueue;
    private static Context mCtx;

    private MySingleton(Context context){
        mCtx = context;
        requestQueue = getRequestQueue();
    }

    public RequestQueue getRequestQueue(){
        if(requestQueue==null){
            requestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
        }
        return requestQueue;
    }

    public static synchronized MySingleton getInstance(Context context){
        if(mInstance==null){
            mInstance = new MySingleton(context);
        }
        return mInstance;
    }

    public void addToRequestQue(Request request){
        requestQueue.add(request);
    }
}

NOTE: The url which will be requested using mySingleton is JsonObjectRequest  and jsonobjectrequest must have a url with api So the url must be something like this baseUrl+city+API key.

Copy these in MainActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class MainActivity extends AppCompatActivity {

    Button button;
    EditText city;
    TextView result;

    //http://api.openweathermap.org/data/2.5/weather?q=Paris&appid=5f56d525d1619d0a2cd2eac4ce55588e

    String baseURL = "http://api.openweathermap.org/data/2.5/weather?q=";
    String API = "&appid=5f56d525d1619d0a2cd2eac4ce55588e";

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

        button = (Button) findViewById(R.id.button);
        city = (EditText) findViewById(R.id.getCity);
        result = (TextView) findViewById(R.id.result);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String myURL = baseURL + city.getText().toString() + API;
                //Log.i("URL", "URL: " + myURL);

                JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, myURL, null,
                        new Response.Listener<JSONObject>() {
                            @Override
                            public void onResponse(JSONObject jsonObject) {
                                Log.i("JSON", "JSON: " + jsonObject);

                                try {
                                    String info = jsonObject.getString("weather");
                                    Log.i("INFO", "INFO: "+ info);

                                    JSONArray ar = new JSONArray(info);

                                    for (int i = 0; i < ar.length(); i++){
                                        JSONObject parObj = ar.getJSONObject(i);

                                        String myWeather = parObj.getString("main");
                                        result.setText(myWeather);
                                        Log.i("ID", "ID: " + parObj.getString("id"));
                                        Log.i("MAIN", "MAIN: " + parObj.getString("main"));
                                    }


                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }




                            }
                        },

                        new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError volleyError) {
                                Log.i("Error", "Something went wrong" + volleyError);

                            }
                        }


                );
                MySingleton.getInstance(MainActivity.this).addToRequestQue(jsonObjectRequest);

            }
        });
    }
}

Lets see what is exactly happening in the MainActivity.java

  • First we set the base url from where we want to fetch the data and API key of your registered one.
  • Then when a user enters a city name ,an url is set up as to request (GET) and get the JSON data from the url by using JsonObjectRequest ,this returns the data inn JSON Onject format something just like this,

JSON: {“coord”:{“lon”:2.35,”lat”:48.86},”weather”:[{“id”:801,”main”:”Clouds”,”description”:”few clouds”,”icon”:”02d”}],”base”:”stations”,”main”:{“temp”:283.58,”pressure”:1034,”humidity”:77,”temp_min”:282.15,”temp_max”:285.93},”visibility”:10000,”wind”:{“speed”:2.6},”clouds”:{“all”:20},”dt”:1553599943,”sys”:{“type”:1,”id”:6540,”message”:0.0052,”country”:”FR”,”sunrise”:1553578899,”sunset”:1553623857},”id”:2988507,”name”:”Paris”,”cod”:200}

  • We take the necessary data which we want and leave other. In this e xample app we take only the main inside of weather Array of objects.
  • Finally we request the volley to get the data from the server. This is achieved by using,
MySingleton.getInstance(MainActivity.this).addToRequestQue(jsonObjectRequest);

The app would have an output like this,

Thank you for reading this post. Follow us on Instagram and Facebook.


To know more tips and tricks you can follow articles on this category :
https://blog.hiewpoint.com/off-topic/

To know about web development and WordPress follow
https://blog.hiewpoint.com/web/

To know about Android development and Android Studio follow
https://blog.hiewpoint.com/android/

survey-2316468_1280

Create A List View Using Custom Adapter

Hello ,welcome to Bunkerspoint. In this post, we will see how to make a List view using custom adapter. This topic may be a bit intimidating so we will keep it easy by using text view only.

In this session we are going to create an app using list view which will display two text views called name and number using Array adapter.

  • open your android Studio app.
  • Click on new project-> give any name as you like.
  • Choose an empty activity-> click on next.
  • Don’t change any settings -> click on finish.
  • project may take some time to build and sync itself.
  • Copy the following code mainactivity.xml file. In the below given code, we create list view and assign it a id called “custom_list”.
<?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">

    <ListView
        android:id="@+id/custom_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

      />

</RelativeLayout>
  • copy the following code into list_item.xml. In list_item.xml ,we create two text views and assign each of them an id so that when list is created we could use ids to display the data into list.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_margin="24dp">


    <TextView
        android:id="@+id/number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingLeft="10dp"
        android:layout_margin="10dp"
        android:textSize="20dp"
        tools:text="1"/>

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:paddingLeft="20dp"
        android:layout_margin="10dp"
        android:textSize="20dp"
        tools:text="maharana"/>

</LinearLayout>
  • Create a new class called Acttivity(any name you want I kept mine as Acttivity) which will use to define your class and store the data in it. We created two objects of String data type.

We created a constructor to extract values from array adapter and return it in getmName and get mNumber methods. So ,that it is displayed. Copy the following code into Acttivity.java class.

package com.example.bunkersdemo2;

public class Acttivity {

    private String mNumber;

    private String mName;



    public Acttivity(String vNumber,String vName){

        mNumber=vNumber;
        mName=vName;

    }


    public String getmNumber() {
        return mNumber;
    }

    public String getmName() {
        return mName;
    }
}
  • create a new class called Acttivity adapter(name whatever you want) and extend it ArrayAdapter(in my case ArrayAdapter).Now we create our own custom constructor which takes two arguments ,context (it will be used to inflate the layout file)and list(to populate the items in the list). The list we are using is ArrayList.

Then we call a method called getView method. we create a variable called listItemView to convertView. If listItemView is null then we inflate the listItemview using the LayoutInflater.inflate(). We use getitem() method to get the position of the object. We update the text views using findviewbyid() and update the data of object in list_item xml using the id number and name and return the listItemView.

package com.example.bunkersdemo2;

import android.app.Activity;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;

public class ActtivityAdapter extends ArrayAdapter<Acttivity> {


    public ActtivityAdapter(Activity context, ArrayList<Acttivity> activity) {
        super(context, 0,activity);
    }



    @Override
    public View getView(int position,  View convertView,  ViewGroup parent) {
        View listItemView = convertView;
        if(listItemView == null) {
            listItemView = LayoutInflater.from(getContext()).inflate(
                    R.layout.list_item, parent, false);
        }

        Acttivity currentActivity=getItem(position);


        TextView number = (TextView)listItemView.findViewById(R.id.number);
        number.setText(currentActivity.getmNumber());


        TextView name = (TextView)listItemView.findViewById(R.id.name);
        name.setText(currentActivity.getmName());

        return listItemView;
    }
}
  • copy the following code into MainActivity.java file. We are done creating Adapter and list item xml .So in mainactivity.java file. we create array list called activity and enter the Acttivity objects which will be displayed. We get a reference to the list view and attach it to the adapter in the list view using findviewbyid () method. Add some items in the arrayList by add() method.
package com.example.bunkersdemo2;

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

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

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

        ArrayList<Acttivity> activity = new ArrayList<Acttivity>();

        activity.add(new Acttivity("1", "Maharana"));
        activity.add(new Acttivity("2", "Shruti"));
        activity.add(new Acttivity("3", "Maharaj"));
        activity.add(new Acttivity("4", "Maharani"));
        activity.add(new Acttivity("5", "Maha"));
        activity.add(new Acttivity("6", "Marna"));
        activity.add(new Acttivity("7", "Mahana"));
        activity.add(new Acttivity("8", "Maharana2"));
        activity.add(new Acttivity("9", "Maharana3"));
        activity.add(new Acttivity("10", "Maharana4"));
        activity.add(new Acttivity("11", "Maharana5"));
        activity.add(new Acttivity("12", "Maharana6"));
        activity.add(new Acttivity("13", "Maharana7"));
        activity.add(new Acttivity("14", "Maharana8"));
        activity.add(new Acttivity("15", "Maharana9"));
        activity.add(new Acttivity("16", "Maharana0"));


        ActtivityAdapter adapter= new ActtivityAdapter(this,activity);
        ListView listView=(ListView) findViewById(R.id.custom_list);
        listView.setAdapter(adapter );

    }
}

OUTPUT


In this post, you have seen how to create a arraylist using custom adapter and how to implement it in your app. you can try and implement in different examples to understand. If you want more information you can go to documentation here. It is always a good practice to read the documentation.
Thank you for reading and keep following bunknerspoint.

WhatsApp Image 2019-04-02 at 6.38.13 PM (1)

Create A Basic Hello World App Using Button

In this tutorial we will see how to make a Hello world app with android studio. Its a very simple project then what special in it ? Well, we are going to create it using a button. In today’s tutorial we’ll teach you how to use button, explain you how a button works and how can you implement it in your app.

Step 1: open your android studio app.

Step 2: click on a new project -> give any name as you like.

Step 3: choose an empty activity, and then click next.

Step 4: don’t change any other settings such as save location, package name or api level.

Step 5: let the project load the modules and sync itself.

Step 6: copy the following code in main_activity.java file.

<?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"
     tools:context=".MainActivity"
     android:orientation="vertical"
     android:layout_margin="12dp">
 
 
 
     <TextView
         android:id="@+id/button_click"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="click below"
         android:paddingLeft="12dp"
         android:paddingBottom="12dp"
         android:textAlignment="center"
         />
 
     <Button
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:onClick="active_click"
         android:text="click here" />
 
 
 </LinearLayout>

In the above written code, what I have done is changed the default “android.support.constraint.ConstraintLayout” to LinearLayout for no special reason but because I prefer it to keep things in straight order. I have kept orientation in vertical order .it will help our views and text in linear order or it may appear in horizontal order.

  Then we removed all the text inside the Text view and set the layout_width and height to match parent and added the text “click below”. And we have kept the layout in such a way that they don’t get cramped.

Now here come the important part, we have created an id for text view because when the button will be clicked the it shouldknow where operation should take place so we need to assign an id to it. Then  we create a button view with text  “click here” and give it action to perform called ”active_Part” by calling onclick method.

Step 7: copy the following code in main_activity.java file.

package com.example.bunkers_demo;
 
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.TextView;
 
 public class MainActivity extends AppCompatActivity {
     String click="Hello world";
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
 
     }
 
 
     public void active_click(View view){
 
         display(click);
     }
     public void display(String view) {
         TextView displayThis = (TextView) findViewById(R.id.button_click);
         displayThis.setText(String.valueOf(view));
     }
 
 }

When the button is clicked it calls active_click method and it displays the value of variable present inside “click”. But you need to create a variable of String type of any name (I have kept mine as “click”) and set the value as ” Hello world” but how does it know where to display for that you will create a function called “display” of String type view. It uses the value stored in variable”click”and display the in id button_click using find view by id method in it. It displays the text view value id then we use setText method so that the updated value of string type updates the text in text view outside the app.

Step 8: after following the steps above you app will look like this.

 

So with this we have learn’t what a button is, how it works and how can it be implemented in your app, you can go to android studio and make changes to see how it works and understand better. We have kept it simple so that it can only display a word but we can design it to perform arithmetic calculations. But that’s for different lesson stay tuned and visit our website for more solutions.

getting started with android studio

Getting Started With Android Development

Are you one among those who want to learn android development? If yes then we’ll guide you with how to get started with android development.

Before installing android studio check that your OS meets some of the basic requirements.

Basic Requirements:

1. The first and the foremost thing you’ll need a computer or laptop, that’s obvious but you’ll need a system with good / best performance because system with low performance would definitely waste your precious time and your time is very important.

2. You could see the system requirements here, Which guides you with the minimum ram, space etc (Head down to the last page).

3. You’ll need to install Android Studio. Click here to read our post on installing android studio.

3. A stable internet connection as Android Studio needs to be updated whenever required and moreover you need tutorials (if you are learning it online) on android studio, you’ll have doubts that needs to be cleared and by the way I’ll tell you no developer in the world could develop an app without getting guides from the internet, Yes no developer could do that.

4. after installing, Open Android Studio and then click on the start a new android studio project.

android studio ss 1

Now let’s build your very first android app (hello world app).

Under the Application name, rename it as Hello World and click next.

android studio ss 2

The below dialog box appears after clicking next.

android studio ss 3

In the above dialog box you need to select for which device you want to build the app.

For now you check the phone and tablet checkbox and then, select the targeted APIs and click next.

android studio ss 4

Then click on the empty activity and click next.

android studio ss 5

Then add the activity name and click finish.

Tada it’s done. You can build and run your device and you would see the message printed as Hello World.

Now there are two ways you could run and see your apps.

1. By using emulators which you could download in the android studio itself and

2. By using real android device and connecting it via USB to your laptop/PC.

Using emulators requires a good ram (at least 8 GB to perform well). So I suggest to use android devices to run your apps if you have lower end devices.

HOW TO RUN YOUR APP IN ANDROID DEVICE:

To run your apps on your device, you’ll first need to switch the developer mode on in your device and then connect it via USB and then click run, and now you could run your apps on your device.

But what if you don’t have any android device, then you could download android emulators available online and it would be faster than the android studio’s emulator. I would recommend you to download the Genymotion emulator, it’s very good and fast.


To know more about android emulators visit Bunkerspoint

Android Studio

Installing Android Studio On Windows/Mac /Linux (Ubuntu)

Struggling with installing Android Studio on your device? In this post we will guide you with installing android studio on  three different OS which covers windows / mac / Ubuntu.

Installing Android Studio has become easier than ever since its   new update  released  in January 2019.

FOLLOW THESE STEPS FOR INSTALLING ANDROID STUDIO

Installation in Windows

  • Click on install.
  • Check on requirements before installation.
  • Install the Android Studio if you have downloaded in .exe(recommended) then double click to launch it, if not.
  • If you have installed in .zip file type, then copy android studio folder and copy it into program files folder open android > bin, then launch studio64.exe(for 64-bit users) or launch studio32.exe(for 32-bit users).
  • After launching the android ,click next  and agree to its terms as you go.
  • If you are first time user then check on the second option “do not import any settings”
  • After installation, it will ask you to download SDK press OK to install all JDK tools or components to install
  • For beginners, it’s better to keep setting as Standard better not to choose custom until you have more experience with standard well it can be changed later
  • After installation and extraction are done you are good to go and click on Finish with this you are done.
  • When you have updates Android Studio will inform you with pop-up notifications or you can choose help>check update.

   Installation in Mac

  • Click on install.
  • Check on requirements before installation.
  • After downloading Android Studio, launch the DMG file of Android Studio.
  • Select Android Studio file then drag and drop it inside the applications folder.
  • Select whether to import previous settings or not if you are first time user then it’s better to check to“ not import any settings”.
Installing Android Studio On Windows/Mac /Linux (Ubuntu)
Installing Android Studio On Windows/Mac /Linux (Ubuntu)
  • Agree to all its terms and continue the installations as it goes.
  • It’s best to keep the settings at Standard for beginners, it can be changed later.
  • Install all the SDK tools or SDK components shown by Android Studio.
  • When the installation is done you are pretty much good to use the Android Studio.
  • For automatic updates, Android Studio will show pop-ups or click on android studio>check for updates.

   Installing Android Studio in ubuntu(linux) 

  • Click on install.
  • Check on requirements before installation.
  • After downloading the .zip file unzip the folder in an appropriate location such as /user/local/ if you are a single user If you are shared user then choose /opt/.
  • To launch Android Studio navigate to terminal android-studio/bin / in the directory, then launch studio.sh file.
Installing Android Studio On Windows/Mac /Linux (Ubuntu)
Installing Android Studio On Windows/Mac /Linux (Ubuntu)
  • Select whether to import previous settings or not if you are first time user then it’s better to check to“ not import any settings”.
  • Agree to all its terms and continue the installations as it goes.
  • Tools > create a new entry is to be used if you want Android Studio to appear in your android studio list applications.
  • It’s best to keep the settings at Standard for beginners, it can be changed later.
  • Install all the SDK tools or SDK components shown by Android Studio.
  • When the installation is done you are pretty much good to use the Android Studio.
  • For automatic updates, Android Studio will show pop-ups or click on help>check for update.

Required commands for 64-bit machines in Linux

For 64-bit users, you need 32-bit libraries that can be done using the following commands

For 64-bit Fedora devices the command is

sudo yum install zlib.i686 ncurses-libs.i686 bzip2-libs.i686

For other 64-bit ubuntu devices

sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386

Following the few simple steps above you can install Android Studio with ease but depending upon ram or internet speed it may take time from 20 minutes to 1 hour or more if you have a slow internet connection.

A tip for you guys who are beginners, Please try to make sure you have basic requirements in OS for installation, if not after installation you may encounter many problems like time for executing, that is even a simple android code may take up to 15 minutes if you don’t have.

Good luck, with this you are good to run your android studio and start your  first project.

Thank you for reading this post. Follow us on Instagram and Facebook.


To know more tips and tricks you can follow articles on this category :
https://blog.hiewpoint.com/off-topic/

To know about web development and WordPress follow
https://blog.hiewpoint.com/web/

To know about Android development and Android Studio follow
https://blog.hiewpoint.com/android/

Android Q

What Is Android And Android Development


What is Android:

Android is an mobile operating system developed by Google which runs android applications and it is based on Linux kernel and many open source software.


Android Open Source Project(AOSP):

 The AOSP is a guide to development of the Android platform. This platform consists of  Linux Kernel, Libraries, Dalvik Runtime, Frameworks and Applications.

As mentioned in www.source/android.com  As an open source project, Android’s goal is to avoid any central point of failure in which one industry player can restrict or control the innovations of any other player. To that end, Android is a full, production-quality operating system for consumer products, complete with customizable source code that can be ported to nearly any device and public documentation that is available to everyone

Anyone could contribute code to AOSP and  also anyone could use the open source code, this allows the developer to learn  from other projects. There are tons of libraries available to use in your projects, it helps the developer in getting rid of  boiler plate codes in its projects. A library includes everything needed to build an app.Think library as a pieces of code already written that helps the developer to develop their mobile apps easily. Android uses Linux kernel to develop an android operating system on it. The Dalvik rutime acts like Java virtual machine which is designed for Android. The Application Frameworks are set of Api’s that allows developers to quickly and easily  write apps. It consists of tools for designing UI like Buttons,textField etc


Android Software Development Kit(SDK):

   The Android SDK enables the developers to create applications for Android platform. The sdk tools consists of libraries, visual editors, sample projects, debuggers, documentation, API and much more. Whenever a new android version is released along with it a new SDK tools are released to be used by developers which are downloaded with the help of sdk manager. Each android version has its own sdk platforms. In order to build an app you must specify an SDK platform as per your build target.


Different Android versions:

  1. Android 1.5: Android Cupcake
  2. Android 1.6: Android Donut
  3. Android 2.0: Android Eclair
  4. Android 2.2: Android Froyo
  5. Android 2.3: Android Gingerbread
  6. Android 3.0: Android Honeycomb
  7. Android 4.0: Android Ice Cream Sandwich
  8. Android 4.1 to 4.3.1: Android Jelly Bean
  9. Android 4.4 to 4.4.4: Android KitKat
  10. Android 5.0 to 5.1.1: Android Lollipop
  11. Android 6.0 to 6.0.1: Android Marshmallow
  12. Android 7.0 to 7.1: Android Nougat
  13. Android 8.0 to Android 8.1: Android Oreo
  14. Android 9.0: Android Pie


What is Android Development:

Android development is the process by which android applications are developed. Android applications can be developed using Java ,Kotlin,C++ languages.


Android Developer Tools:

Google provides Android software development kit  and Gradle tooling kit to start compiling and running your android apps


Where to develop android applications:

   Google provides the official IDE ,Android Studio to develop android applications. It is the most used IDE for developing android apps. Before Android Studio, Eclipse was used by many android developers to develop android apps, but now most of the developers has shifted from Eclipse to Android Studio. There are other many IDE’s available to develop android applications but most of the developers prefers Android Studio as it has its benefits in using it. Also there are other cross platform IDE’s to develop mobile applications for two leading mobile OS, Android and IOS ,that means single code for both mobile OS. Sounds cool right? But we would recommend you to start first with the official IDE’s to develop applications like Android Studio for android applications and etc.


Okay now, If you made up your mind to start developing in Android Studio then you would think whether to start Android Studio with Java or Kotlin. Previously it was only Java and C++  but now it is also Android with Kotlin.

We recommend you to start Android Studio with Java first. For more article visit our site: Bunkers Point.

do check on that for more information on it.