androj 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- androj-0.1.0/LICENSE +17 -0
- androj-0.1.0/PKG-INFO +68 -0
- androj-0.1.0/README.md +52 -0
- androj-0.1.0/pyproject.toml +29 -0
- androj-0.1.0/setup.cfg +4 -0
- androj-0.1.0/src/androj/__init__.py +82 -0
- androj-0.1.0/src/androj/examples/airplane/AirplaneModeReceiver.java +29 -0
- androj-0.1.0/src/androj/examples/airplane/AndroidManifest.xml +23 -0
- androj-0.1.0/src/androj/examples/airplane/FILES.txt +8 -0
- androj-0.1.0/src/androj/examples/airplane/MainActivity.java +35 -0
- androj-0.1.0/src/androj/examples/alarm/AlarmReceiver.java +15 -0
- androj-0.1.0/src/androj/examples/alarm/AndroidManifest.xml +29 -0
- androj-0.1.0/src/androj/examples/alarm/FILES.txt +8 -0
- androj-0.1.0/src/androj/examples/alarm/MainActivity.java +76 -0
- androj-0.1.0/src/androj/examples/alert/FILES.txt +6 -0
- androj-0.1.0/src/androj/examples/alert/MainActivity.java +48 -0
- androj-0.1.0/src/androj/examples/battery_low/AndroidManifest.xml +23 -0
- androj-0.1.0/src/androj/examples/battery_low/BatteryLowReceiver.java +21 -0
- androj-0.1.0/src/androj/examples/battery_low/FILES.txt +8 -0
- androj-0.1.0/src/androj/examples/battery_low/MainActivity.java +36 -0
- androj-0.1.0/src/androj/examples/context_menu/FILES.txt +7 -0
- androj-0.1.0/src/androj/examples/context_menu/MainActivity.java +54 -0
- androj-0.1.0/src/androj/examples/context_menu/activity_main.xml +16 -0
- androj-0.1.0/src/androj/examples/date_time/FILES.txt +6 -0
- androj-0.1.0/src/androj/examples/date_time/MainActivity.java +42 -0
- androj-0.1.0/src/androj/examples/explicit_intents/ConfirmActivity.java +37 -0
- androj-0.1.0/src/androj/examples/explicit_intents/DetailsActivity.java +48 -0
- androj-0.1.0/src/androj/examples/explicit_intents/FILES.txt +8 -0
- androj-0.1.0/src/androj/examples/explicit_intents/MainActivity.java +109 -0
- androj-0.1.0/src/androj/examples/library_database/DBHelper.java +94 -0
- androj-0.1.0/src/androj/examples/library_database/FILES.txt +7 -0
- androj-0.1.0/src/androj/examples/library_database/MainActivity.java +114 -0
- androj-0.1.0/src/androj/examples/listview_gridview/DBHelper.java +52 -0
- androj-0.1.0/src/androj/examples/listview_gridview/FILES.txt +7 -0
- androj-0.1.0/src/androj/examples/listview_gridview/MainActivity.java +87 -0
- androj-0.1.0/src/androj/examples/options_menu/FILES.txt +7 -0
- androj-0.1.0/src/androj/examples/options_menu/MainActivity.java +39 -0
- androj-0.1.0/src/androj/examples/options_menu/main_activity.xml +7 -0
- androj-0.1.0/src/androj/examples/radio_checkbox/FILES.txt +7 -0
- androj-0.1.0/src/androj/examples/radio_checkbox/MainActivity.java +75 -0
- androj-0.1.0/src/androj/examples/radio_checkbox/activity_main.xml +10 -0
- androj-0.1.0/src/androj/examples/sms_email_call/FILES.txt +6 -0
- androj-0.1.0/src/androj/examples/sms_email_call/MainActivity.java +97 -0
- androj-0.1.0/src/androj/examples/two_activities/FILES.txt +7 -0
- androj-0.1.0/src/androj/examples/two_activities/MainActivity.java +31 -0
- androj-0.1.0/src/androj/examples/two_activities/activity_second.java +23 -0
- androj-0.1.0/src/androj.egg-info/PKG-INFO +68 -0
- androj-0.1.0/src/androj.egg-info/SOURCES.txt +48 -0
- androj-0.1.0/src/androj.egg-info/dependency_links.txt +1 -0
- androj-0.1.0/src/androj.egg-info/top_level.txt +1 -0
androj-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 andro contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
androj-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: androj
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Export Android Java and XML practical examples
|
|
5
|
+
Author: Andro contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: android,java,xml,practical,intent,sqlite
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# androj
|
|
18
|
+
|
|
19
|
+
`androj` is a small Python package that exports Android Java/XML practical source examples into your current working directory.
|
|
20
|
+
|
|
21
|
+
> This package does not build or run Android apps. It copies the bundled source snippets so you can open them in Android Studio and adapt them to your project.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install androj
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import androj
|
|
33
|
+
|
|
34
|
+
androj.help() # list all available functions
|
|
35
|
+
androj.alarm() # export alarm example
|
|
36
|
+
androj.airplane() # export Airplane Mode receiver example
|
|
37
|
+
androj.sms_email_call()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Each function creates a folder under:
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
./andro_examples/<example-name>/
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
For example, `androj.alarm()` exports the files to `andro_examples/alarm/` and returns that folder's `pathlib.Path`.
|
|
47
|
+
|
|
48
|
+
## Available functions
|
|
49
|
+
|
|
50
|
+
- `androj.airplane()`
|
|
51
|
+
- `androj.alarm()`
|
|
52
|
+
- `androj.alert()`
|
|
53
|
+
- `androj.battery_low()`
|
|
54
|
+
- `androj.context_menu()`
|
|
55
|
+
- `androj.date_time()`
|
|
56
|
+
- `androj.explicit_intents()`
|
|
57
|
+
- `androj.library_database()`
|
|
58
|
+
- `androj.listview_gridview()`
|
|
59
|
+
- `androj.options_menu()`
|
|
60
|
+
- `androj.radio_checkbox()`
|
|
61
|
+
- `androj.sms_email_call()`
|
|
62
|
+
- `androj.two_activities()`
|
|
63
|
+
|
|
64
|
+
## Important
|
|
65
|
+
|
|
66
|
+
The package includes the source snippets supplied for these practicals. Some examples do not include every Android resource (for example, every layout XML or Gradle file). You may need to create missing resources, update package names, and adjust theme/manifest entries in Android Studio.
|
|
67
|
+
|
|
68
|
+
The exported files are source code, not executable Python modules.
|
androj-0.1.0/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# androj
|
|
2
|
+
|
|
3
|
+
`androj` is a small Python package that exports Android Java/XML practical source examples into your current working directory.
|
|
4
|
+
|
|
5
|
+
> This package does not build or run Android apps. It copies the bundled source snippets so you can open them in Android Studio and adapt them to your project.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install androj
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import androj
|
|
17
|
+
|
|
18
|
+
androj.help() # list all available functions
|
|
19
|
+
androj.alarm() # export alarm example
|
|
20
|
+
androj.airplane() # export Airplane Mode receiver example
|
|
21
|
+
androj.sms_email_call()
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Each function creates a folder under:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
./andro_examples/<example-name>/
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For example, `androj.alarm()` exports the files to `andro_examples/alarm/` and returns that folder's `pathlib.Path`.
|
|
31
|
+
|
|
32
|
+
## Available functions
|
|
33
|
+
|
|
34
|
+
- `androj.airplane()`
|
|
35
|
+
- `androj.alarm()`
|
|
36
|
+
- `androj.alert()`
|
|
37
|
+
- `androj.battery_low()`
|
|
38
|
+
- `androj.context_menu()`
|
|
39
|
+
- `androj.date_time()`
|
|
40
|
+
- `androj.explicit_intents()`
|
|
41
|
+
- `androj.library_database()`
|
|
42
|
+
- `androj.listview_gridview()`
|
|
43
|
+
- `androj.options_menu()`
|
|
44
|
+
- `androj.radio_checkbox()`
|
|
45
|
+
- `androj.sms_email_call()`
|
|
46
|
+
- `androj.two_activities()`
|
|
47
|
+
|
|
48
|
+
## Important
|
|
49
|
+
|
|
50
|
+
The package includes the source snippets supplied for these practicals. Some examples do not include every Android resource (for example, every layout XML or Gradle file). You may need to create missing resources, update package names, and adjust theme/manifest entries in Android Studio.
|
|
51
|
+
|
|
52
|
+
The exported files are source code, not executable Python modules.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "androj"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Export Android Java and XML practical examples"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [{name = "Andro contributors"}]
|
|
13
|
+
keywords = ["android", "java", "xml", "practical", "intent", "sqlite"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: Software Development :: Libraries :: Python Modules"
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools]
|
|
22
|
+
package-dir = {"" = "src"}
|
|
23
|
+
include-package-data = true
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.package-data]
|
|
29
|
+
androj = ["examples/**/*"]
|
androj-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""
|
|
2
|
+
androj: Export Android Java/XML practical examples into your current project folder.
|
|
3
|
+
|
|
4
|
+
Each public example function creates:
|
|
5
|
+
./andro_examples/<example-name>/
|
|
6
|
+
|
|
7
|
+
and copies the matching Java/XML source files there.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from shutil import copy2
|
|
12
|
+
from importlib.resources import files
|
|
13
|
+
|
|
14
|
+
__version__ = "0.1.0"
|
|
15
|
+
|
|
16
|
+
_EXAMPLES = {
|
|
17
|
+
"airplane": "Listen for the Airplane Mode changed system broadcast.",
|
|
18
|
+
"alarm": "Basic AlarmManager and BroadcastReceiver example.",
|
|
19
|
+
"alert": "AlertDialog example.",
|
|
20
|
+
"battery_low": "Listen for the system battery-low broadcast.",
|
|
21
|
+
"context_menu": "Context menu example for changing a background color.",
|
|
22
|
+
"date_time": "Display date and time in different formats.",
|
|
23
|
+
"explicit_intents": "Three-activity example using explicit intents and extras.",
|
|
24
|
+
"library_database": "SQLite library-management example.",
|
|
25
|
+
"listview_gridview": "SQLite product list using ListView and GridView.",
|
|
26
|
+
"options_menu": "Options menu example.",
|
|
27
|
+
"radio_checkbox": "RadioButton and CheckBox example.",
|
|
28
|
+
"sms_email_call": "Implicit intents for SMS, email, and phone dialer.",
|
|
29
|
+
"two_activities": "Navigate between two activities using an explicit intent.",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def _export_example(name: str) -> Path:
|
|
33
|
+
"""Copy one example's bundled source files into ./andro_examples/<name>/."""
|
|
34
|
+
if name not in _EXAMPLES:
|
|
35
|
+
raise ValueError(f"Unknown example: {name}")
|
|
36
|
+
|
|
37
|
+
destination = Path.cwd() / "andro_examples" / name
|
|
38
|
+
destination.mkdir(parents=True, exist_ok=True)
|
|
39
|
+
|
|
40
|
+
source_folder = files("androj").joinpath("examples", name)
|
|
41
|
+
for item in source_folder.iterdir():
|
|
42
|
+
if item.is_file():
|
|
43
|
+
with item.open("rb") as source, (destination / item.name).open("wb") as target:
|
|
44
|
+
target.write(source.read())
|
|
45
|
+
|
|
46
|
+
print(f"Downloaded/exported '{name}' example to: {destination}")
|
|
47
|
+
return destination
|
|
48
|
+
|
|
49
|
+
def help() -> str:
|
|
50
|
+
"""Print the available androj functions and return the same help text."""
|
|
51
|
+
lines = [
|
|
52
|
+
"androj - Android practical source exporter",
|
|
53
|
+
"",
|
|
54
|
+
"Available functions:",
|
|
55
|
+
]
|
|
56
|
+
for name, description in _EXAMPLES.items():
|
|
57
|
+
lines.append(f" androj.{name}()")
|
|
58
|
+
lines.append(f" {description}")
|
|
59
|
+
lines += [
|
|
60
|
+
"",
|
|
61
|
+
"Each function exports its source files to:",
|
|
62
|
+
" ./andro_examples/<example-name>/",
|
|
63
|
+
]
|
|
64
|
+
message = "\n".join(lines)
|
|
65
|
+
print(message)
|
|
66
|
+
return message
|
|
67
|
+
|
|
68
|
+
def airplane(): return _export_example("airplane")
|
|
69
|
+
def alarm(): return _export_example("alarm")
|
|
70
|
+
def alert(): return _export_example("alert")
|
|
71
|
+
def battery_low(): return _export_example("battery_low")
|
|
72
|
+
def context_menu(): return _export_example("context_menu")
|
|
73
|
+
def date_time(): return _export_example("date_time")
|
|
74
|
+
def explicit_intents(): return _export_example("explicit_intents")
|
|
75
|
+
def library_database(): return _export_example("library_database")
|
|
76
|
+
def listview_gridview(): return _export_example("listview_gridview")
|
|
77
|
+
def options_menu(): return _export_example("options_menu")
|
|
78
|
+
def radio_checkbox(): return _export_example("radio_checkbox")
|
|
79
|
+
def sms_email_call(): return _export_example("sms_email_call")
|
|
80
|
+
def two_activities(): return _export_example("two_activities")
|
|
81
|
+
|
|
82
|
+
__all__ = ["help", *_EXAMPLES.keys()]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package com.example.myapp; // Keep your own package name
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.widget.Toast;
|
|
7
|
+
|
|
8
|
+
public class AirplaneModeReceiver extends BroadcastReceiver {
|
|
9
|
+
|
|
10
|
+
@Override
|
|
11
|
+
public void onReceive(Context context, Intent intent) {
|
|
12
|
+
|
|
13
|
+
if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
|
|
14
|
+
|
|
15
|
+
boolean isAirplaneModeOn =
|
|
16
|
+
intent.getBooleanExtra("state", false);
|
|
17
|
+
|
|
18
|
+
String message;
|
|
19
|
+
|
|
20
|
+
if (isAirplaneModeOn) {
|
|
21
|
+
message = "Airplane Mode is ON";
|
|
22
|
+
} else {
|
|
23
|
+
message = "Airplane Mode is OFF";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
|
+
|
|
4
|
+
<application
|
|
5
|
+
android:allowBackup="true"
|
|
6
|
+
android:label="Airplane Mode App"
|
|
7
|
+
android:supportsRtl="true"
|
|
8
|
+
android:theme="@style/Theme.MyApplication">
|
|
9
|
+
|
|
10
|
+
<activity
|
|
11
|
+
android:name=".MainActivity"
|
|
12
|
+
android:exported="true">
|
|
13
|
+
|
|
14
|
+
<intent-filter>
|
|
15
|
+
<action android:name="android.intent.action.MAIN" />
|
|
16
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
17
|
+
</intent-filter>
|
|
18
|
+
|
|
19
|
+
</activity>
|
|
20
|
+
|
|
21
|
+
</application>
|
|
22
|
+
|
|
23
|
+
</manifest>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Example: Airplane
|
|
2
|
+
|
|
3
|
+
Files included:
|
|
4
|
+
- MainActivity.java
|
|
5
|
+
- AirplaneModeReceiver.java
|
|
6
|
+
- AndroidManifest.xml
|
|
7
|
+
|
|
8
|
+
These are the source snippets supplied for this example. You may need to add or adapt layout resources, package names, theme names, and manifest entries in Android Studio.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package com.example.myapp; // Keep your own package name
|
|
2
|
+
|
|
3
|
+
import android.content.IntentFilter;
|
|
4
|
+
import android.os.Bundle;
|
|
5
|
+
import android.widget.TextView;
|
|
6
|
+
|
|
7
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
8
|
+
|
|
9
|
+
public class MainActivity extends AppCompatActivity {
|
|
10
|
+
|
|
11
|
+
TextView tvStatus;
|
|
12
|
+
AirplaneModeReceiver receiver;
|
|
13
|
+
|
|
14
|
+
@Override
|
|
15
|
+
protected void onCreate(Bundle savedInstanceState) {
|
|
16
|
+
super.onCreate(savedInstanceState);
|
|
17
|
+
setContentView(R.layout.activity_main);
|
|
18
|
+
|
|
19
|
+
tvStatus = findViewById(R.id.tvStatus);
|
|
20
|
+
receiver = new AirplaneModeReceiver();
|
|
21
|
+
|
|
22
|
+
IntentFilter filter =
|
|
23
|
+
new IntentFilter("android.intent.action.AIRPLANE_MODE");
|
|
24
|
+
|
|
25
|
+
registerReceiver(receiver, filter);
|
|
26
|
+
|
|
27
|
+
tvStatus.setText("Receiver registered. Change Airplane Mode to test.");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Override
|
|
31
|
+
protected void onDestroy() {
|
|
32
|
+
super.onDestroy();
|
|
33
|
+
unregisterReceiver(receiver);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.example.myapp; // Keep your own package name
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.widget.Toast;
|
|
7
|
+
|
|
8
|
+
public class AlarmReceiver extends BroadcastReceiver {
|
|
9
|
+
|
|
10
|
+
@Override
|
|
11
|
+
public void onReceive(Context context, Intent intent) {
|
|
12
|
+
Toast.makeText(context, "Alarm! Time to wake up!",
|
|
13
|
+
Toast.LENGTH_LONG).show();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<uses-permission
|
|
2
|
+
android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
|
3
|
+
|
|
4
|
+
<application
|
|
5
|
+
android:allowBackup="true"
|
|
6
|
+
android:icon="@mipmap/ic_launcher"
|
|
7
|
+
android:label="Alarm Clock"
|
|
8
|
+
android:roundIcon="@mipmap/ic_launcher_round"
|
|
9
|
+
android:supportsRtl="true"
|
|
10
|
+
android:theme="@style/Theme.MyApplication">
|
|
11
|
+
|
|
12
|
+
<receiver
|
|
13
|
+
android:name=".AlarmReceiver"
|
|
14
|
+
android:enabled="true"
|
|
15
|
+
android:exported="false" />
|
|
16
|
+
|
|
17
|
+
<activity
|
|
18
|
+
android:name=".MainActivity"
|
|
19
|
+
android:exported="true">
|
|
20
|
+
|
|
21
|
+
<intent-filter>
|
|
22
|
+
<action android:name="android.intent.action.MAIN" />
|
|
23
|
+
|
|
24
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
25
|
+
</intent-filter>
|
|
26
|
+
|
|
27
|
+
</activity>
|
|
28
|
+
|
|
29
|
+
</application>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Example: Alarm
|
|
2
|
+
|
|
3
|
+
Files included:
|
|
4
|
+
- MainActivity.java
|
|
5
|
+
- AlarmReceiver.java
|
|
6
|
+
- AndroidManifest.xml
|
|
7
|
+
|
|
8
|
+
These are the source snippets supplied for this example. You may need to add or adapt layout resources, package names, theme names, and manifest entries in Android Studio.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
package com.example.myapp;
|
|
2
|
+
|
|
3
|
+
import android.app.AlarmManager;
|
|
4
|
+
import android.app.PendingIntent;
|
|
5
|
+
import android.content.Context;
|
|
6
|
+
import android.content.Intent;
|
|
7
|
+
import android.os.Bundle;
|
|
8
|
+
import android.widget.Button;
|
|
9
|
+
import android.widget.TimePicker;
|
|
10
|
+
import android.widget.Toast;
|
|
11
|
+
|
|
12
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
13
|
+
|
|
14
|
+
import java.util.Calendar;
|
|
15
|
+
|
|
16
|
+
public class MainActivity extends AppCompatActivity {
|
|
17
|
+
|
|
18
|
+
TimePicker timePicker;
|
|
19
|
+
Button btnSetAlarm, btnCancelAlarm;
|
|
20
|
+
AlarmManager alarmManager;
|
|
21
|
+
PendingIntent pendingIntent;
|
|
22
|
+
|
|
23
|
+
@Override
|
|
24
|
+
protected void onCreate(Bundle savedInstanceState) {
|
|
25
|
+
super.onCreate(savedInstanceState);
|
|
26
|
+
setContentView(R.layout.activity_main);
|
|
27
|
+
|
|
28
|
+
timePicker = findViewById(R.id.timePicker);
|
|
29
|
+
btnSetAlarm = findViewById(R.id.btnSetAlarm);
|
|
30
|
+
btnCancelAlarm = findViewById(R.id.btnCancelAlarm);
|
|
31
|
+
|
|
32
|
+
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
|
33
|
+
|
|
34
|
+
Intent intent = new Intent(this, AlarmReceiver.class);
|
|
35
|
+
|
|
36
|
+
pendingIntent = PendingIntent.getBroadcast(
|
|
37
|
+
this,
|
|
38
|
+
0,
|
|
39
|
+
intent,
|
|
40
|
+
PendingIntent.FLAG_UPDATE_CURRENT |
|
|
41
|
+
PendingIntent.FLAG_IMMUTABLE
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
btnSetAlarm.setOnClickListener(v -> setAlarm());
|
|
45
|
+
|
|
46
|
+
btnCancelAlarm.setOnClickListener(v -> cancelAlarm());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private void setAlarm() {
|
|
50
|
+
int hour = timePicker.getHour();
|
|
51
|
+
int minute = timePicker.getMinute();
|
|
52
|
+
|
|
53
|
+
Calendar calendar = Calendar.getInstance();
|
|
54
|
+
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
|
55
|
+
calendar.set(Calendar.MINUTE, minute);
|
|
56
|
+
calendar.set(Calendar.SECOND, 0);
|
|
57
|
+
|
|
58
|
+
// If the selected time has already passed, schedule it for tomorrow
|
|
59
|
+
if (calendar.getTimeInMillis() <= System.currentTimeMillis()) {
|
|
60
|
+
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
alarmManager.setExact(
|
|
64
|
+
AlarmManager.RTC_WAKEUP,
|
|
65
|
+
calendar.getTimeInMillis(),
|
|
66
|
+
pendingIntent
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
Toast.makeText(this, "Alarm set!", Toast.LENGTH_SHORT).show();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private void cancelAlarm() {
|
|
73
|
+
alarmManager.cancel(pendingIntent);
|
|
74
|
+
Toast.makeText(this, "Alarm cancelled", Toast.LENGTH_SHORT).show();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
package com.example.alertapp;
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle;
|
|
4
|
+
import android.view.View;
|
|
5
|
+
import android.widget.Button;
|
|
6
|
+
import android.widget.EditText;
|
|
7
|
+
import android.widget.Toast;
|
|
8
|
+
|
|
9
|
+
import androidx.activity.EdgeToEdge;
|
|
10
|
+
import androidx.appcompat.app.AlertDialog;
|
|
11
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
12
|
+
import androidx.core.graphics.Insets;
|
|
13
|
+
import androidx.core.view.ViewCompat;
|
|
14
|
+
import androidx.core.view.WindowInsetsCompat;
|
|
15
|
+
|
|
16
|
+
public class MainActivity extends AppCompatActivity {
|
|
17
|
+
Button btn;
|
|
18
|
+
EditText et;
|
|
19
|
+
@Override
|
|
20
|
+
protected void onCreate(Bundle savedInstanceState) {
|
|
21
|
+
super.onCreate(savedInstanceState);
|
|
22
|
+
EdgeToEdge.enable(this);
|
|
23
|
+
setContentView(R.layout.activity_main);
|
|
24
|
+
btn=findViewById(R.id.btn);
|
|
25
|
+
et=findViewById(R.id.et);
|
|
26
|
+
btn.setOnClickListener(v -> showAlert());
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
public void showAlert() {
|
|
30
|
+
String st = et.getText().toString();
|
|
31
|
+
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
|
32
|
+
|
|
33
|
+
builder.setTitle("Alert");
|
|
34
|
+
builder.setMessage(st);
|
|
35
|
+
|
|
36
|
+
builder.setPositiveButton("Yes", (dialog, which) -> {
|
|
37
|
+
Toast.makeText(MainActivity.this,
|
|
38
|
+
"You clicked Yes", Toast.LENGTH_SHORT).show();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
builder.setNegativeButton("No", (dialog, which) -> {
|
|
42
|
+
Toast.makeText(MainActivity.this,
|
|
43
|
+
"You clicked No", Toast.LENGTH_SHORT).show();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
builder.show();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
|
+
|
|
4
|
+
<application
|
|
5
|
+
android:allowBackup="true"
|
|
6
|
+
android:label="Battery Low App"
|
|
7
|
+
android:supportsRtl="true"
|
|
8
|
+
android:theme="@style/Theme.MyApplication">
|
|
9
|
+
|
|
10
|
+
<activity
|
|
11
|
+
android:name=".MainActivity"
|
|
12
|
+
android:exported="true">
|
|
13
|
+
|
|
14
|
+
<intent-filter>
|
|
15
|
+
<action android:name="android.intent.action.MAIN" />
|
|
16
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
17
|
+
</intent-filter>
|
|
18
|
+
|
|
19
|
+
</activity>
|
|
20
|
+
|
|
21
|
+
</application>
|
|
22
|
+
|
|
23
|
+
</manifest>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package com.example.myapp; // Keep your own package name
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.widget.Toast;
|
|
7
|
+
|
|
8
|
+
public class BatteryLowReceiver extends BroadcastReceiver {
|
|
9
|
+
|
|
10
|
+
@Override
|
|
11
|
+
public void onReceive(Context context, Intent intent) {
|
|
12
|
+
|
|
13
|
+
if (Intent.ACTION_BATTERY_LOW.equals(intent.getAction())) {
|
|
14
|
+
Toast.makeText(
|
|
15
|
+
context,
|
|
16
|
+
"Battery is low!",
|
|
17
|
+
Toast.LENGTH_LONG
|
|
18
|
+
).show();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Example: Battery Low
|
|
2
|
+
|
|
3
|
+
Files included:
|
|
4
|
+
- MainActivity.java
|
|
5
|
+
- BatteryLowReceiver.java
|
|
6
|
+
- AndroidManifest.xml
|
|
7
|
+
|
|
8
|
+
These are the source snippets supplied for this example. You may need to add or adapt layout resources, package names, theme names, and manifest entries in Android Studio.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package com.example.myapp; // Keep your own package name
|
|
2
|
+
|
|
3
|
+
import android.content.Intent;
|
|
4
|
+
import android.content.IntentFilter;
|
|
5
|
+
import android.os.Bundle;
|
|
6
|
+
import android.widget.TextView;
|
|
7
|
+
|
|
8
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
9
|
+
|
|
10
|
+
public class MainActivity extends AppCompatActivity {
|
|
11
|
+
|
|
12
|
+
TextView tvStatus;
|
|
13
|
+
BatteryLowReceiver receiver;
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
protected void onCreate(Bundle savedInstanceState) {
|
|
17
|
+
super.onCreate(savedInstanceState);
|
|
18
|
+
setContentView(R.layout.activity_main);
|
|
19
|
+
|
|
20
|
+
tvStatus = findViewById(R.id.tvStatus);
|
|
21
|
+
receiver = new BatteryLowReceiver();
|
|
22
|
+
|
|
23
|
+
IntentFilter filter =
|
|
24
|
+
new IntentFilter(Intent.ACTION_BATTERY_LOW);
|
|
25
|
+
|
|
26
|
+
registerReceiver(receiver, filter);
|
|
27
|
+
|
|
28
|
+
tvStatus.setText("Receiver registered. Waiting for low battery...");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Override
|
|
32
|
+
protected void onDestroy() {
|
|
33
|
+
super.onDestroy();
|
|
34
|
+
unregisterReceiver(receiver);
|
|
35
|
+
}
|
|
36
|
+
}
|