Articles on Trending Technologies

Technical articles with clear explanations and examples

How to set an alert in Android to fire at given date and time?

Azhar
Azhar
Updated on 07-Jul-2020 1K+ Views

This example demonstrates how to do I an alert in Android to fire at a given date and time 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 app.com.sample; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.DialogFragment; import android.app.AlarmManager; import android.app.PendingIntent; import android.app.TimePickerDialog; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.widget.TimePicker; import java.text.DateFormat; import java.util.Calendar; import java.util.Objects; public class MainActivity extends AppCompatActivity implements TimePickerDialog.OnTimeSetListener{    String timeText;   ...

Read More

Android GPS, Location Manager tutorial

Azhar
Azhar
Updated on 07-Jul-2020 2K+ Views

This example demonstrates how to access Android GPS, Location ManagerStep 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 app.com.sample; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.content.IntentSender; import android.content.pm.PackageManager; import android.location.Location; import android.net.Uri; import android.os.Bundle; import android.os.Looper; import android.provider.Settings; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import com.google.android.gms.common.api.ApiException; ...

Read More

How do add dependency in Android studio

Azhar
Azhar
Updated on 07-Jul-2020 1K+ Views

This example demonstrates about How to add dependency in Android studioStep 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 app.com.sample; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.content.IntentSender; import android.content.pm.PackageManager; import android.location.Location; import android.net.Uri; import android.os.Bundle; import android.os.Looper; import android.provider.Settings; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import ...

Read More

How to create Android Device Network Listener based on on/off network?

Azhar
Azhar
Updated on 07-Jul-2020 513 Views

This example demonstrates how do I create Android Device Network Listener based on on/off network.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

Read More

How can I get onclick event on webview in Android?

Azhar
Azhar
Updated on 07-Jul-2020 5K+ Views

This example demonstrates how do I get onClick event on webView 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.os.Message; import android.view.MotionEvent; import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnTouchListener, Handler.Callback {    private static final int CLICK_ON_WEBVIEW = 1;    private static final int CLICK_ON_URL = 2;   ...

Read More

How to play videos in Android from assets folder or raw folder?

Azhar
Azhar
Updated on 07-Jul-2020 5K+ Views

This example demonstrates how do I play videos in Android from the assets folder or raw 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 android resource folder(raw) and copy-paste your video file in that folder.Step 4 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.net.Uri; import android.os.Bundle; import android.widget.MediaController; import android.widget.VideoView; public class MainActivity extends AppCompatActivity {    @Override    protected void ...

Read More

How to implement custom FieldNamingStrategy using Gson in Java?

raja
raja
Updated on 07-Jul-2020 1K+ Views

The FieldNamingStrategy is a mechanism for providing custom field naming in Gson. This allows the client code to translate field names into a particular convention that is not supported as a normal Java field declaration rules. The translateName() method will prefix every field name with the string “pre_”.In the below example, we can implement the Custom FieldNamingStrategy.Exampleimport java.lang.reflect.Field; import com.google.gson.*; public class GsonFieldNamingStrategyTest {    public static void main(String[] args) {       Employee emp = new Employee();       emp.setEmpId(115);       emp.setFirstName("Adithya");       emp.setLastName("Jai");       CustomFieldNamingStrategy customFieldNamingStrategy = new CustomFieldNamingStrategy();     ...

Read More

How to get the JsonFactory settings using Jackson in Java?

raja
raja
Updated on 07-Jul-2020 1K+ Views

The JsonFactory class is a thread-safe and responsible for creating instances of writer and reader. The list of settings that can be turned on/off is present in an enumeration JsonFactory.Feature, it contains static method values() that return the enum constant of this type with the specified name.Syntaxpublic static enum JsonFactory.Feature extends EnumExampleimport com.fasterxml.jackson.core.JsonFactory; public class JsonFactorySettingsTest {    public static void main(String[] args) {       JsonFactory jsonFactory = new JsonFactory();       for(JsonFactory.Feature feature : JsonFactory.Feature.values()) {          boolean result = jsonFactory.isEnabled(feature);          System.out.println(feature.name() + ":" + result);       }    } }OutputINTERN_FIELD_NAMES:true ...

Read More

FieldNamingPolicy enum using Gson in Java?

raja
raja
Updated on 07-Jul-2020 1K+ Views

Gson library provides the naming conventions as part of enum FieldNamingPolicy. We can set the field naming policy using the setFieldNamingPolicy() method of the GsonBuilder class.FieldNamingPolicy enum ConstantsIDENTITY − Using this naming policy, the field name is unchanged.LOWER_CASE_WITH_DASHES − Using this naming policy, modify the Java Field name from its camel-cased form to a lower case field name where each word is separated by a dash (-).LOWER_CASE_WITH_UNDERSCORES − Using this naming policy, modify the Java Field name from its camel-cased form to a lower case field name where each word is separated by an underscore (_).UPPER_CAMEL_CASE − Using this naming policy, ...

Read More

How to get the values of a key using the JsonPointer interface in Java?

raja
raja
Updated on 07-Jul-2020 864 Views

The JSONPointer is a standard that defines a string syntax that can be used to access a particular key value in the JSON document. An instance of JSONPointer can be created by calling the static factory method createPointer() on the Json class. In the JSONPointer,  every string syntax is prefixed with “/”. We can get the value of a key by calling the getValue() method on the JsonPointer object.JSON fileExampleimport javax.json.*; import java.io.*; public class JsonPointerTest {    public static void main(String[] args) throws Exception {       JsonReader jsonReader = Json.createReader(new FileReader("simple.json"));       JsonStructure jsonStructure = jsonReader.read();       JsonPointer jsonPointer1 ...

Read More
Showing 47101–47110 of 61,248 articles
Advertisements