rokkonet

PC・Androidソフトウェア・アプリの開発・使い方に関するメモ

android開発

android開発 ActivityResultContractsによるパーミッション取得(権限取得/permission取得)

2023 Mar. 05. 2022 Mar. 11. 出典 Android の位置情報の権限要求(フォアグラウンド)について Android 7.0 android 11で動作確認した Android 7.0ではパーミッション取得確認ダイアログに「今後表示しない」チェックボックスが表示された Android11では「…

android開発 shouldShowRequestPermissionRationale()

2022 Mar. 11. 出典 [Android][Java] パーミッションダイアログで「今後表示しない」を選択されたかどうかを判定する | deecode blog shouldShowRequestPermissionRationale() の返り値 * 一度も拒否されていない(まだパーミッションダイアログを出していな…

android開発 共有ストレージ領域のパス取得

2022 Mar. 05. 2022 Mar. 03. 下記の getExternalStorageDirectory() はAndroid 10 (API レベル 29)で非推奨となった sharedDirFile: File = Environment.getExternalStorageDirectory() sharedDirStr: String = Environment.getExternalStorageDirectory().…

android開発 アクションバー(タイトルバー、アプリバー)の表示文字列設定

2022 Feb. 27. 出典ページ Android ActionBarとToolBarについてのメモ - 追憶行 supportActionBar?.title = "STRING" sample kotlin code override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // アクションバーに表…

android開発 AlertDialog setPositiveButton(), setNeutralButton(), setNegativeButton()の第2引数はダイアログへのクリックのリスナ

2022 Feb. 13 参考ページ KotlinでAlertDialogを作るときの「which->」ってどういう... - Yahoo!知恵袋 DialogInterface.OnClickListener | Android Developers 例 AlertDialog.Builder(activity).setView(myDialogView).setTitle("My Title") .setPositiveB…

kotlin / java ファイルに1文字書き込み

2020 Feb. 06. androidのアプリ固有のストレージ領域のファイルに1文字書き込むkotlinコード例 lateinit var fos: FileOutputStream try { val saveFile = File(appContext.filesDir, getString(R.string.saveFileName)) // appContext.filesDir: アプリ固有…

android開発 カンマ区切りの1行の文字列データをダイアログ上にリスト表示する

2020 Feb. 05. カンマ区切りの1行の文字列データをダイアログ上にリスト表示するkotlinコード例 ・カンマ区切り文字列をListに変換 ・システムに組み込まれた"android.R.layout.simple_list_item_1"を介して、ListをArrayAdapterに関連付ける ・ArrayAdapter…

kotlin / java テキストファイルから1行読み込み

2022 Feb. 05. androidのアプリ固有ストレージ領域内のテキストファイルから先頭の1行を読み込むkotlinコード例 java.io.FileReader: ファイルからテキストを1文字読み込む java.io.BufferedReader: ファイルからテキストを1行読み込む。FileReaderを拡張し…

android開発 文字列リソース(R.string / strings.xml)の文字列取得はgetString()

2022 Mar. 19. 2022 Feb. 05. 文字列リソース(R.string / strings.xml)に設定された文字列取得は Context.getResources().getString(R.string.ITEM) 。 R.string.ITEM.toString() ではR.string.ITEMのid番号そのものの文字列が返される。

android開発 ContextはonCreate()で取得しないとnull参照エラーとなる

2022 Feb. 05. ContextはonCreate()で取得しないとnull参照エラーとなる。 onCreate()外で使う場合、onCreate()内で取得しておいたContextを使う。

android開発 ContentResolver#query 絞り込み条件指定

2022 Jul. 18. 2022 May 02. 2022 Jan. 30. 参考ページ 共有ストレージからメディア ファイルにアクセスする | Android デベロッパー | Android Developers ContentResolverでソート・絞り込み検索の条件を追加する方法|Androidアプリ開発のあれこれ Conten…

android開発 インターネット接続がwifiか、モバイル通信かを判定する

2021 Dec. 28. 引用元 【Android/Kotlin】インターネット接続の確認とNetworkInfo非推奨の解消 - Qiita ACCESS_NETWORK_STATE権限を許可する uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" AndroidManifest.xml

android開発 Snackbarのsnippet

2021 Dec. 11. 出典 [Android & Kotlin] Snackbar で通知とアクションを実装しカスタマイズする build.bradle(:app) implementation 'com.google.android.material:material:x.x.x'が必要 plugins { id 'com.android.application' id 'kotlin-android' } and…

android開発 ダイアログを開く

2021 Oct. 31. MainActivity.kt class MainActivity : AppCompatActivity() { // Bundleを利用してデータを渡す val str1 = "ab" val int1 = 12 val args = Bundle() args.putString("String1", str1) args.putInt("Integer1", int1) // DialogFragmentのイ…

android開発 Bundleを利用したデータの受け渡し

2022 Feb. 26. 2021 Nov. 14. 2021 Oct. 31. 出典 onSaveInstanceStateについてちゃんと知る - Qiita Bundleの保存・読み込み onSaveInstanceStateはonPauseの直後に呼ばれる。 onSavedInstanceStateで保存した値は、onCreateもしくはonRestoreInstanceState…

android開発 アプリケーションの再起動

2021 Oct. 31. 出典 Restarting Android app programmatically - Stack Overflow val launchIntent = baseContext.packageManager .getLaunchIntentForPackage(baseContext.packageName) launchIntent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) finish() …

android開発 AlertDialogのボタンオブジェクトの取得

2021 Oct. 30. 出典 Android - android開発 DialogFragmentのonStart()内でのOKボタンのOnClickイベント捕捉|teratail 概要 DialogFragmentのonCreateDialog()内でのAlertDialog.Builderのcreate()時に、「ボタンオブジェクトを取得し、操作する」ハンドラ…

android開発 ダイアログ上の2つの EditText の両方に文字列がある時にOKボタンを有効にする

2021 Oct. 30. 出典 Android - android開発 DialogFragmentのonStart()内でのOKボタンのOnClickイベント捕捉|teratail 概要 TextWatcherでEditTextへの入力状況を監視し、条件を満たした時のみOKボタンを有効(isEnabled)にする。 TextWatcherのafterTextCha…

android開発 DialogFragmentのインスタンスはshowメソッドを実行するルーチン内のローカル変数とする

2021 Oct. 30. DialogFragmentのインスタンスはshowメソッドを実行するルーチン内のローカル変数とする。 表示が終わると自動で削除されることがあるので、グローバルに保持すると、メモリリークとなる恐れがある。 ボタン(btnOpenDialog)をタップしたらダイ…

android開発 ダイアログのOKボタンを押しても条件によってはダイアログを開いておく(AlertDialog , DialogFragment)

2021 Oct. 10. 出典 Android Dialog/AlertDialog getButton NullPointerException | Lua Software Code 概要 AlertDialogのgetButton()により、OKボタン、Cancelボタンのインスタンスを取得する DialogFragmentのonStart()にokButton.setOnClickListener { }…

android開発 ダイアログから呼び出し元に値を渡す(独自リスナー利用)

2022 Apr. 29. 2022 Mar. 03. 2021 Oct. 03. 出典 【Kotlin】DialogFragmentからActivityへ値を渡す - Qiita 参考 android開発 ダイアログから呼び出し元に値を渡す - rokkonet 手法 ダイアログクラスに、呼び出し元Activityにデータを渡す抽象メソッドを持…

android開発 DefaultSharedPreferences Android 10(API level 29)以降での設定

2021 Sep. 26. 出典 sharedpreferences - PreferenceManager getDefaultSharedPreferences deprecated in Android Q - Stack Overflow DefaultSharedPreferencesの利用は、Android 10(API level 29)以降は次の設定を要する build.gradle(modle:app) depend…

android開発 build.gradle(module:app) implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"は不要

2021 Sep. 26. 出典 kotlin-stdlibの依存関係をgradleに書く必要はなくなりました - 縁側プログラミング kotlin 1.4.0以降ではbuild.gradle(module:app)に次の設定は不要。 dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_vers…

android開発 kotlin EditTextへの文字列のセットにはsetText()を使う

2021 Sep. 23. EditTextへの文字列のセット val str: String = "abc" (NG) editTexr01.text = str // 「EditableにStringを代入しようとしている」とのエラーになる (OK) editTexr01.setText(str)

android開発 画面回転後のActivityにおいてLiveDataによるデータ更新を防ぐ

2021 Sep. 18. 状況 ViewModel内のLiveDataの値に従ってActivityで音楽再生するようにしていると、画面回転によって意図しない音楽再生となった時の対処 概要 Activityのcreateが直前にdestroyされたことによるものなのかどうかを示すフラグ変数を持つ。 onS…

android開発 ViewModel コルーチンで非同期ワーカースレッド内での処理結果をBoolean値で取得する

2021 Sep. 17. 概要 下記コード例では、 getConnectionSmb()において、非同期ワーカースレッドでSMB接続を行うconnectSmb(): Booleanの結果を取得している。 getConnectionSmb()内でviewModelScope.launch(Dispatchers.IO) { }を利用し、その中でconnectSmb(…

android開発 SMBサーバーもしくは端末内からランダムに1つの音声ファイルをストリーミング再生する

2022 Jul. 18. 2022 Feb. 13. 2021 Dec. 05. 2021 Nov. 14. 2021 Sep. 16. ソース保管場所 https://bitbucket.org/arsmus/randomsmbsoundplay/src/master/ 概要 SMBサーバーからランダムに1つの音声ファイルをストリーミング再生する。 SMBサーバーにつなが…

android開発 URIからファイルシステム上のパスを取得する

2022 May 02. 2021 Sep. 12. 出典 Invalid URI at getting path in different android api - Stack Overflow 端末 Android 11 (API レベル 30) 概要 ContentResolverにて、collectionにuriを、projectionに"_data"をセットしqueryする サンプルkotlinコード …

android開発 Intentで起動するアプリを指定する

2022 Dec. 04. 2022 Jan. 30. 2021 Sep. 12. Intent#setPackageでアプリを指定する 音声uriとVLCメディアプレーヤーを指定するインテント例 // audioUri: Uri URI of an audio content val audioIntent = Intent() audioIntent.action = Intent.ACTION_VIEW …

android開発 TextView Do not concatenate text displayed with setText. Use resource string with placeholders.

2021 Sep. 11. 事象 TextViewへのsetText()の引数に、変数・式といったリテラル以外を含む式を入れると"Do not concatenate text displayed with setText. Use resource string with placeholders."と警告される。 対応 コードではなく、Stringリソース(R.st…