Download New Sharecodepoint Android App from Google Play Store : DocScannerPoint : Document Scanner with OCR, PDF: Download Now


Domyhomework123.com - programming homework help. Get your programming homework done with expert homework helper. Trust Writemypaper123.com with your paper and you will never regret it.

Download Latest Notes, Study Materials and More...

Visit: Download Now


Ask Any Question Relative to your Sujbect

Visit: Ask Question


Get Two digit after decimal point in Android Studio or Java

Get Two digit after decimal point in Android Studio or Java
How to get two digits after the decimal point in java and android studio
private static String getDecimalFormat(double value) {
    String getValue = String.valueOf(value).split("[.]")[1];
      if (getValue.length() == 1) {
          return String.valueOf(value).split("[.]")[0] +
                "."+ getValue.substring(0, 1) + 
                String.format("%0"+1+"d", 0);
       } else {
          return String.valueOf(value).split("[.]")[0]
            +"." + getValue.substring(0, 2);
      }
 }
Output:

System.out.println("value getDecimalFormat:- " + getDecimalFormat(1.0));
value getDecimalFormat:- 1.00

System.out.println("value getDecimalFormat:- " + getDecimalFormat(0.22437891));
value getDecimalFormat:- 0.22

System.out.println("value getDecimalFormat:- " + getDecimalFormat(-54.0));
value getDecimalFormat:- -54.00

System.out.println("value getDecimalFormat:- " + getDecimalFormat(38495.963741));

value getDecimalFormat:- 38495.96

Copy all Files and Folder from Folder in Android studio.

Copy all Files and Folder from Folder in Android studio.
How to copy files from the folder in android studio. please try this:

Example :

AppManifest in the project. Please allow this permission to read and write external storage.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
public static void copyFileOrDirectory(String srcDir, String dstDir) {
 
        try {
            File src = new File(srcDir);
            File dst = new File(dstDir, src.getName());
 
            if (src.isDirectory()) {
 
                String files[] = src.list();
                int filesLength = files.length;
                for (int i = 0; i < filesLength; i++) {
                    String src1 = (new File(src, files[i]).getPath());
                    String dst1 = dst.getPath();
                    copyFileOrDirectory(src1, dst1);
 
                }
            } else {
                copyFile(src, dst);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public static void copyFile(File sourceFile, File destFile) throws IOException {
        if (!destFile.getParentFile().exists())
            destFile.getParentFile().mkdirs();
 
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
 
        FileChannel source = null;
        FileChannel destination = null;
 
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }

Error Configuration : Android Studio 3.1.0 - Configuration 'compile' is obsolete and has been replaced with 'implementation'

Error Configuration : Android Studio 3.1.0 - Configuration 'compile' is obsolete and has been replaced with 'implementation'

WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html Affected Modules: app

The Error in Android Studio.

Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestImplementation' and 'androidTestApi'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

Configuration 'androidTestApi' is obsolete and has been replaced with 'androidTestImplementation'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' and 'testApi'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

Solution:

Goto Gradle Scripts.

Then Goto build.gradle(Module: app)

"Configuration 'compile' is obsolete and has been replaced with 'implementation'.

Example :

If you using compile then show the configuration error just replace compile to implementation.

This is the old way of writing the dependency libraries (for Gradle version 2 and below):

dependencies with Warning in android studio 3.1

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:appcompat-v7:25.3.1'

    compile 'com.android.support:support-v4:25.3.1'

    compile 'com.android.support:design:25.3.1'

    compile 'com.google.code.gson:gson:2.6.2'

    compile 'com.squareup.retrofit2:converter-gson:2.1.0'

    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'

    compile 'com.github.channguyen:rsv:1.0.1'

    compile 'com.valdesekamdem.library:md-toast:0.9.0'

    compile 'com.google.android.gms:play-services-ads:11.0.4'

    testCompile 'junit:junit:4.12'

}

You have to Just Change the following words: 

1) compile to implementation where word compile is returned.

2) testCompile to testImplementation where testCompile is returned.

3) androidTestCompile to androidTestImplementation where androidTestCompile is return.

Check the solution for this Example

dependencies OK in android studio 3.1 | In Android Studio version 3.1 dependencies compile word is replaced to implementation. This is the new (right) way of importing the dependencies for Gradle version 3:

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:25.3.1'

    implementation 'com.android.support:support-v4:25.3.1'

    implementation 'com.android.support:design:25.3.1'

    implementation 'com.google.code.gson:gson:2.6.2'

    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'

    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'

    implementation 'com.github.channguyen:rsv:1.0.1'

    implementation 'com.valdesekamdem.library:md-toast:0.9.0'

    implementation 'com.google.android.gms:play-services-ads:11.0.4'

    testImplementation 'junit:junit:4.12'

}

 

If you Want to add a third-party library like retrofit and another library. Then you have to use the implementation Keyword not compile Keyword.

For Example:

This is wrong.
compile 'com.squareup.retrofit2:retrofit:2.4.0'

This is Right.
implementation 'com.squareup.retrofit2:retrofit:2.4.0'

Android App - Type of android app

Android App - Type of android app

Android app is one of the most popular among us. Android app is available on all android phones. Games and many more apps are built in these days for android phones. The android app is created for users who use phones all the time. The android app makes the work easier for everyone. For Example before if we have to deposit money to account then we have to go to the bank but now we don't need to go anywhere. Our mobile does everything in any place. The android app makes the process simpler. Through this, we can deposit money or we can do multiple transactions instantly without any delay.

Android app is having games and other popular features too like barcode scanner, camera, etc. We can download any android app through the Google Play store. Play Store is the place where we can install any app. Developers first make an android app in ionic, PhoneGap or great native and then publish it on play store then you can download the Android app.  

Android studio is the platform that is commonly used to develop an android app. You can also build your own app if you have a good knowledge of development. Sometimes the storage space problem also occurs while installing a new android app from the play store. Android apps are written in java programming languages and use java libraries. 

Android app is of two types:
1.Hybrid App
2.Native App

Amazon app stores and many other android apps focussed websites are used for installing android apps. Android app is running on an android platform which is a software application. A typical Android app is designed for smartphones, tablets, Pc running on the Android operating system. Android is a mobile operating system which is very much helpful for us to make our tasks better than earlier.

Top 20 Android Interview Questions and Answers Cheat Sheet - sharecodepoint

Top 20  Android Interview Questions and Answers Cheat Sheet - sharecodepoint

Android programming is growing day by day. The questions asked by interviewers in android is given below. A list of top android interview questions and answers:

1. What is Android?
Android is an open-source, Linux-based operating system used in mobiles, tablets, televisions, etc.

2. Who is the founder of Android?
Andy Rubin.

3. Explain the Android application architecture.
Following is a list of components of Android application architecture:
Services: Used to perform background functionalities. 
Intent: Used to perform the interconnection between activities and the data passing mechanism. Resource Externalization: strings and graphics. 
Notification: light, sound, icon, notification, dialog box and toast. 
Content Providers: It will share the data between applications.

4. What are the code names of android?
  1. Aestro 
  2. Blender 
  3. Cupcake 
  4. Donut 
  5. Eclair 
  6. Froyo 
  7. Gingerbread 
  8. Honeycomb 
  9. Ice Cream 
  10. Sandwich 
  11. Jelly 
  12. Bean 
  13. KitKat 
  14. Lollipop Marshmallow

5. What are the advantages of Android?
Open-source: It means no license, distribution and development fee. 
Platform-independent: It supports Windows, Mac, and Linux platforms. 
Supports various technologies: It supports camera, Bluetooth, wifi, speech, EDGE etc. technologies. 
Highly optimized Virtual Machine: Android uses a highly optimized virtual machine for mobile devices, called DVM (Dalvik Virtual Machine).

6. Does android support other languages than java?
Yes, an android app can be developed in C/C++ also using android NDK (Native Development Kit). It makes performance faster. It should be used with the Android SDK.

7. What are the core building blocks of android?
The core building blocks of Android are 
Activity 
View 
Intent 
Service 
Content Provider 
Fragment etc.

8. What is activity in Android?
Activity is like a frame or window in java that represents GUI. It represents one screen of android.

9. What are the life cycle methods of android activity?
There are 7 life-cycle methods of activity. They are as follows: 
onCreate() 
onStart() 
onResume() 
onPause() 
onStop() 
onRestart() 
onDestroy()

10. What is the intent?
It is a kind of message or information that is passed to the components. It is used to launch an activity, display a web page, send SMS, send an email, etc. There are two types of intents in android: 
Implicit Intent 
Explicit Intent

11. How are the view elements identified in the android program?
View elements can be identified using the keyword findViewById.

12. Define Android toast.
An android toast provides feedback to the users about the operation being performed by them. It displays the message regarding the status of the operation initiated by the user.

13. Explain the use of 'bundle' in android?
We use bundles to pass the required data to various subfolders.

14. What is an application resource file?
The files which can be injected for the building up of a process are called an application resource file.

15. List the various storages that are provided by Android.
The various storage provided by android are: 
Shared Preferences 
Internal Storage 
External Storage 
SQLite Databases 
Network Connection

16. How are layouts placed in Android?
Layouts in Android are placed as XML files.

17. What is the implicit intent in android?
The Implicit intent is used to invoke the system components.

18. What is explicit intent in android?
An explicit intent is used to invoke the activity class.

19. What is a fragment?
The fragment is a part of Activity by which we can display multiple screens on one activity.

20. Which types of flags are used to run an application on Android?
Following are two types of flags to run an application in Android: 
FLAG_ACTIVITY_NEW_TASK
 FLAG_ACTIVITY_CLEAR_TOP

Android Studio Shortcuts key - Important shortcut keys

Android Studio Shortcuts key - Important shortcut keys
1. Ctrl + Shift + N :- Go to File 

2. Ctrl + E :- Lookup recent file 

3. Ctrl + G :- Go to line 

4. Ctrl + B :- Go to declaration 

5. Ctrl + Alt + B :- Go to implementation 

6. F4 :- Go to source 

7. Ctrl + U :- Go to super class

8. Ctrl + Alt + H :- Show Call hierarchy

9. Ctrl + Shift + F :- Search in path/project

10. Ctrl + Alt + L : Reformat code 

11. Ctrl + Alt + O :- Optimize imports 

12. Ctrl + Space : Code Completion 

13. Alt + Enter :- Issue quick fix 

14. Ctrl + Alt + T :- Surround code block

15. Shift + F6 :- Resume and refactor

16. Ctrl + / :- Line Comment or Uncomment 

17. Ctrl + Shift + / :- Block Comment or Uncomment

18. Alt + UP/ DOWN :- Go to previous / next method

19. Ctrl + P :- Show parameters for method

20. Ctrl + Q :- Quick documentation lookup 

21. Ctrl + Y :- Delete line

22. Atl + Delete :- Safe Delete 

23. Ctrl + F4 :- Close Active Tab

24. Shift + f10 :- Build and Run

25. Ctrl + F9 :- Build

26. Ctrl + Shift + A :- All purpose (Meta) Shortcut

27. Ctrl + Shift + Backspace : Navigate to last edit location 

28. Alt + Arrow Left/ Arrow Right :- Navigate open tabs

How to add admob ads in android app - Mobile app monetization the smart way

How to add admob ads in android app - Mobile app monetization the smart way
AdMob helps app developers monetize their mobile apps by showing ads in their mobile apps. - Admob.

How to generate Ads for Android apps !

How to monetize your android application using AdMob.

AdMob is a mobile ad network from google.

In this tutorial i will show you how to place AdMob simple banner ad in your android application.

What is Admob ?
adMob can be used for Android and iOS apps... Full Details


Step 1 : Add complie line to build.gradle
Go to > build.gradle (Module: app) 
compile 'com.google.firebase:firebase-ads:10.0.1' 

compile 'com.google.android.gms:play-services-ads:10.0.1'


Step 2 : Add string to string.xml
Even resource part-system glitch.
<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>

Step 3 : Add xmlns to main_activity.xml
xmlns:ads="http://schemas.android.com/apk/res-auto"
<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111" >
    </com.google.android.gms.ads.AdView>

Step 4 : Import class into MainActivity.java
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

AdView adView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
                .setRequestAgent("android_studio:ad_template").build();
        adView.loadAd(adRequest);

Step 5 : Add user permission to AndroidMainfest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

That's it! To place AdMob simple banner ad in your android application. Thanks for reading!

 If you have any doubt regarding the tutorial then leave your doubts in the comment box.

Make login page android app using android studio with validation : Part 1

Make login page android app using android studio with validation : Part 1
This tutorial in on how to make login page android app using android studio with validation.

Login Page project is an android app is implemented in android studio. You can download login page android app with source code.

How to import the project :
Create new project . You just need to copy the code then paste that code into your project.Create new project . You just need to copy the code then paste that code into your project.

Login Information : 
Username : sy@scp.com
Password : abc@123

LoginPage android app features :
  • Add all validation : like 
    • username & password incorrect.
    •  username & password blank error and more.
  • Clear focus
  • Reset Fields
Step 1:
Firstly import the package of android files.
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
Step 2 :
First we want to create a login page layout. Add 2 EditText  (one is for take username from user & second is use to take the password from the user.) , 2 Button (one is login button & second is reset button) and 1 TextView (show the error status).
activity_main.xml
<?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"
    android:padding="10dp"
    tools:context="com.sharecodepoint.loginpage.MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Email Address"
        android:id="@+id/username"
        android:layout_marginTop="20dp"
        android:textSize="17dp"
        android:inputType="textEmailAddress"
        android:padding="10dp"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:id="@+id/password"
        android:textSize="17dp"
        android:inputType="textPassword"
        android:padding="10dp"
        android:layout_below="@id/username"
        android:layout_marginTop="20dp"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/login"
        android:text="Login"
        android:layout_below="@id/password"
        android:layout_marginTop="20dp"
        android:background="#009688"
        android:textColor="#f5f5f5"
        android:textSize="17dp"
        android:onClick="dothis"
        />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/reset"
        android:text="Reset"
        android:layout_below="@id/login"
        android:layout_marginTop="20dp"
        android:background="#AD1457"
        android:textColor="#f5f5f5"
        android:textSize="17dp"
        android:onClick="dorest"
        />
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/reset"
        android:layout_marginTop="40dp"
        android:id="@+id/showerror"
        android:textSize="20dp"
        android:padding="10dp"
        android:textAlignment="center"
        android:textColor="#f5f5f5"/>
</RelativeLayout>

Step 3 :
In this code you get :
1. How to clear focus from EditText.
2. How to change the background color of TextView with color string.
3. How to set Visibility of TextView (INVISIBLE & VISIBLE).
4. How to use if else in android.
5. How to compare the string value in android.
6. How to use not operator in android.
7. How to change the main activity title when login is successfully.

MainActivity.java
public class MainActivity extends AppCompatActivity {

    EditText user, pass;
    Button btn,rest;
    TextView error;

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

        user = (EditText) findViewById(R.id.username);
        pass = (EditText) findViewById(R.id.password);
        btn = (Button) findViewById(R.id.login);
        rest = (Button) findViewById(R.id.reset);
        error = (TextView)findViewById(R.id.showerror);
        error.setVisibility(View.INVISIBLE);
    }

    public void dothis(View v) {
        String u = user.getText().toString();
        String p = pass.getText().toString();
        String check_email = "sy@scp.com";
        String check_pass = "abc@123";

        if (u.equals("")) {
            error.setVisibility(View.VISIBLE);
            error.setBackgroundColor(Color.parseColor("#D50000"));
            error.setText("Please enter your email");

        } 
        else if (p.equals("")) {
            error.setVisibility(View.VISIBLE);
            error.setBackgroundColor(Color.parseColor("#D50000"));
            error.setText("Please enter your password");
            pass.onEditorAction(EditorInfo.IME_ACTION_DONE);

        }
        else if (!u.equals(check_email) && !p.equals(check_pass)) {
            error.setVisibility(View.VISIBLE);
            error.setBackgroundColor(Color.parseColor("#D50000"));
            error.setText("Invalid Email or Invalid Password");
            user.onEditorAction(EditorInfo.IME_ACTION_DONE);
            pass.onEditorAction(EditorInfo.IME_ACTION_DONE);
        }
        else if (!u.equals(check_email)) {
            error.setVisibility(View.VISIBLE);
            error.setText("Invalid Email");
            error.setBackgroundColor(Color.parseColor("#D50000"));
        }
        else if (!p.equals(check_pass)) {
            error.setVisibility(View.VISIBLE);
            error.setBackgroundColor(Color.parseColor("#D50000"));
            error.setText("Invalid Password");
            pass.onEditorAction(EditorInfo.IME_ACTION_DONE);
        }
        else if (u.equals(check_email) && p.equals(check_pass)) {
            error.setVisibility(View.VISIBLE);
            error.setBackgroundColor(Color.parseColor("#D50000"));
            error.setText("Login Successfully !!");
            error.setBackgroundColor(Color.parseColor("#00C853"));
            pass.onEditorAction(EditorInfo.IME_ACTION_DONE);
            setTitle("Welcome: " + u);
        }
    }
    public  void dorest(View v){
        user.setText("");
        pass.setText("");
        pass.clearFocus();
    }
}

Output : 




That's it! Download apk files. Thanks for reading!

If you have any doubt regarding the creation of android app then leave your doubts in the comment box.

How to create simple notepad  in android: check out

 Animated Bouncing Balls Using HTML and CSS3