android_app

android app

set up eclipse

  1. Download Android SDK.
    http://developer.android.com/sdk/index.html#ExistingIDE

  2. Insall ADT plugin for Eclipse. http://developer.android.com/sdk/installing/installing-adt.html

First Android app

Add the following into first Android app:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);

    final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    startActivityForResult(intent, 0);

    return true;
}

This example will demonstrate the usage of Storage Access Framework(SAF).
More details, see https://developer.android.com/guide/topics/providers/document-provider.html#client

PreferenceFragment

Create a java class which extends PreferenceFragment,

String resources: valus/strings.xml

Array resources: values/arrays.xml

<string-array name="list_provinces">
    <item >Shang Hai</item>
    <item >Bei Jing</item>
    <item >Hang Zhou</item>
</string-array>

AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="org.cfig.a1.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

application has 1 activity, this activity will be started firstly when enter this app.

create preference screen xml: xml/pref.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:holo="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <PreferenceCategory android:title="Province" >
        <CheckBoxPreference
            android:key="@string/k_province_sh"
            android:summary="City of Magics"
            android:title="Shang Hai" />
        <CheckBoxPreference
            android:key="@string/k_province_bj"
            android:summary="City of Kings"
            android:title="Bei Jing" />

        <SwitchPreference
            android:key="key_switch"
            android:title="Switch" />
    </PreferenceCategory>
    <PreferenceCategory android:title="Select Province" >
        <ListPreference
            android:entries="@array/list_provinces"
            android:entryValues="@array/list_provinces_value"
            android:key="@string/k_province_select"
            android:title="Province" />
    </PreferenceCategory>

    <Preference android:key="k_a" android:title="Start PowerSettings" >
        <intent android:action="org.cfig.powersettings.POWER_SETTING" />
    </Preference>

</PreferenceScreen>

BOOT_COMPLETED receiver

Eclipse for platform development

http://source.android.com/source/using-eclipse.html

Intent fullscreenIntent = new Intent(this, FullscreenActivity.class);
mContext.startActivity(fullscreenIntent);