Android Studio Internet Check- JAVA and XML Code

Arah Lab
0


 


OnBackPressed dialog - XML CODE
Android Studio Java Code Box with Copy Button

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    >


    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:clickable="true"
        app:cardBackgroundColor="#FFFFFF"
        app:cardCornerRadius="12dp"
        app:cardElevation="10dp"
        android:layout_centerInParent="true"
        android:layout_margin="10dp"
        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                >

                <com.airbnb.lottie.LottieAnimationView
                    android:id="@+id/LottiPrime1"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    app:lottie_autoPlay="true"
                    android:layout_gravity="center"
                    app:lottie_loop="true"
                    app:lottie_rawRes="@raw/notification"
                    android:visibility="visible"
                    android:scaleType="centerCrop"
                    android:layout_marginTop="5dp"
                    />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@color/black"
                    android:gravity="center"
                    android:textSize="22sp"
                    android:text="Internet problem on your phone please check internet"
                    android:layout_marginTop="10dp"
                    android:fontFamily="@font/fond2"
                    />


            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="60dp"
                android:layout_marginRight="60dp"
                android:layout_alignParentBottom="true"
                >

                <androidx.cardview.widget.CardView
                    android:id="@+id/yes"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    app:cardBackgroundColor="#002BFF"
                    app:cardCornerRadius="30dp"
                    app:cardElevation="8dp"
                    android:layout_margin="7dp"
                    android:clickable="true"
                    android:foreground="?attr/selectableItemBackground"
                    >

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:textColor="@color/white"
                        android:textSize="25sp"
                        android:text="Okay"
                        android:gravity="center"
                        />


                </androidx.cardview.widget.CardView>


           </LinearLayout>


        </RelativeLayout>



    </androidx.cardview.widget.CardView>


</RelativeLayout>

        




  OnBackPressed dialog - JAVA CODE
Android Studio Java Code Box with Copy Button

ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mobiledata = connectivityManager.getActiveNetworkInfo();

        if (mobiledata!=null && mobiledata.isConnected()){

        }else {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);

            View myView = getLayoutInflater().inflate(R.layout.internet, null);
            alert.setView(myView);

            final AlertDialog dialog = alert.create();
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.setCancelable(false);

            myView.findViewById(R.id.yes).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    finishAndRemoveTask();
                }
            });

            dialog.show();
        }

        



Tags

Post a Comment

0Comments

Post a Comment (0)