screen 這個就可以解決我們的問題
cd /usr/ports/sysutils/screen; make install clean
String ServerAddress = "http://192.168.0.1";
String DataA = "1"; String DataB = "2";
String result = "";
List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("AA",DataA )); params.add(new BasicNameValuePair("BB",DataB )); HttpPost httpRequest = new HttpPost(ServerAddress); try { httpRequest.setEntity(new UrlEncodedFormEntity(getParams(),HTTP.UTF_8)); HttpResponse mHttpResponse = new DefaultHttpClient().execute(httpRequest); if(mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK){ result = EntityUtils.toString(mHttpResponse.getEntity()); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
params.add(new BasicNameValuePair("AA",DataA ));
if(mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK){ result = EntityUtils.toString(mHttpResponse.getEntity()); }
public static String md5Encode(String str) { StringBuffer buf = new StringBuffer(); try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(str.getBytes()); byte bytes[] = md5.digest(); for(int i = 0; i < bytes.length; i++) { String s = Integer.toHexString(bytes[i] & 0xff); if(s.length()==1) { buf.append("0"); } buf.append(s); } } catch(Exception ex) { } return buf.toString(); }
//將資料寫入JSONArray JSONArray result = new JSONArray(json_data); //取出陣列內所有物件 for(int i = 0;i < result.length(); i++) { //取出JSON物件 JSONObject stock_data = result.getJSONObject(i); //取得物件內資料 System.out.println("t:"+stock_data.getString("t")); System.out.println("l_cur:"+stock_data.getString("l_cur")); System.out.println("c:"+stock_data.getString("c")); System.out.println("cp:"+stock_data.getString("cp")); }
TextView textview = (TextView) findViewById(R.id.textview1); Paint paint = textview.getPaint(); paint.setFlags(Paint.STRIKE_THRU_TEXT_FLAG); paint.setAntiAlias(true);
TextView textview = (TextView) findViewById(R.id.textview1); Paint paint = textview.getPaint(); paint.setFlags(Paint.ANTI_ALIAS_FLAG); paint.setAntiAlias(true);
public void UploadFiles(String PathFile) { new Thread() { @Override public void run() { super.run(); List< NameValuePair> params = new ArrayList< NameValuePair>(); params.add(new BasicNameValuePair("file",PathFile)); HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("Server Address/update.php"); try{ //setup multipart entity MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); for(int i=0;i< params.size();i++){ //identify param type by Key if(params.get(i).getName().equals("file")){ File f = new File(params.get(i).getValue()); FileBody fileBody = new FileBody(f); entity.addPart("image"+i,fileBody); }else{ entity.addPart(params.get(i).getName(),new StringBody(params.get(i).getValue())); } } post.setEntity(entity); //create response handler ResponseHandler< String> handler = new BasicResponseHandler(); //execute and get response UploadFilesResponse = new String(client.execute(post,handler).getBytes(),HTTP.UTF_8); if(D) Log.e(TAG, "--- response ---"+ UploadFilesResponse); }catch(Exception e){ e.printStackTrace(); } } }.start(); }
<?php if(move_uploaded_file($_FILES['image0']['tmp_name'], "./ImageFiles/".$_FILES['image0']['name'])){ echo "uploaded"; }else{ echo "unsuccessfully"; } ?>
<!-- Camera --> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" />
//設定檔名 File tmpFile = new File( Environment.getExternalStorageDirectory(), "image.jpg"); Uri outputFileUri = Uri.fromFile(tmpFile); Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); //利用intent去開啟android本身的照相介面 intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(intent, 0);
new File( 路徑, 檔名)
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(D) Log.e(TAG, "--- onActivityResult ---"); if (resultCode == RESULT_OK) { String img_address = Environment.getExternalStorageDirectory()+"image.jpg"; Bitmap bmp = BitmapFactory.decodeFile(img_address); //利用BitmapFactory去取得剛剛拍照的圖像 ImageView ivTest = (ImageView)findViewById(R.id.imageView1); ivTest.setImageBitmap(bmp); } }
public static String getHtmlContent(final String url) { String result=""; HttpGet httpRequest = new HttpGet(url); HttpClient httpclient = new DefaultHttpClient(); try { HttpResponse httpResponse = httpclient.execute(httpRequest); if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { result = EntityUtils.toString(httpResponse.getEntity()); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
public static String postData(String url, List<NameValuePair> params) { String result=""; HttpPost httpRequest = new HttpPost(url); try { httpRequest.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8)); HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); if(httpResponse.getStatusLine().getStatusCode() == 200){ result = EntityUtils.toString(httpResponse.getEntity()); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
List<NameValuePair> params= new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("data","1234567")); params.add(new BasicNameValuePair("data1","000000")); postData("http://iccl.nkmu.edu.tw/WSN/getData.php", params)
$c2dm = new c2dm($useremail ,$useremail_passwd , $long_registration_id);
$c2dm->sendMessage(1,"Hello World!!");
'data.message' => $message //TODO: Add your data here.
<!-- Only this application can receive the messages and registration result --> <permission android:name="com.example.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.myapp.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive message --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- Send the registration id to the server --> <uses-permission android:name="android.permission.INTERNET" />
<service android:name=".C2DMReceiver" />
<!-- Only C2DM servers can send messages for the app. If permission is not set - any other app can generate it --> <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <!-- Receive the actual message --> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.example.myapp" /> </intent-filter> <!-- Receive the registration id --> <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.example.myapp" /> </intent-filter> </receiver>
package your.package; import java.io.IOException; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import com.google.android.c2dm.C2DMBaseReceiver; public class C2DMReceiver extends C2DMBaseReceiver{ private static final String TAG="C2DMReceiver"; public C2DMReceiver() { super(C2DMActivity.SENDER_ID); } public C2DMReceiver(String senderId) { super(senderId); // TODO Auto-generated constructor stub } @Override protected void onMessage(Context context, Intent intent) { // TODO Auto-generated method stub Log.v(TAG, "C2DMReceiver message"); } } @Override public void onError(Context context, String errorId) { // TODO Auto-generated method stub Log.v(TAG, "C2DMReceiver error"); } @Override public void onRegistered(Context context, String registrationId) throws IOException { // TODO Auto-generated method stub super.onRegistered(context, registrationId); Log.v(TAG, "C2DMReceiver Register:"+registrationId); } @Override public void onUnregistered(Context context) { // TODO Auto-generated method stub super.onUnregistered(context); Log.v(TAG, "C2DMReceiver UnRegister"); } }
@Override protected void onMessage(Context context, Intent intent) { // TODO Auto-generated method stub Log.v(TAG, "C2DMReceiver message"); Bundle extras = intent.getExtras(); if(extras!=null){ String msg = (String)extras.get(C2DMActivity.MESSAGE_KEY_ONE); Log.v(TAG, "The received msg = "+msg); NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher, msg, System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, C2DMActivity.class), 0); notification.setLatestEventInfo(this, getString(R.string.app_name), msg, contentIntent); notificationManager.notify(0, notification); } }
public class C2DMActivity extends Activity { /** Called when the activity is first created. */ //Debugging private static final String TAG = "C2DM"; private static final boolean D = true; public static final String SENDER_ID = "your email"; //使用C2DM服務的用戶帳號 public static final String MESSAGE_KEY_ONE = "message"; //與Server接收消息的key值 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Log.v(TAG, "Start"); C2DMessaging.register(this, SENDER_ID); //register } }
WifiConfiguration config = new WifiConfiguration(); config.allowedAuthAlgorithms.clear(); config.allowedGroupCiphers.clear(); config.allowedKeyManagement.clear(); config.allowedPairwiseCiphers.clear(); config.allowedProtocols.clear(); config.SSID = "\"" + SSID + "\"";
config.wepKeys[0] = ""; config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); config.wepTxKeyIndex = 0;
config.preSharedKey = "\""+Password+"\""; config.hiddenSSID = true; config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); config.wepTxKeyIndex = 0;
config.preSharedKey = "\""+Password+"\""; config.hiddenSSID = true; config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); config.allowedProtocols.set(WifiConfiguration.Protocol.WPA); config.status = WifiConfiguration.Status.ENABLED;
mWifiManager = (WifiManager)getSystemService(WIFI_SERVICE); try { WifiConfiguration wc = new WifiConfiguration(); wc.SSID = "\"ICCL\""; //AP SSID NAME wc.preSharedKey = "\"passwd\""; //AP passwd wc.hiddenSSID = true; wc.status = WifiConfiguration.Status.ENABLED; wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN); int netId = mWifiManager.addNetwork(wc); boolean success = mWifiManager.enableNetwork(netId, false); //Connect AP if(success){ //只能說明你的密碼沒有輸錯,並且網路可用,但不一定連接上了! Toast.makeText(getApplicationContext(), "Connect ICCL AP.", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(getApplicationContext(), "Connect ICCL AP.", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { Toast.makeText(getApplicationContext(), "Err", Toast.LENGTH_SHORT).show(); e.printStackTrace(); }