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

2016年8月23日 星期二

[Unity][Android] 自製 Unity Bluetooth Low Energy 4.0 Plugin 紀錄

程式碼參閱 Google android-BluetoothLeGatt-master 範例改寫,產生 classes.jar 檔供使用在 Unity 5.x Personal 版的 Android 平台上,使其可進行檢查藍芽功能、開啟藍芽功能、搜尋 BLE、連接 BLE 等藍芽操作功能。

透過引用 Unity Mono classes.jar 繼承 UnityPlayerActivity 的 Activity 中加入一個 callback function interface,以便 BroadcastReceiver  收到藍芽斷線、連線、服務、資料等訊息時,主動回傳到 Unity 中處理。

2016年6月25日 星期六

[Android] Android Studio 建立與使用 AAR Library

透過 Android Studio Version 2.1.2 建立並使用 Android Archive Library (*.aar)。
要取得 *.jar 檔,只要對 *.aar 解壓縮即可。


2016年3月28日 星期一

[Android Studio] Rendering Problems

有時 Android 更新 API 版本後,Layout 預覽圖會產生 Rendering Problems:


2016年1月7日 星期四

[Android] 新舊 App 程式同時存在,安裝 App 不覆蓋原本的 App

Android 認 applicationId 判斷是否有舊版 App 程式存在,安裝 APK 時會詢問是否覆蓋舊有的 App 程式。

只要修改不同的 applicationId 就可讓新舊版程式都同時存在在 Android 系統內。

2016年1月3日 星期日

[Android] Message Box




import android.content.Context;
import android.widget.Toast;

public void SayHello()
{
    Context context = getApplicationContext();
    Toast.makeText(context, "Hello!", Toast.LENGTH_LONG).show();
}


[Android] 手機馬達震動 Vibrator



在 ProjectName\app\src\main\AndroidManifest.xml 開啟 Vibrate 權限

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.epowertek.myapplication" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" android:label="Vibrate">
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            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>
</manifest>


在 MainActivity.java 中加入下面程式碼測試

import android.os.Vibrator;

public void VibratorEvent(){
   Vibrator myVibrator = (Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);
    myVibrator.cancel();
    // ON 100ms ->; OFF 200ms ->; ON 100ms ->; OFF 200ms
    myVibrator.vibrate(new long[]{100, 200, 100, 200}, -1);
}