-2

I wanna develop apk where apk works is show pop up screen after some time when internet is connected

1 Answers1

0

my friend,

If you mean you want to show pop up screen (Dialog) when the internet is connected, this code will work with your app:

AndroidManifest.xml

<!-- Access to the Internt -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

MainActivity.java

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

    if (isConnectingToInternet(MainActivity.this))
    {
        AlertDialog.Builder build = new AlertDialog.Builder(MainActivity.this);
        build.setIcon(android.R.drawable.sym_def_app_icon);
        build.setTitle("Internet Connect");
        build.setMessage("You phone is connected on internet");

        build.setCancelable(false);

        //for Yes
        build.setNegativeButton("Ok", new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int which){
                dialog.cancel();
            }
        });

        AlertDialog olustur = build.create();
        olustur.show();
    }
}

public static boolean isConnectingToInternet(Context context) {
    ConnectivityManager connectivity =
            (ConnectivityManager) context.getSystemService(
                    Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++)
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
    }
    return false;
}
Tornado
  • 35
  • 5