android
Purpose
This skill equips the AI to handle core Android development tasks, including SDK setup, managing activity and fragment lifecycles, implementing the permissions model, applying Material Design principles, and preparing apps for Google Play Store distribution. It focuses on practical implementation for efficient app building.
When to Use
Use this skill for Android app development scenarios, such as initializing projects with SDK tools, debugging lifecycle events (e.g., onPause or onDestroy), requesting runtime permissions, designing responsive UIs with Material components, or automating Play Store uploads. Apply it when working on mobile apps in the "mobile" cluster, especially for Google ecosystem integrations.
Key Capabilities
- Set up Android SDK: Download and configure via SDK Manager with commands like
sdkmanager --list to view packages.
- Manage activity/fragment lifecycles: Implement methods like onCreate() for activities or onViewCreated() for fragments to handle state changes.
- Handle permissions model: Use runtime checks with ContextCompat.checkSelfPermission() and request via ActivityCompat.requestPermissions().
- Apply Material Design: Integrate components like MaterialButton or BottomNavigationView from the Material library.
- Manage Play Store: Prepare app bundles and use Google Play Console API for uploads, requiring authentication with $GOOGLE_API_KEY.
Usage Patterns
To set up a new Android project:
- Use Android Studio or CLI: Run
gradle init --type android-library to create a basic project.
- Add dependencies in build.gradle: e.g., implementation 'com.android.support:appcompat-v7:28.0.0'.
For handling fragment lifecycles:
- Extend Fragment and override onCreateView() to inflate layouts.
- Use getActivity() in fragments to access activity context for permission requests.
When requesting permissions:
- Check status first: If not granted, call requestPermissions() with a request code.
- Handle results in onRequestPermissionsResult() to proceed or show errors.
For Material Design: Wrap layouts with CoordinatorLayout and add behaviors like app:layout_behavior="@string/appbar_scrolling_view_behavior".
Common Commands/API
- CLI Commands: Use
adb devices to list devices; adb logcat with flags like -s MyApp for filtered logs; sdkmanager --install "build-tools;30.0.3" to install specific SDK components.
- API Endpoints: For Play Store, use Google Play Developer API (e.g., POST to https://www.googleapis.com/androidpublisher/v3/applications/{packageName}/edits with $GOOGLE_API_KEY in headers).
- Code Snippets:
- Activity lifecycle example:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
- Permissions request:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
- Material Design component:
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
- Fragment lifecycle:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize views here
}
Integration Notes
Integrate Android SDK by setting environment variables: export ANDROID_HOME=/path/to/sdk and add to PATH. For Google services, include Google Play Services in build.gradle: implementation 'com.google.android.gms:play-services-auth:20.1.0' and use $GOOGLE_API_KEY for API calls (e.g., in HTTP requests: Authorization: Bearer $GOOGLE_API_KEY). When combining with other skills, ensure compatibility: For mobile cluster integrations, align with iOS skill for cross-platform configs; use JSON config files like {"apiKey": "$GOOGLE_API_KEY"} for Play Store automation scripts.
Error Handling
Handle permission errors by checking results in onRequestPermissionsResult(): If request is denied, log with Log.e("Permission", "Denied") and prompt user via AlertDialog. For lifecycle issues (e.g., NullPointerException in onDestroy), use try-catch blocks around resource releases. Common SDK errors: If sdkmanager fails, verify internet connectivity or use --verbose flag for details. For Play Store API, catch HttpException for 401 errors by re-authenticating with $GOOGLE_API_KEY. Always wrap API calls in try { ... } catch (Exception e) { Log.d("Error", e.getMessage()); }.
Concrete Usage Examples
Implementing an activity with permission check:
Create an activity to request camera access:
public class CameraActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 100);
}
}
}
Then build and run: ./gradlew assembleDebug && adb install app/build/outputs/apk/debug/app-debug.apk.
Using Material Design for a login screen:
Design a fragment with Material components:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:hint="Username" />
</com.google.android.material.textfield.TextInputLayout>
In the fragment: Override onCreateView() to inflate and handle user input, ensuring compatibility with activity lifecycle.
Graph Relationships
- Related to cluster: mobile (shares mobile development concepts).
- Connected to skills: ios (for cross-platform mobile strategies), google (via shared tags like "google" for ecosystem tools).
- Links: sdk (direct overlap in Android SDK usage), permissions (common with web skills for access control).
1---2name: android-23description: Android root: SDK, activity/fragment lifecycle, permissions model, Material Design, Play Store4---5
6# android
7
8## Purpose
9This skill equips the AI to handle core Android development tasks, including SDK setup, managing activity and fragment lifecycles, implementing the permissions model, applying Material Design principles, and preparing apps for Google Play Store distribution. It focuses on practical implementation for efficient app building.
10
11## When to Use
12Use this skill for Android app development scenarios, such as initializing projects with SDK tools, debugging lifecycle events (e.g., onPause or onDestroy), requesting runtime permissions, designing responsive UIs with Material components, or automating Play Store uploads. Apply it when working on mobile apps in the "mobile" cluster, especially for Google ecosystem integrations.
13
14## Key Capabilities
15- Set up Android SDK: Download and configure via SDK Manager with commands like `sdkmanager --list` to view packages.
16- Manage activity/fragment lifecycles: Implement methods like onCreate() for activities or onViewCreated() for fragments to handle state changes.
17- Handle permissions model: Use runtime checks with ContextCompat.checkSelfPermission() and request via ActivityCompat.requestPermissions().
18- Apply Material Design: Integrate components like MaterialButton or BottomNavigationView from the Material library.
19- Manage Play Store: Prepare app bundles and use Google Play Console API for uploads, requiring authentication with $GOOGLE_API_KEY.
20
21## Usage Patterns
22To set up a new Android project:
231. Use Android Studio or CLI: Run `gradle init --type android-library` to create a basic project.
242. Add dependencies in build.gradle: e.g., implementation 'com.android.support:appcompat-v7:28.0.0'.
25For handling fragment lifecycles:
261. Extend Fragment and override onCreateView() to inflate layouts.
272. Use getActivity() in fragments to access activity context for permission requests.
28When requesting permissions:
291. Check status first: If not granted, call requestPermissions() with a request code.
302. Handle results in onRequestPermissionsResult() to proceed or show errors.
31For Material Design: Wrap layouts with CoordinatorLayout and add behaviors like app:layout_behavior="@string/appbar_scrolling_view_behavior".
32
33## Common Commands/API
34- CLI Commands: Use `adb devices` to list devices; `adb logcat` with flags like `-s MyApp` for filtered logs; `sdkmanager --install "build-tools;30.0.3"` to install specific SDK components.
35- API Endpoints: For Play Store, use Google Play Developer API (e.g., POST to https://www.googleapis.com/androidpublisher/v3/applications/{packageName}/edits with $GOOGLE_API_KEY in headers).
36- Code Snippets:
37 - Activity lifecycle example:
38 ```java
39 @Override
40 protected void onCreate(Bundle savedInstanceState) {
41 super.onCreate(savedInstanceState);
42 setContentView(R.layout.activity_main);
43 }
44 ```
45 - Permissions request:
46 ```java
47 if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
48 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
49 }
50 ```
51 - Material Design component:
52 ```xml
53 <com.google.android.material.button.MaterialButton
54 android:layout_width="wrap_content"
55 android:layout_height="wrap_content"
56 android:text="Click Me" />
57 ```
58 - Fragment lifecycle:
59 ```java
60 @Override
61 public void onViewCreated(View view, Bundle savedInstanceState) {
62 super.onViewCreated(view, savedInstanceState);
63 // Initialize views here
64 }
65 ```
66
67## Integration Notes
68Integrate Android SDK by setting environment variables: export ANDROID_HOME=/path/to/sdk and add to PATH. For Google services, include Google Play Services in build.gradle: implementation 'com.google.android.gms:play-services-auth:20.1.0' and use $GOOGLE_API_KEY for API calls (e.g., in HTTP requests: Authorization: Bearer $GOOGLE_API_KEY). When combining with other skills, ensure compatibility: For mobile cluster integrations, align with iOS skill for cross-platform configs; use JSON config files like {"apiKey": "$GOOGLE_API_KEY"} for Play Store automation scripts.
69
70## Error Handling
71Handle permission errors by checking results in onRequestPermissionsResult(): If request is denied, log with Log.e("Permission", "Denied") and prompt user via AlertDialog. For lifecycle issues (e.g., NullPointerException in onDestroy), use try-catch blocks around resource releases. Common SDK errors: If `sdkmanager` fails, verify internet connectivity or use --verbose flag for details. For Play Store API, catch HttpException for 401 errors by re-authenticating with $GOOGLE_API_KEY. Always wrap API calls in try { ... } catch (Exception e) { Log.d("Error", e.getMessage()); }.
72
73## Concrete Usage Examples
741. **Implementing an activity with permission check:**
75 Create an activity to request camera access:
76 ```java
77 public class CameraActivity extends AppCompatActivity {
78 @Override
79 protected void onCreate(Bundle savedInstanceState) {
80 super.onCreate(savedInstanceState);
81 setContentView(R.layout.activity_camera);
82 if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
83 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 100);
84 }
85 }
86 }
87 ```
88 Then build and run: `./gradlew assembleDebug && adb install app/build/outputs/apk/debug/app-debug.apk`.
89
902. **Using Material Design for a login screen:**
91 Design a fragment with Material components:
92 ```xml
93 <com.google.android.material.textfield.TextInputLayout
94 android:layout_width="match_parent"
95 android:layout_height="wrap_content">
96 <com.google.android.material.textfield.TextInputEditText
97 android:hint="Username" />
98 </com.google.android.material.textfield.TextInputLayout>
99 ```
100 In the fragment: Override onCreateView() to inflate and handle user input, ensuring compatibility with activity lifecycle.
101
102## Graph Relationships
103- Related to cluster: mobile (shares mobile development concepts).
104- Connected to skills: ios (for cross-platform mobile strategies), google (via shared tags like "google" for ecosystem tools).
105- Links: sdk (direct overlap in Android SDK usage), permissions (common with web skills for access control).