intent(インテント)の受け取り方

基本ですが。

明示的

Intentチュートリアル 

intentを受け取る側はActivityクラスのgetIntentメソッドを使用すれば良い。
また、intentに付加情報が設定されている場合はget〜Extraメソッドを使えば
取り出すことができる。
// キーを使ってパラメータを取得
final String var = intent.getStringExtra("com.suddenAngerSystem.displayString");
text.setText(var);


Intentを使って画面を遷移する(明示的Intent) « Tech Booster 

Intentはthis.getIntent()メソッドで受け取ります。
ただし、IntentによらないでsubActivityが起動した場合、
nullとなります。受け取り処理はnullチェックを入れるなど、
値に注意して下さい。
Intent intent = getIntent();
if (intent != null) {
    String str = intent.getStringExtra("org.jpn.techbooster.demo.intent.testString");
    Toast.makeText(this, str, Toast.LENGTH_LONG).show();
}

暗黙的

気になってたのはここ。送り側は、こちら

Intent.ACTION_SENDで他のアプリケーションと連携する | Tech Booster 

getIntentでIntentを取得します。Intentが通常の起動(android.intent.action.MAIN)
ではなくACTION_SENDだった場合にだけgetExtrasでBundleを取得して文字列を取り出します。
Intent intent = getIntent();
String action = intent.getAction();
if (Intent.ACTION_SEND.equals(action)) {
  Bundle extras = intent.getExtras();
  if (extras != null) {
    CharSequence ext = extras.getCharSequence(Intent.EXTRA_TEXT);
      if (ext != null) {
        editText_.setText(ext);
  }
}


ボコ:【android開発】電池残量を取得する方法 開発02 インテントを受け取る 

AndroidManifest.xmlをいじらずに済む。

	@Override
	protected void onResume() {
		super.onResume();
		//受信を開始
		IntentFilter filter=new IntentFilter();
		filter.addAction(Intent.ACTION_BATTERY_CHANGED);
		registerReceiver(myReceiver,filter);
	}
	//受信機
	public BroadcastReceiver myReceiver = new BroadcastReceiver() {
		private int scale;
		private int level;

		@Override
		public void onReceive(Context context, Intent intent) {
			if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
				// 電池残量の最大値
				scale = intent.getIntExtra("scale", 0);
				// 電池残量
				level = intent.getIntExtra("level", 0);
			}
		}
	};

すこしいろいろ

Intent | Android Developers 

ネットワークの状態を調べる

このへんか。

NetworkInfoを使って、通信接続が可能状態か知る « Tech Booster 

パーミッション

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

ソース

すこし手を入れながら理解する。

public class MainSample extends Activity implements OnClickListener {
    ConnectivityManager cm;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        Button bt = (Button) findViewById(R.id.checkbutton);
        bt.setOnClickListener(this);
    }
 
    @Override
    public void onClick(View v) {
        NetworkInfo nInfo = cm.getActiveNetworkInfo();
        if (nInfo != null && nInfo.isConnected()) {
            appearToast(nInfo.getTypeName() + " Network connected");
        } else {
            appearToast("No Network Connection!");
        }
    }

    private void function appearToast(String message) {
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }

}

NetworkInfo | Android Developers 

コードを探す。


how to see if wifi is connected in android - Stack Overflow 

android.net.wifi.WifiManager m = (WifiManager) getSystemService(WIFI_SERVICE);
android.net.wifi.SupplicantState s = m.getConnectionInfo().getSupplicantState();
NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(s);
if( state != NetworkInfo.DetailedState.CONNECTED ){
    return false;
}
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

if (mWifi.isConnected()) {
    // Do whatever
}

Wi-Fiの状態は細かく取れる。

SupplicantState supState; 
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
supState = wifiInfo.getSupplicantState();
AUTHENTICATING Network link established, performing authentication.
BLOCKED Access to this network is blocked.
CONNECTED IP traffic should be available.
CONNECTING Currently setting up data connection.
DISCONNECTED IP traffic not available.
DISCONNECTING Currently tearing down data connection.
FAILED Attempt to connect failed.
IDLE Ready to start data connection setup.
OBTAINING_IPADDR Awaiting response from DHCP server in order to assign IP address information.
SCANNING Searching for an available access point.
SUSPENDED IP traffic is suspended

Androidが通信可能かどうか」を取りたいので、

        cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo nInfo = cm.getActiveNetworkInfo();
        if (nInfo != null && nInfo.isConnected()) {
            appearToast(nInfo.getTypeName() + " Network connected");
        } else {

結局ここらか。

ConnectivityManager

このクラスでネットワーク周りを操作。

ConnectivityManager | Android Developers 

EclipseのプロジェクトにXでエラーが出てビルドできない

謎のエラーで。

Error generating final archive: Debug certificate expired on ...

結局、debug.keystoreを削除すればそれで終わる。

I can't compile my app because the build tools generated an expired debug certificate 

GALAXY NEXUS(GSM)をSuperbootで5行でroot化

バージョンが新しくなっている。

01 Feb r4: Superboot - rooting the GSM + LTE Galaxy Nexus - Android @ MoDaCo 

fastbootモード(VOLUMEUP+DOWN+POWERON)でUSBで接続したPCから5行のコマンド実行で終わる。

wget http://loadbalancing.modaco.com/download.php?file=r4-galaxynexus-gsm-superboot.zip
unzip r4-galaxynexus-gsm-superboot.zip
cd r4-galaxynexus-gsm-superboot
./fastboot-linux oem unlock
./install-superboot-linux.sh

アーカイブ内一覧。

~/r4-galaxynexus-gsm-superboot$ ls
AdbWinApi.dll     adb-windows.exe     fastboot-windows.exe
AdbWinUsbApi.dll  boot.superboot.img  install-superboot-linux.sh
adb-linux         fastboot-linux      install-superboot-mac.sh
adb-mac           fastboot-mac        install-superboot-windows.bat

AWS EBSボリュームを増量する

気がついたら100%で増量しなければならなくなった。
それが、簡単にできる。

EBS-backedインスタンスのrootボリュームをサイズ増量 | koba206の開発WIKI 

すべては、コマンドラインの手順を書かれていますが、
ブラウザコンソールからも簡単にGUI操作で可能。

手順

  1. 起動中のインスタンスを止める。
  2. EBSボリュームをインスタンスから切り離す(デタッチ)する。
  3. EBSボリュームのスナップショットをつくる。
  4. ボリュームを増量したサイズの30GBとスナップショットを指定してつくる。
  5. 作成したボリュームを/dev/sda1につなぐ(アタッチ)する。
  6. インスタンスを起動する。
  7. グローバルなIPと切れているのでつなぐ。
  8. リサイズして、30GBに。
# df -h
Filesystem            Size  Used Avail Use% マウント位置
/dev/xvda1            6.0G  1.6G  4.1G  28% /
none                  837M     0  837M   0% /dev/shm

# resize2fs /dev/xvda1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/xvda1 to 7864320 (4k) blocks.
The filesystem on /dev/xvda1 is now 7864320 blocks long.

# df -h
Filesystem            Size  Used Avail Use% マウント位置
/dev/xvda1             30G  1.6G   27G   6% /
none                  837M     0  837M   0% /dev/shm

ボリュームとインスタンスをアタッチするとき、/dev/xvda1 がないといわれたので
/dev/sda1 につないだのだが、これいかに。

有名日本語IMEの辞書ファイルの形式と場所

エキスポート、インポート時のテキスト形式と場所
まとめておくと、よく使う単語の辞書をPC上で作成編集可能になる。
日本語で「あか」からの変換で各メールアドレスやアカウントに変換。

Simeji

/sdcard/Simeji/simeji_user_dic.txt
JSON形式

{"EN_KEY":[],"EN_VALUE":[],"JAJP_VALUE":["aaa@hotmail.com","bbb@gmail.com","ccc@gmail.com"],"JAJP_KEY":["あか","あか","あか"]}

OpenWnn

(そのうち)