- 投稿日:2020-04-03T18:57:06+09:00
Proxy有りでUnityのAndroidビルド
ユーザー名フォルダの直下にある .gradle フォルダの中に
gradle.properties という名前のファイルを作成
作成したファイルをエディタ等で開き、下記のように記述(Http・Https両方必要かは環境による気がする)
gradle.propertiessystemProp.http.proxyHost=Proxy指定ホスト systemProp.http.proxyPort=8080 systemProp.http.proxyUser=ログインユーザーID systemProp.http.proxyPassword=パスワード systemProp.https.proxyHost=Proxy指定ホスト systemProp.https.proxyPort=8080 systemProp.https.proxyUser=ログインユーザーID systemProp.https.proxyPassword=パスワード■参考URL
https://answers.unity.com/questions/1621072/how-to-fix-gradle-build-error-when-building-androi.html
- 投稿日:2020-04-03T15:54:06+09:00
【Android】build.gradleからfastlaneでversionNameを取得する
概要
fastlaneでversionNameを使用したい時、build.gradleで管理しつつ、FastfileでもversionNameを使えるようにしたので議事録として記載
build.gradle側の記載
app/build.gradleapply plugin: 'com.android.application' ・・・ def versionMajor = 1 def versionMinor = 2 def versionPatch = 3 android { ・・・ defaultConfig { ・・・ versionName "${versionMajor}.${versionMinor}.${versionPatch}" }それぞれバージョンを定義して、
defaultConfig
のversionNameで組み合わせるFastfile側の取得処理
fastlane/Fastfileplatform :android do before_all do |lane, options| end ・・・ lane :version_name do app_version_name = get_version_name end after_all do |lane, options| # laneの実行が成功した際に呼ばれる ・・・ end error do |lane, exception, options| # laneの実行がエラーになった際に呼ばれる ・・・ end end def get_version_name version_major = 0 version_minor = 0 version_patch = 0 File.open("../app/build.gradle") do |file| file.each_line do |line| if line.strip.start_with?("def versionMajor") version_major = line.split("=")[1].strip.to_i elsif line.strip.start_with?("def versionMinor") version_minor = line.split("=")[1].strip.to_i elsif line.strip.start_with?("def versionPatch") version_patch = line.split("=")[1].strip.to_i end end end end文字列にする場合は、それぞれの変数を組み合わせる
"#{version_major}.#{version_minor}.#{version_patch}"
versionNameを使いたいlaneで呼んであげる
アプリバージョンを上げる時はbuild.gradle側を更新するだけでfastlaneでも最新のversionNameを取得できる
- 投稿日:2020-04-03T13:49:41+09:00
Android の Wi-Fi まわりのことメモ
WiFi まわりのことを扱う機会があったので、復習がてら整理してみる。
パーミッション取得
- AndroidManifest.xml に追加
OS、 targetSDK によって必要な権限が異なる。詳しくは公式ドキュメント参照。
以下は一例。AndroidManifest.xml<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
- 権限取得処理実装
必要なタイミングで権限をユーザーに求める処理を呼び出す。
activityprivate val PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION = 0 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) なんかボタン.setOnClickListener { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestPermissions(arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION) } else { // 許可済みの処理 } } } override fun onRequestPermissionsResult(requestCode: Int, @NonNull permissions: Array<String>, @NonNull grantResults: IntArray) { if (requestCode != PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION) { return } if (grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // 許可済みの処理 } }WiFi をスキャンする
activityval wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager val wifiScanReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val success = intent.getBooleanExtra(WifiManager.EXTRA_RESULTS_UPDATED, false) if (success) { scanSuccess() } else { scanFailure() } } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // startScan() が呼ばれると SCAN_RESULTS_AVAILABLE_ACTION がブロードキャストされる registerReceiver(wifiScanReceiver, IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) val success = wifiManager.startScan() if (!success) { scanFailure() } } private fun scanSuccess() { // スキャン成功処理 } private fun scanFailure() { // スキャン失敗処理 }WiFi に接続する
なんかボタン.setOnClickListener { val connectScanResult: ScanResult = 接続したいWiFiの ScanResult // 既に保存されている WiFi の設定情報を取得 var configuredNetworks: List<WifiConfiguration>? try { configuredNetworks = wifiManager.configuredNetworks } catch (e: Exception) { configuredNetworks = null } var networkId = -1 if (configuredNetworks != null) { for (configuredNetwork: WifiConfiguration in configuredNetworks) { // "(ダブルクォーテーション) が前後についているので除外している val normalizedSsid = configuredNetwork.SSID.substring(1, configuredNetwork.SSID.length - 1) // すでに接続情報があるかチェックする if (connectScanResult.SSID.equals(normalizedSsid)) { networkId = configuredNetwork.networkId break } } } if (networkId < 0) { // 接続情報がないので作る val configuration = WifiConfiguration().apply { SSID = "\"$connectScanResult.SSID\"" // 設定する前に一回クリアする(よくわかってない・・・) allowedProtocols.clear() allowedProtocols.set(WifiConfiguration.Protocol.RSN) allowedProtocols.set(WifiConfiguration.Protocol.WPA) allowedAuthAlgorithms.clear() allowedPairwiseCiphers.clear() allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP) allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP) allowedGroupCiphers.clear() allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP) allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP) // 設定する // connectScanResult.capabilities に "WEP"、"PSK" などが含まれるかどうかで設定方法が変わる allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE) allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN) allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED) allowedGroupCiphers.clear() allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40) allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104) wepKeys[0] = "\"接続する WiFi のパスワード\"" wepTxKeyIndex = 0 } networkId = wifiManager.addNetwork(configuration) } if (networkId < 0) { Toast.makeText(this, "接続できませんでした", Toast.LENGTH_SHORT).show() return } if (wifiManager.enableNetwork(networkId, true)) { Toast.makeText(this, connectScanResult.SSID + "に接続しました。", Toast.LENGTH_SHORT).show() } else { Toast.makeText(this, "接続できませんでした", Toast.LENGTH_SHORT).show() } }接続中のネットワークの SSID を取得する
val wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager if (wifiManager.connectionInfo.networkId != -1) { // ネットワーク接続中 // ※ ここで取得できる SSID は先頭と末尾に "(ダブルクォーテーション) が前後についている // https://developer.android.com/reference/android/net/wifi/WifiInfo#getSSID() val ssid = wifiManager.connectionInfo.ssid } else { // ネットワークに接続されていない }参考
- 投稿日:2020-04-03T11:49:01+09:00
リップルエフェクト付きの角丸ボタンの作り方
色や角の丸みはお好みで
button.xml<?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorAccent"> <item> <shape android:shape="rectangle"> <solid android:color="@color/colorPrimary"/> <corners android:radius="25dp"/> </shape> </item> </ripple>
- 投稿日:2020-04-03T08:09:07+09:00
Android ぱっと見でわかるConstraintLayout
ConstraintLayout
で最低限おぼえておくべき4つ
- layout_constraintTop_toTopOf
- layout_constraintTop_toBottomOf
- layout_constraintStart_toStartOf
- layout_constraintStart_toEndOf