四国GTUG の宣伝をお願いします。
個々のライセンスの調査
C. LICENSE TO DISTRIBUTE SOFTWARE. Subject to the terms and conditions of this Agreement and restrictions and exceptions set forth in the README File, including, but not limited to the Java Technology Restrictions and Limitations on Redistribution of these Supplemental Terms, Oracle grants you a non-exclusive, non-transferable, limited license without fees to reproduce and distribute the Software, provided that (i) you distribute the Software complete and unmodified and only bundled as part of, and for the sole purpose of running, your Programs, (ii) the Programs add significant and primary functionality to the Software, (iii) you do not distribute additional software intended to replace any component(s) of the Software, (iv) you do not remove or alter any proprietary legends or notices contained in the Software, (v) you only distribute the Software subject to a license agreement that: (a) is a complete, unmodified reproduction of this Agreement; or (b) protects Oracle's interests consistent with the terms contained in this Agreement and that includes the notice set forth in Section H, and (vi) you agree to defend and indemnify Oracle and its licensors from and against any damages, costs, liabilities, settlement amounts and/or expenses (including attorneys' fees) incurred in connection with any claim, lawsuit or action by any third party that arises or results from the use or distribution of any and all Programs and/or Software. The license set forth in this Section C does not extend to the Software identified in Section G. D. LICENSE TO DISTRIBUTE REDISTRIBUTABLES. Subject to the terms and conditions of this Agreement and restrictions and exceptions set forth in the README File, including but not limited to the Java Technology Restrictions and Limitations on Redistribution of these Supplemental Terms, Oracle grants you a non-exclusive, non-transferable, limited license without fees to reproduce and distribute those files specifically identified as redistributable in the README File ("Redistributables") provided that: (i) you distribute the Redistributables complete and unmodified, and only bundled as part of Programs, (ii) the Programs add significant and primary functionality to the Redistributables, (iii) you do not distribute additional software intended to supersede any component(s) of the Redistributables (unless otherwise specified in the applicable README File), (iv) you do not remove or alter any proprietary legends or notices contained in or on the Redistributables, (v) you only distribute the Redistributables pursuant to a license agreement that: (a) is a complete, unmodified reproduction of this Agreement; or (b) protects Oracle's interests consistent with the terms contained in the Agreement and includes the notice set forth in Section H, (vi) you agree to defend and indemnify Oracle and its licensors from and against any damages, costs, liabilities, settlement amounts and/or expenses (including attorneys' fees) incurred in connection with any claim, lawsuit or action by any third party that arises or results from the use or distribution of any and all Programs and/or Software. The license set forth in this Section D does not extend to the Software identified in Section G.
Windowsの場合 マウント Portable WinCDEmuをダウンロードしてください
英語の方が使いやすい
自分の手持ちのドライバはぐぐってください。ADBドライバーという名前でぐぐってください。 googleドライバーというのはisoファイルの中に入っているので入れるときに聞かれたらそれを使って下さい
ダブルクリックで実行 最初にワークスペースの設定 自分のファイルシステム上で書き込みしていいところを指定する
Window-Android SDK Manager Android 2.2を選択
import android.widget.Button;が増えるのでエラーが出なくなる
button.setOnClickListener(new OnClickListener() { public void onClick(View v) { Toast.makeText(HelloWorldActivity.this, "Hello!", Toast.LENGTH_LONG).show(); } });
res-values-strings.xmlをディレクトリごとコピー valuesとvalues-jaとの二つにする。 values-ja/strings.xmlを日本語に書き換える
Toast行を以下に入れ替え
new Thread() { @Override public void run() { try{ Thread.sleep(10 * 1000); } catch (InterruptedException e){ e.printStackTrace(); } handler.post(new Runnable(){ public void run() { Toast.makeText(HelloWorldActivity.this,"Hello!", Toast.LENGTH_LONG).show(); } }); }}.start();
ハンドラを作っておく
public class HelloPADE2Activity extends Activity {
の下に一行追加
private Handler handler = new Handler();
Ctl+Shift+Oでimportを増やしておく
public class HelloPADEActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button)findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { // new Thread() { // @Override // public void run() { // Log.v("hello", "Error"); // try { // new NumberFormatException(); // Thread.sleep(10 * 1000); // } catch (InterruptedException e) { // e.printStackTrace(); // } // handler.post(new Rnnable() { // public void run() { // Toast.makeText(HelloWorldActivity.this, // "Hello!", Toast.LENGTH_LOGNG).show(); // } // }); // } // }.start(); EditText text = (EditText) findViewById(R.id.editText1); String value = text.getText().toString(); Intent intent = new Intent(HelloWorldActivity.this, SecondActivity.class); intent.putExtra("text",value); startActivityForResult(intent, 0); } }); } @Override protected void on ActibityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 0 && resultCode ==1) { String value = data.getExtras().getString("result"); Toast.makeText(this, value, Toast.LENGTH_LONG).show(); } } }
package jp.cane.android.sweet; import android.app.Activityl import android.content.Intent; import android.os.Bundle; public class SecondActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); Intent intent = getIntent(); String value = intent.getExtras().getString("text"); // Toast.makeText(this,value,Toast.LENGTH_LONG.show(); value = "こんにちは、" + value; Intent data = new Intent(); data.putExtra("result",value); setResult(1); finish(); } }
package jp.cane.android.sweet; import android.app.Activityl import android.content.Intent; import android.os.Bundle; public class SecondActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); Intent intent = getIntent(); String value = intent.getExtras().getString("text"); // Toast.makeText(this,value,Toast.LENGTH_LONG.show(); value = "こんにちは、" + value; Intent data = new Intent(); data.putExtra("result",value); setResult(1); finish(); } }
New-classで、MainService?.java できたらextendedのサービスを追加 を以下のように作る package jp.cone.android.sweet;{
import android.app.Service; import android.content.Intent; import android.os.IBinder;
public class MainService extends Service { @Override public void onCreate() super.onCreate(); } @Override public IBinder onBind(Intent intent) { return null; } }
その次に、以下のように拡張する
public class MainService extends Service implements Runnable { private Handler handler = new Handler(); @Override public void onCreate() super.onCreate(); new Thread(this).start(); } @Override public IBinder onBind(Intent intent) { return null; } public void run() { while (true) { try { Thread.sleep(3 * 1000); } catch (InterruptedException e) { e.printStackTrace(); } handler.post(new Runnable() { public void run() { Toast.makeText(MainService.this, "Hello", Toast.LENGTH_LONG).show(); } }); } } }
このサービスは問題があって、AndroidOSから勝手にkillされる。それを防ぐためにはstartforgroundとかをやると終了されなくなる。
MainService?.javaを書き換え
public void run() { handler.post(new Runnable() { public void run() { adapter = BluetoothAdapter.getDefaultAdapter(); } }); while (adapter == null) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } while (true) // try { // Tread.sleep(3 * 1000); // } catch (InterruptedException e) { // e.printStackTrace(); // } // handler.post(new Runnable() { // public void run() { // Toast.makeText(MainService.this, "Hello", Toast.LENGTH_LONG).show(); // } // }); try { BluetoothSocket socket; if (true) { // server BluetoothServerSocket ssocket = adapter .listenUsingRfcommWithServiceRecord("BTChat", UUID.fromString(UI_MODE_SERVICE)); socket = ssocket.accept(); } else { // client socket = adapter.getRemoteDevice("00:11:22:33:44:55") .createRfcommSockeToServiceRecord( UUID.fromString(UI_MODE_SERVICE)); socket.connect(); } // if server , move below one line to "point B". socket.getOutputStream().write("hogehoge\n".getBytes());
InputStream is = socket.getInputStream(); BufferedReader reader = new BufferdReader( new InputStreamReader(is)); final String line = reader.readLine(); handler.post(new Runnable() { public void run() { Toast.makeText(MainService.this, line, Toast.LENGTH_LONG).show(); } });
// point B } catch (IOException e) { // TODO Auto-genereted catch block e.printStackTrace }
パーミッションを追加する必要がある res-AndroidManifest?.xmlのAndroid Manifest Permissionsでon.BLUETOOTH
on.BLUETOOTH_ADMIN
アクティビティを追加する度に