System directories
| Method | Result |
|---|---|
| Environment.getDataDirectory() | /data |
| Environment.getDownloadCacheDirectory() | /cache |
| Environment.getRootDirectory() | /system |
External storage directories
| package com.example.mobile1; | |
| public class student { | |
| private String name; | |
| private String family; | |
| private String major; | |
| private String age; | |
| private String idNumber; | |
| public student(String name, String family, String major, String age, String idNumber) { |
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout 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:orientation="vertical" | |
| android:background="#fe1" | |
| tools:context=".MainActivity"> |
| package com.example.testapp1; | |
| import android.content.BroadcastReceiver; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.net.ConnectivityManager; | |
| import android.net.NetworkInfo; | |
| public class MBroadcastReceiver extends BroadcastReceiver { |
| <?xml version="1.0" encoding="utf-8"?> | |
| <androidx.constraintlayout.widget.ConstraintLayout 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:orientation="horizontal" | |
| tools:context=".MainActivity"> | |
| private void showProgressDialog() { | |
| ProgressDialog progressDialog = new ProgressDialog(this); | |
| progressDialog.setTitle("Progress Dialog"); | |
| progressDialog.setMessage("Loading..."); | |
| progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); | |
| progressDialog.setCancelable(false); | |
| progressDialog.show(); | |
| // Simulate a long-running task | |
| new Handler().postDelayed(() -> { |
| private void showAlertDialog() { | |
| AlertDialog.Builder builder = new AlertDialog.Builder(this); | |
| builder.setIcon(R.drawable.outline_error_24); | |
| builder.setTitle("Alert Dialog"); | |
| builder.setMessage("This is an alert dialog."); | |
| builder.setPositiveButton("OK", (dialog, which) -> dialog.dismiss()); | |
| builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { | |
| @Override | |
| public void onClick(DialogInterface dialog, int which) { | |
| Toast.makeText(getBaseContext(), "Show Alert Dialog Canceled", Toast.LENGTH_SHORT).show(); |
| public static boolean isNetworkConnected(Context context) { | |
| ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |
| android.net.Network network = connectivityManager.getActiveNetwork(); | |
| if (network == null) return false; | |
| NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(network); | |
| if (networkCapabilities == null) return false; |
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
| public class TempListItem { | |
| private String[] name = { | |
| "Emily", | |
| "James", | |
| "Sophia", | |
| "William", | |
| "Olivia", | |
| "Benjamin", | |
| "Ava", |
System directories
| Method | Result |
|---|---|
| Environment.getDataDirectory() | /data |
| Environment.getDownloadCacheDirectory() | /cache |
| Environment.getRootDirectory() | /system |
External storage directories