Play Custom Sound on Receiving Notification in Android

Anvi Jain
Updated on 30-Jul-2019 22:30:26

2K+ Views

This example demonstrate about How to play a custom sound on receiving notification 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.package app.tutorialspoint.com.notifyme ; import android.app.Activity ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.content.Intent ; import android.media.RingtoneManager ; import android.net.Uri ; import android.os.Bundle ; import android.support.annotation. Nullable ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; public class MainActivity ... Read More

Update Inner Field in MongoDB

Smita Kapse
Updated on 30-Jul-2019 22:30:26

194 Views

To update the inner field, use the below syntax −db.yourCollectionName.update({"_id" : yourObjectId}, {$set : {"yourOuterFieldName.yourInnerFieldName" :yourValue}});Let us first create a collection with documents −> db.updateDocumentDemo.insertOne( ...   { ... ...      "StudentDetails" : { ...         "StudentFirstName" : "Adam", ...         "StudentLastName" : "Samith" ...      }, ...      "StudentOtherDetails" : { ...         "StudentFavouriteSubject" : "MySQL", ...         "StudentScore" : 45 ...      } ...   } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd50bb32cba06f46efe9efe") }Following is the query to ... Read More

Set FlowLayout for JFrame in Java

Anvi Jain
Updated on 30-Jul-2019 22:30:26

683 Views

To set FlowLayout for a frame, use the Container. At first, set a JFrame −JFrame frame = new JFrame();Now, use Container and set the layout as FlowLayout−Container container container = frame.getContentPane(); container.setLayout(new FlowLayout());The following is an example to set FlowLayout for JFrame −Examplepackage my; import java.awt.Container; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] val) {       JFrame frame = new JFrame();       Container container;       JButton btn;       frame.setBounds(20, 20, 15, 15);       container = frame.getContentPane();       container.setLayout(new ... Read More

Set TitledBorder Direction in Java

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

169 Views

To set TitleBorder direction, you need to use the constants and set it for border. For example, for direction center −TitledBorder border = BorderFactory.createTitledBorder("Border"); border.setTitlePosition(TitledBorder.CENTER);Above, we have set the setTitlePosition() for the direction.The following is an example to set TitledBorder direction in Java −Examplepackage my; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.TitledBorder; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       TitledBorder border = BorderFactory.createTitledBorder("Border");       border.setTitlePosition(TitledBorder.CENTER);       TitledBorder border2 = new TitledBorder(   ... Read More

Remove Array Element from MongoDB Collection Using Update and Pull

George John
Updated on 30-Jul-2019 22:30:26

207 Views

Let us first create a collection with documents -> db.removingAnArrayElementDemo.insertOne({"UserMessage":["Hi", "Hello", "Bye"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cef97bdef71edecf6a1f6a4") }Display all documents from a collection with the help of find() method -> db.removingAnArrayElementDemo.find().pretty();Output{    "_id" : ObjectId("5cef97bdef71edecf6a1f6a4"),    "UserMessage" : [       "Hi",       "Hello",       "Bye"    ] }Following is the query to remove an array element from MongoDB -> db.removingAnArrayElementDemo.update(    {_id:ObjectId("5cef97bdef71edecf6a1f6a4")},    { "$pull": { "UserMessage": "Hello" } } ); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })Let us check the document once again:> db.removingAnArrayElementDemo.find().pretty();Output{   ... Read More

Importance of Math.trunc() Method in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

183 Views

Math.trunc()Unlike Math.floor(), Math.ceil() and Math.round(), Math.trunc() method removes fractional part and gives out only integer part. It doesn't care about rounding the number to the nearest integer. It doesn't even notice whether the value is positive or negative. Its function is only to chop up the fractional part.syntaxMath.trunc(x);parameters - Math.trunc() takes a number as an argument and truncates the fractional part.In the following example, Math.trunc() method truncated the fractional values of the provided positive numbers.ExampleLive Demo var val1 = Math.trunc("1.414"); var val2 = Math.trunc("0.49"); var val3 = Math.trunc("8.9"); document.write(val1); ... Read More

Work with Auto-Incrementing Column in MySQL

Rama Giri
Updated on 30-Jul-2019 22:30:26

138 Views

To work with auto incrementing column, you can set it as AUTO_INCREMENT while creating the table.Let us first create a table. Here, we have set the Id field as column since that would be our auto increment column −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(20),    -> LastName varchar(20)    -> ); Query OK,  0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName, LastName) values('John', 'Smith'); Query OK,  1 row affected (0.14 sec) mysql> insert into DemoTable(FirstName, LastName) values('Chris', 'Brown'); Query OK,  1 row affected (0.13 sec) mysql> insert into DemoTable(FirstName, LastName) values('Carol', 'Taylor'); Query OK,  1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+----+-----------+----------+ | Id | FirstName | LastName | +----+-----------+----------+ | 1  | John  ... Read More

All Permutations of a String Using Iteration

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

888 Views

In this section we will see how to get all permutations of a string. The recursive approach is very simple. It uses the back-tracking procedure. But here we will use the iterative approach.All permutations of a string ABC are like {ABC, ACB, BAC, BCA, CAB, CBA}. Let us see the algorithm to get the better idea.AlgorithmgetAllPerm(str)begin    sort the characters of the string    while true, do       print the string str       i := length of str – 1       while str[i - 1] >= str[i], do          i := ... Read More

OpenCV Python Program to Blur an Image

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

649 Views

OpenCV is one of the best python package for image processing. Also like signals carry noise attached to it, images too contain different types of noise mainly from the source itself (Camera sensor). Python OpenCV package provides ways for image smoothing also called blurring. This is what we are going to do in this section. One of the common technique is using Gaussian filter (Gf) for image blurring. With this, any sharp edges in images are smoothed while minimizing too much blurring.Syntaxcv.GaussianBlur(src,  ksize,  sigmaX[,  dst[,  sigmaY[,  borderType=BORDER_DEFAULT]]] )Where−src – input imagedst – output imageksize – Gaussian kernel size[ height width]. If ksize ... Read More

Clear All Selections in Java Swing JList

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

707 Views

To clear all selections, use the List clearSelection() method in Java −JList list = new JList(sports); list.clearSelection();Above, the elements in Sports array is a String array −String sports[]= { "Cricket", "Football", "Hockey", "Rugby"};The following is an example to clear all selection in JList −Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame {    static JFrame frame;    static JList list;    public static void main(String[] args) {       frame = new JFrame("JList Demo");       SwingDemo s = new SwingDemo();       JPanel panel = new JPanel();       String sports[]= ... Read More

Advertisements