2011年2月10日星期四

對應Android 2.3.3的Android SDK現已推出

對應Android 2.3.3的Android SDK為開發人員增加了新的NFC(Near Field Communications近場通信)功能, 如寫入, 標籤,並建立點對點連接.

新的API可以啟用令人興奮的新應用, 如票務, 評分, 簽入, 廣告和其與他設備交換數據.

詳情:
http://android-developers.blogspot.com/2011/02/android-233-platform-new-nfc.html

2011年2月9日星期三

Android的共享選項編輯器(SharedPreferences.Editor)

共享選項編輯器(SharedPreferences.Editor)是一個用於修改SharedPreferences對象值的接口. 編輯選項值後, 調用commit()或apply()方法以更新SharedPreferences.

Android的共享選項編輯器(SharedPreferences.Editor)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<CheckBox
android:id="@+id/pref_checkbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/pref_edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/saveedittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Save EditText"
/>
</LinearLayout>


package com.AndroidSharedPreferencesEditor;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;

public class AndroidSharedPreferencesEditor extends Activity {

CheckBox checkBox;
EditText editText;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
checkBox = (CheckBox)findViewById(R.id.pref_checkbox);
editText = (EditText)findViewById(R.id.pref_edittext);
Button buttonSaveEditText = (Button)findViewById(R.id.saveedittext);
LoadPreferences();

checkBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){

@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
SavePref();
}});

buttonSaveEditText.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
SavePref();
}});

}

private void LoadPreferences(){
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);

boolean savedBoolean = sharedPreferences.getBoolean("PREF_BOOLEAN", false);
String savedString = sharedPreferences.getString("PREF_STRING", "");

checkBox.setChecked(savedBoolean);
editText.setText(savedString);
}

private void SavePref(){
boolean booleanCheckBox = checkBox.isChecked();
String stringEditText = editText.getText().toString();

SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("PREF_BOOLEAN", booleanCheckBox);
editor.putString("PREF_STRING", stringEditText);
editor.commit();
}
}



相關文章:
- getPreferences() vs getSharedPreferences()

2011年2月7日星期一

對話框樣式的應用程序

一般來講, 應用程序或活動覆蓋整個屏幕. 但是可以通過android:theme, 使應用程序看起來像對話框, 就像一個浮動窗口一樣.

對話框樣式的應用程序

只需要修改AndroidManifest.xml, 在<activity>添加:
android:theme="@android:style/Theme.Dialog"

例子:
<activity android:name=".AndroidDialogTheme"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog">


2011年2月4日星期五

通過android.os.Build和System.getProperty()獲取系統信息(SysInfo)

HTC Wildfire的系統信息(SysInfo)

佈局文件, main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="android.os.Build"
android:background="#505050"
/>
<TextView
android:id="@+id/device"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/model"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/product"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="android.os.Build.VERSION"
android:background="#505050"
/>
<TextView
android:id="@+id/codename"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/incremental"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/release"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/sdk"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/sdk_int"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="System.getProperty()"
android:background="#505050"
/>
<TextView
android:id="@+id/os_arch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/os_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/os_version"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>


程序代碼
package com.AndroidSysInfo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidSysInfo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textDevice = (TextView)findViewById(R.id.device);
TextView textModel = (TextView)findViewById(R.id.model);
TextView textProduct = (TextView)findViewById(R.id.product);

TextView textCodename = (TextView)findViewById(R.id.codename);
TextView textIncremental = (TextView)findViewById(R.id.incremental);
TextView textRelease = (TextView)findViewById(R.id.release);
TextView textSdk = (TextView)findViewById(R.id.sdk);
TextView textSdkInt = (TextView)findViewById(R.id.sdk_int);

TextView textOS_Arch = (TextView)findViewById(R.id.os_arch);
TextView textOS_Name = (TextView)findViewById(R.id.os_name);
TextView textOS_Version = (TextView)findViewById(R.id.os_version);

textDevice.setText(".DEVICE: " + android.os.Build.DEVICE);
textModel.setText(".MODEL: " + android.os.Build.MODEL);
textProduct.setText(".PRODUCT: " + android.os.Build.PRODUCT);

textCodename.setText(".CODENAME: " + android.os.Build.VERSION.CODENAME);
textIncremental.setText(".INCREMENTAL: " + android.os.Build.VERSION.INCREMENTAL);
textRelease.setText(".RELEASE: " + android.os.Build.VERSION.RELEASE);
textSdk.setText(".SDK: " + android.os.Build.VERSION.SDK);
textSdkInt.setText(".SDK_INT: " + String.valueOf(android.os.Build.VERSION.SDK_INT));

textOS_Arch.setText("os.arch: " + System.getProperty("os.arch"));
textOS_Name.setText("os.name: " + System.getProperty("os.name"));
textOS_Version.setText("os.version: " + System.getProperty("os.version"));
}
}


Android Event 02-02-2011全程播



2011年2月3日星期四

谷歌宣布Android市場網站

谷歌推出了Android市場網站(http://market.android.com/),讓你直接從瀏覽器瀏覽和搜索Android應用程序。

Android Market的網站內,可以直接發送應用程序到你的Android設備,與朋友通過Twitter分享應用程序。亦可以從網站或從Android設備直接閱讀和發布應用程序評論。

另外, 到網站使用谷歌帳戶登錄, 並點擊"My Market Account"可以看到你所購買或下載的應用程序,使管理應用程序非常容易。

2011年2月1日星期二

利用剪貼板管理器(ClipboardManager)執行複製和粘貼(Copy and Paste)

剪貼板管理器(ClipboardManager)是一個剪貼板服務的接口, 用於在剪貼板放置和檢索文本.

從系統獲取剪貼板管理器:

ClipboardManager clipboardManager
= (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);


在剪貼板放置文本:

clipboardManager.setText("Text place in ClipboardManager");


在剪貼板檢索文本:

clipboardManager.getText();