Found 1631 Articles for Android

How to obtain the phone number of the android phone programmatically?

Azhar
Updated on 03-Jul-2020 08:39:23

652 Views

This example demonstrates how do I obtain the phone number of the android phone programmatically.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javaimport android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.telephony.TelephonyManager; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    TextView textView;    private static final int REQUEST_CODE = 101;    @Override    protected ... Read More

How to send an object one Android activity to another using Intents?

Azhar
Updated on 03-Jul-2020 08:40:13

187 Views

This example demonstrates how do I send an object from one android activity to another using intents.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 – Create an object from a java class (Message.java)import java.io.Serializable; public class Message implements Serializable {    private static final long serialVersionUID = 1L;    private String message;    public String getMessage(){       return message;    }    public void setMessage(String ... Read More

How to get fling gesture detection working in an android app?

Azhar
Updated on 03-Jul-2020 08:40:51

645 Views

This example demonstrates how do I get fling gesture detection working in an android app.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javaimport android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.GestureDetector; import android.view.MotionEvent; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    GestureDetector gestureDetector;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       gestureDetector = new ... Read More

How to write files to asset folder in android?

Azhar
Updated on 03-Jul-2020 08:41:35

3K+ Views

This example demonstrates how do I write files to asset folder in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 – Create a new Assets folder and write a new text file in it.To write a text file, Right click, select New >> file (Quote.txt)Step 4 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.io.IOException; import java.io.InputStream; public ... Read More

How to pass a variable from Activity to Fragment in Android?

Azhar
Updated on 03-Jul-2020 08:42:40

3K+ Views

This example demonstrates how do I pass a variable from activity to Fragment in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                 Step 3 − Add the following code to src/MainActivity.javaimport android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; 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) {   ... Read More

How to get the Action bar height in android?

Azhar
Updated on 03-Jul-2020 08:44:49

1K+ Views

This example demonstrates how do I get the action bar height in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                 Step 3 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.support.v7.widget.Toolbar;    public class MainActivity extends AppCompatActivity {    Toolbar toolbar;    Button button;    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {   ... Read More

How to convert an image to Base 64 string on Android?

Azhar
Updated on 03-Jul-2020 07:20:49

1K+ Views

This example demonstrates how do I convert an image to Base 64 string on android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 – Copy paste an image in the res/drawable. Example: res/drawable/logo.pngStep 4 − Add the following code to src/MainActivity.javaimport android.annotation.SuppressLint; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Base64; import android.widget.TextView; import java.io.ByteArrayOutputStream; public class MainActivity extends AppCompatActivity {    TextView textView;    String string;    Bitmap ... Read More

How to parse HTML in android?

Azhar
Updated on 03-Jul-2020 07:15:35

2K+ Views

This example demonstrates how do I parse HTML in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 – Add the given dependency in the build.gradle (Module: app)implementation 'org.jsoup:jsoup:1.11.2'Step 4 − Add the following code to src/MainActivity.javaimport android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.TextView; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import java.io.IOException; public class MainActivity extends AppCompatActivity {    Button button;    TextView textView; ... Read More

How to set the color of a textView span in android?

Azhar
Updated on 03-Jul-2020 07:17:54

681 Views

This example demonstrates how do I set the color of a textView span in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javaimport android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; 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);     ... Read More

How can I remove a button or make it invisible in Android?

Azhar
Updated on 03-Jul-2020 07:14:01

807 Views

This example demonstrates how remove a button or make it invisible in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.               Step 3 − Add the following code to src/MainActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends AppCompatActivity {    OnClickListener listener1=null;    OnClickListener listener2=null;    Button button1;    Button button2;    @Override    protected void onCreate(Bundle ... Read More

Advertisements