利用Intent達到目的,
Intent intent= new Intent(android.provider.Settings.ACTION_SETTINGS);
startActivity(intent);
紅色區域可以代換為其他的設定屬性(如GPS,音量, 網路 blablabla..),
可參考API:
http://developer.android.com/reference/android/provider/Settings.html
2015年2月1日 星期日
[Android] GPS定位範例 (轉載)
LocationActivity.java
/*
* 利用Criteria選擇最優的位置服務,演示定位使用者的位置並且監聽位置變化的代碼
* */
package uni.location;
import android.app.Activity;
import android.content.CoNtext;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.widget.TextView;
public class LocationActivity extends Activity {
/** Called when the activity is first created. */
//創建lcoationManager物件
private LocationManager manager;
private static final String TAG = "LOCATION DEMO";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//獲取系統的服務,
manager = (LocationManager)getSystemService(CoNtext.LOCATION_SERVICE);
//創建一個criteria物件
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
//設置不需要獲取海拔方向資料
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
//設置允許產生資費
criteria.setCostAllowed(true);
//要求低耗電
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = manager.getBestProvider(criteria, false);
Log.i(TAG, "we choose "+ provider);
Location location = manager.getLastKnownLocation(provider);
//第一次獲得設備的位置
updateLocation(location);
//重要函數,監聽資料測試
manager.requestLocationUpdates(provider, 6000, 10,
locationListener);
}
//創建一個事件監聽器
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateLocation(location);
}
public void onProviderDisabled(String provider){
updateLocation(null);
Log.i(TAG, "Provider now is disabled..");
}
public void onProviderEnabled(String provider){
Log.i(TAG, "Provider now is enabled..");
}
public void onStatusChanged(String provider, int status,Bundle extras){ }
};
//獲取使用者位置的函數,利用Log顯示
private void updateLocation(Location location) {
String latLng;
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLng = "Latitude:" + lat + " Longitude:" + lng;
} else {
latLng = "Can't access your location";
}
Log.i(TAG, "The location has changed..");
Log.i(TAG, "Your Location:" +latLng);
}
}
同時修改manifest.xml檔
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="HTTP://schemas.android.com/apk/res/android"
package="uni.location"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".LocationActivity"
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>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
2013年8月1日 星期四
[Word] 編號 超過 10 會有刪不掉的空白
「檢視」->「尺規」打勾
可以看到原本的版面跳出尺規
隨意在尺規上點兩下 跳出「段落」
左下角的「定位點(T)」 按下去
將右上角的「預設定位停駐點(F)」設為0.21字元
完工~
可以看到原本的版面跳出尺規
隨意在尺規上點兩下 跳出「段落」
左下角的「定位點(T)」 按下去
將右上角的「預設定位停駐點(F)」設為0.21字元
完工~
2012年9月6日 星期四
[C#] 統計arraylist內各個項目出現次數
//註: arDif是存放資料的ArrayList, 我們要統計裡面存放的資料, 項目以及其出現次數
Dictionary<double, int> result = new Dictionary<double, int>();
foreach (int d in arDif)
{
if (result.ContainsKey(d))
{
result[d] = result[d] + 1;
}
else
{
result.Add(d, 1);
}
}
//show資料
foreach (KeyValuePair<double, int> item in result)
{
textBox9.Text += string.Format("{0} : {1}"+Environment.NewLine, item.Key, item.Value);
}
[C#] ArrayList轉Array
static void Main(string[] args){ { ArrayList Lists = new ArrayList(); Lists.Add("a"); Lists.Add("b"); Lists.Add("c"); string[] s = (string[])Lists.ToArray(typeof(string)); foreach (string item in s) { Console.WriteLine(item); } } { ArrayList Lists = new ArrayList(); Lists.Add(1); Lists.Add(2); Lists.Add(3); int[] i = (int[])Lists.ToArray(Type.GetType("System.Int32")); foreach (int item in i) { Console.WriteLine(item.ToString()); } }}
訂閱:
文章 (Atom)