I wanna develop apk where apk works is show pop up screen after some time when internet is connected
Asked
Active
Viewed 156 times
1 Answers
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
-
bro this msg is pop up when apk is open .. but i wanna show pop up when end user close apk .Also i wanna set up time for pop up . – Talha Ali May 30 '21 at 04:28
-
but I want the application to show notifications without open the apk.. – Talha Ali May 31 '21 at 11:31