Set Absolute Position of a View in Android

Azhar
Updated on 07-Jul-2020 13:11:11

3K+ Views

This example demonstrates how do I set the absolute position of a view 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 androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.ImageView; import android.widget.RelativeLayout; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       RelativeLayout rl = findViewById(R.id.relativeLayout);       ImageView iv = ... Read More

Use Font Awesome in Native Android Application

Azhar
Updated on 07-Jul-2020 13:10:32

557 Views

This example demonstrates how do I use FontAwesome in the native android applications.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 download asset folder. Copy-paste the fontAwesome.ttf In the asset folder.Step 4 − Add the following code to src/MainActivity.javapackage app.com.sample; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Typeface; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);   ... Read More

Barcode Scanning in Android

Azhar
Updated on 07-Jul-2020 13:08:51

1K+ Views

This example demonstrates how do I use barcode scanning 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 dependency in Gradleimplementation 'com.google.zxing:core:3.2.1' implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar'Step 4 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult; public class MainActivity extends AppCompatActivity {    Button btnBarcode;    TextView textView; ... Read More

Bring an Activity to Foreground in Android

Azhar
Updated on 07-Jul-2020 13:08:06

3K+ Views

This example demonstrates how do I bring an activity to the foreground (top of stack) 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 androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       Intent i = new Intent(this, MyActivity.class);       i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); ... Read More

Run a Method Every 10 Seconds in Android

Azhar
Updated on 07-Jul-2020 13:07:01

9K+ Views

This example demonstrates how do I run a method every 10 seconds 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 androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.os.Handler; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    Handler handler = new Handler();    Runnable runnable;    int delay = 10000;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main); ... Read More

Merge Two JSON Strings in Order Using JSONParserSequence in Java

raja
Updated on 07-Jul-2020 13:06:13

880 Views

The JsonParserSequence is a helper class that can be used to create a parser containing two sub-parsers placed in a particular sequence. We can create a sequence using the static method createFlattened() of the JsonParserSequence class.Syntaxpublic static JsonParserSequence createFlattened(JsonParser first, JsonParser second)Exampleimport java.io.*; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.util.*; public class JsonParserSequenceTest {    public static void main(String[] args) throws JsonParseException, IOException {       String jsonString1 = "{\"id\":\"101\", \"name\":\"Ravi Chandra\", \"address\":\"Pune\"}";       String jsonString2 = "{\"id\":\"102\", \"name\":\"Raja Ramesh\", \"address\":\"Hyderabad\", \"contacts\":[{\"mobile\":\"9959984805\", \"home\":\"7702144400\"}]}";       JsonFactory jsonFactory = new JsonFactory();       JsonParser jsonParser1 = jsonFactory.createParser(jsonString1);       JsonParser jsonParser2 = jsonFactory.createParser(jsonString2);       ... Read More

Check If Headset is Plugged into Android Device

Azhar
Updated on 07-Jul-2020 13:04:53

1K+ Views

This example demonstrates how do I check whether a headset is plugged into an android device.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 androidx.appcompat.app.AppCompatActivity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    BroadcastReceiver broadcastReceiver;    boolean Microphone_Plugged_in = false;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);   ... Read More

Map JSON Data with Jackson Object Model in Java

raja
Updated on 07-Jul-2020 13:04:14

3K+ Views

The ObjectMapper class provides functionality for converting between Java objects and matching JSON constructs. We can achieve mapping of JSON data represented by an Object Model to a particular Java object using a tree-like data structure that reads and stores the entire JSON content in memory. In the first step, read the JSON data into the JsonNode object then mapped it to another instance by calling the treeToValue() method of ObjectMapper class.Syntaxpublic T treeToValue(TreeNode n, Class valueType) throws JsonProcessingExceptionExampleimport java.io.*; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; public class JsonTreeModelDemo {    public static void main(String[] args) throws JsonProcessingException, IOException {       String jsonString ... Read More

Create Directory Programmatically in Android

Azhar
Updated on 07-Jul-2020 12:54:18

5K+ Views

This example demonstrates how to create directory programmatically in AndroidStep 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.app.sample; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import java.io.File; import android.os.Bundle; import android.os.Environment; import android.app.Activity; import android.view.Menu; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       File file = new ... Read More

Ignore Screen Orientation Change in Android Application

Azhar
Updated on 07-Jul-2020 12:53:46

409 Views

This example demonstrates how to make an application ignore screen orientation change 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.app.sample; import androidx.appcompat.app.AppCompatActivity; import android.content.pm.ActivityInfo; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);    } }Step 4 − Add the following code ... Read More

Advertisements