顯示具有 Android 標籤的文章。 顯示所有文章
顯示具有 Android 標籤的文章。 顯示所有文章

2019年4月26日

Android: LayoutParamers of View

根據view所在的ViewGroup而有相對應的LayoutParamers.
例如:包在FrameLayout底下的Textview,它的LayoutParamers就是FrameLayout.LayoutParamers.

2018年10月2日

已解除安裝,仍出現"安裝套件所使用的簽名和現有套件的簽名相同"

用adb uninstall com.xxx.xxx 即可!

2018年9月28日

Android: webview 呼叫JavaScript函數

本來執行得好好的程式碼,在新版的Android就失效了?
Debug了半天,原來是WebView不能在同一個Thread呼叫?

myWebView.loadUrl("javascript:alert('test')");

需要改成底下:

myWebView.post(new Runnable() {
@Override
public void run() {
myWebView.loadUrl("javascript:alert('test')");
}
});

2018年4月25日

Android: 在不同thread上,更改button上的文字

button1.post(new Runnable() {
                          public void run() {
    button1.setText(R.string.btn1);
                       } });

2017年8月30日

Service Intent must be explicit: Intent { act=com.android.vending.billing.InAppBillingService.BIND }

IabHelper.java

增加一行指令即可!

   public void startSetup(final OnIabSetupFinishedListener listener) {
        // If already set up, can't do it again.
        if (mSetupDone) throw new IllegalStateException("IAB helper is already set up.");
        // Connection to IAB service
        logDebug("Starting in-app billing setup.");
        mServiceConn = new ServiceConnection() {

              .....................省略

        };
       
        Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");

              .....................省略

    }

2017年7月28日

Android: In-app-billing 付費機制Google範例

Preparing Your In-app Billing Application
Administering In-app Billing
Security and Design

AndroidManifest.xml中必須增加底下宣告:
 <uses-permission android:name="com.android.vending.BILLING" />
Package的名稱必須Rename,
package com.wsj.android.trivialdrivesample;
換入你上傳App後的金鑰,
String base64EncodedPublicKey = "MIIBIjANBgkqhkiG9w0B...省略.....";
Google Play Console中,產生程式中購買的對應物品,以便測試

  • 手機的primary gmail帳號要設成測試gmail帳號,不能用開發者的gmail帳號!
  • APK必須發佈Alpha或Beta才能測試,利用所附的URL成為測試人員,然後下載APP.
  • "錯誤!此項目目前無法購買"<----退出計畫,後重新成為測試人員!!
  • 所欲購買項目必須啟動(in Active)
  • "錯誤!請先入登入GOOGLE帳戶"<---加入Alpha/Beta測試計畫
  • 測試帳號須登登錄信用卡資訊才能完成測試購買

2017年4月27日

Android: Eclipse 使用android-support-v7-appcompat.jar和android-design-support.jar和google-play-services

有些舊project不想翻新到Android Studio,但又想增加新功能,但是程式範例用到新的jar,不得已只好想辦法,舊瓶裝新酒。

android-support-v7-appcompat.jar :import程式碼project,編譯(target到android 5.0以上)。
引用的project在project的內容中,加入reference即可。

android-design.support.jar:引用的project直接用外部jar即可。

google-play-services:import /extras/google/google_play_services/libproject/google-play-services_lib專案。(好像r30版本之後沒有此專案!幸好還找得到下載舊版的地方)

2017年4月12日

Android: AlertDialog 改變其高度

AlertDialog alert = new AlertDialog.Builder(this).create();
alert.show();  
//
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int h90 = (int)(0.9f*((float)metrics.heightPixels)) ;   //高度設為90%
alert.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, h90);
//

2017年3月21日

Unable to execute dex: GC overhead limit exceeded in Eclipse

Export專案時,發生上述的錯誤,原來是Eclipse的在Eclipse.ini中的Xms和Xmx值設定太小,將其設成 512 和 1024 即可。
-Xms512m 
-Xmx1024m

2015年5月19日

Android: Eclipse程式專案出現紅色驚嘆號!

前晚救回Eclipse開發平台,今天還有些小問題須解決!

  • 專案x
    原來正常編譯的專案,很多都因為Android-sdk的移除重裝,必須重新指定編譯的Android SDK版本。
  • 專案!驚嘆號
    表示找不到相關的Library。將相關的程式庫放到指定的位置就OK了。


Android: Eclipse ADT Plug-in 升級問題

     將近午夜時,突然心血來潮想試試Android 4.4 KitKat SDK的WebView是否能支援Html5 video 的Playback rate指令,希望可以但一直沒時間測試。就趁這空檔,升級ADT插件和更新下載SDK。因為之前升級一直很順利,心中是有閃過萬一失敗的陰影,但沒放在心上...

2015年1月2日

Android: NDK不支援有版本資訊的C程式庫?

Issue 55868: NDK: Support for prebuild libs with full sonames

    近日遇到奇怪的問題;好不容易從某Linux Open Sourses原始碼編譯成程式庫.so,正在高興終於編好時,從Andorid載入時竟發生找不到Libxxxx.so.4 程式庫?
    Google半天,終於問對問題找到答案,學會該怎麼serch問題還真是不易呀!
   原來Linux系統的程式庫soname有所謂版本資訊,例如Libxxx.so.4.4.8。Linux用兩個Libxxx.so和Libxxx.so.4(Symbol Link)連結到Libxxx.so.4.4.8,但Android的Linker目前並未支援。若只是將Libxxx.so.4.4.8改名成Libxxx.so複製過去,用 readelf -d Libxxx.so 檢視其soname還是Libxxx.so.4,沒有用的!

2014年12月28日

Android: JNI相關

Java调用C程序, C调用Java程序
JNI Tips
Android 開發筆記 - 使用 NDK / JNI 實作從底層呼叫上層 (C call Java)
Java Programming Tutorial Java Native Interface (JNI)
http://blog.csdn.net/i5suoi/article/details/19036975
探秘腾讯Android手机游戏平台之不安装游戏APK直接启动法
Android应用开发提高系列(4)——Android动态加载(上)——加载未安装APK中的类

2014年12月25日

Android: NDK 測試範例

1. 下載安裝 Android NDK
     例如我將64bits版本的NDK安裝到 E:/dev/SDKs/android-ndk-r9b-windows-x86_64/

2. 下載安裝 Cygwin
     安裝時記得包含Devel中的make 和 Shells中的bash

3. 用Eclipse編譯個簡單的Android Project,內容如下
package com.wsj.android.testjni;
import ......;
public class HelloNDK extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_ndk);
System.loadLibrary("hellondk");    //載入原生程式庫
int result = sayHello();                       //呼叫原生函數 
Log.i("HelloNDK", "" + result);
}
private native int sayHello();           //宣告原生函數
}

2014年11月11日

Android: 非UI Thread更動 UI

當Threrad在同個Activity時,蠻方便的作法:

runOnUiThread(new Runnable() {
    @Override
    public void run() {
       // 更新UI.....
    }
  }
);
 

2014年11月8日

Android: 轉換 Immutable Bitmap into Mutable

BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;  //加上這個選項!!!! (API level 11以上)

Bitmap bm = BitmapFactory.decodeByteArray(data, 0, data.length, options);
Canvas canvas = new Canvas(bm);  // 不然會有錯誤產生!
.......

2014年10月2日

CodeProject : Android 文章

2014年9月4日

Android: AndEngine - Android Game Engine

AndEngine - Android Game Engine:
AndEngine - AndEngineWiki:
AndEngine Simple Android Game Tutorial « Jimmar's blog thingie:
andengineexamples - AndEngine - Examples

範例影片
How to Create a Simple Android Game with AndEngine:
AndEngine Tutorial 01 - Creating a Scene - Perle Development:

好多範例的2D OpenGLES遊戲引擎!!

Andengine Forums

PolyLine.java



2014年7月5日

Android: 解壓縮有密碼的zip檔(Zip4J)

Zip4j 
參考此jar,簡單用法如下:
public static void unzip(File zipFile, String dest, String passwd) throws ZipException {
        ZipFile zFile = new ZipFile(zipFile); 
        File destDir = new File(dest);   
        if (destDir.isDirectory() && !destDir.exists()) {   
            destDir.mkdir();   
        }   
        if (zFile.isEncrypted()) {   
            zFile.setPassword(passwd.toCharArray());   
        }   
        zFile.extractAll(dest);     
    }   

2014年7月3日

Android: Nano Sleep

來源CALL GLOP()

private static final long SLEEP_PRECISION=2*1000000 ;
private static final long SPIN_YIELD_PRECISION= 1000;

    public static void sleepNanos (long nanoDuration) throws InterruptedException {
        final long end = System.nanoTime() + nanoDuration;
        long timeLeft = nanoDuration;
        do {
            if (timeLeft > SLEEP_PRECISION)
                Thread.sleep (1);
            else
                if (timeLeft > SPIN_YIELD_PRECISION)
                    Thread.sleep(0);

            timeLeft = end - System.nanoTime();
            if (Thread.interrupted())
                throw new InterruptedException ();
        } while (timeLeft > 0);
    }