Reference:
http://yeeapps.com/11/news_detial.php?news_id=adb%20server%20is%20out%20of%20date.killing%E7%9A%84%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%B3%95
Step:
1. 在cmd中執行adb nodaemon server,查看adb的埠號是多少,一般情況下是5037
2. 再執行netstat -ano | findstr "5037",找出佔據埠號5037的程序,並記錄其 PID
3. 到工作管理員中,將同一個 PID的程序刪除
2015年11月5日 星期四
2015年11月4日 星期三
Changing layout height programmatically
Reference:
http://www.cnblogs.com/wanqieddy/p/4040601.htmlCode snippet:
layout.xml:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/my_relative_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent">
................
class.java:
RelativeLayout mRelativeLayout = (RelativeLayout) findViewById(R.id.my_relative_layout_id);
mRelativeLayout.setLayoutParams(new LinearLayout.LayoutParams(200,600));
Note:
setLayoutParams裡的參數型態不是要改變高度的 layout型態,而是要和外面一層layout的型態相同(如上面紅字所標註),否則會出現 ClassCastException以上面的範例來說,要改變高度的 layout型態是 RelativeLayout,如果 setLayoutParams裡面帶入的參數型態為 RelativeLayout.LayoutParams,就會出現下面的 exception
java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
因為要改變高度的 layout,外面一層的 layout型態為 LinearLayout,所以setLayoutParams裡面帶入的參數型態要是 LinearLayout.LayoutParams
2015年10月15日 星期四
如何在 App 畫面上顯示 Google map
Reference:
https://developers.google.com/maps/documentation/android-api/map#indoor_mapshttps://developer.android.com/guide/topics/location/index.html
Illustration:
按照“取得 Google map的 API key”一文,取得了 Google Map API key之後,之後在下列檔案新增紅字的部分,就可以在你的 app裡面顯示 Google map了1. AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="your_package_name" >
<permission android:name="your_package_name.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="your_package_name.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
...... >
<meta-data
android:name="com.google.android.gms.version"
android:value="6587000" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />
.......
</application>
<!--
如果使用OpenGL ES version 2來顯示
避免 Google Play Store 認為我們的 App 不支援 OpenGL ES version 2
-->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
</manifest>
2. res/values/google_maps_key.xml
<resources>......
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
YOUR_KEY_HERE
</string>
</resources>
取得 Google map的 API key
Reference:
http://developer.android.com/tools/publishing/app-signing.html
https://developers.google.com/maps/documentation/android-api/signup
http://wazai.net/1916/%E7%B0%BD%E7%BD%B2%E4%BD%A0%E7%9A%84android%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F-keystorehttps://developers.google.com/maps/documentation/android-api/signup
Step:
1. 打開命令提示字元視窗,輸入下列的指令:keytool -genkey -v -keystore yourkeyname.keystore -alias yourkeyname -keyalg RSA -keysize 2048 -validity 10000
Note:
如果這邊出現「keytool: command not found」,請把$JAVA_HOME\bin加入環境變數$PATH中,或是直接到$JAVA_HOME\bin\目錄下執行 keytool,例如 $JAVA_HOME\bin是 C:\Program Files\Java\jdk1.7.0_02\bin,就先cd C:\Program Files\Java\jdk1.7.0_02\bin之後開始輸入上面的指令。
將上述指令 -keystore yourkeyname.keystore以及 -alias yourkeyname中的 yourkeyname改成自己要的名字,其他東西照著貼上就好,-validity官方說明文件建議設定10000以上的值
Ex:
keytool -genkey -v -keystore jasonrelease.keystore -alias jasonrelease -keyalg RSA -keysize 2048 -validity 10000
2. 將產生的 yourkeyname.keystore移到 $JAVA_HOME\bin\目錄下
3. 在命令提示字元視窗輸入下列指令
keytool -list -v -keystore jasonrelease.keystore
android debug key:
keytool -list -v -keystore debug.keystore
password:android
android debug key:
keytool -list -v -keystore debug.keystore
password:android
4. 將 SHA1編碼複製起來,等一下在 Google API Console網頁會使用到
5. 利用 Google搜尋 Google API Console,找到Google API註冊網站
https://console.developers.google.com/
6. API -> Google Maps Android API -> 啟用
7. 憑證 -> 新增憑證 -> API金鑰 -> 「Android」金鑰
8. 新增「套件名稱和指紋」
9. 輸入開發的 app的套件名稱和剛剛複製起來的 SHA1編碼,點擊建立按鈕後完成
2015年10月14日 星期三
Hide the statusbar and navigation bar permanently
Reference:
http://stackoverflow.com/questions/21724420/how-to-hide-navigation-bar-permanently-in-android-activityCode snippet:
private int currentApiVersion;
@Override
@SuppressLint("NewApi")
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
currentApiVersion = android.os.Build.VERSION.SDK_INT;
final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
// This work only for android 4.4+
if(currentApiVersion >= Build.VERSION_CODES.KITKAT)
{
getWindow().getDecorView().setSystemUiVisibility(flags);
// Code below is to handle presses of Volume up or Volume down.
// Without this, after pressing volume buttons, the navigation bar will
// show up and won't hide
final View decorView = getWindow().getDecorView();
decorView
.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
{
@Override
public void onSystemUiVisibilityChange(int visibility)
{
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
{
decorView.setSystemUiVisibility(flags);
}
}
});
}
}
@SuppressLint("NewApi")
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
if(currentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
{
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
2015年10月13日 星期二
ActionBar 顯示返回鍵
Reference:
http://yuzhou2.blogspot.tw/2015/08/android-actionbar-homeasup.htmlhttp://developer.android.com/guide/topics/ui/actionbar.html
https://developer.android.com/training/implementing-navigation/ancestral.html
Code snippet:
AndroidManifest.xml<application ...>
<activity android:name=".MainActivity" ...>
</activity>
<activity android:name=".SecondActivity"
android:parentActivityName=".MainActivity" ...>
</activity>
</application>
SecondActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
ActionBar actionBar = getSupportActionBar();
// change the icon of key
actionBar.setHomeAsUpIndicator(R.drawable.icon);
actionBar.setDisplayHomeAsUpEnabled(true);
}
Note:
This is appropriate when the parent activity may be different depending on how the user arrived at the current screen.SecondActivity.java
@Override
public Intent getParentActivityIntent() {
finish();
return null;
}
訂閱:
文章 (Atom)