
今晩は。EveryDaySoft代表の永田です。 最近も稼働が上がっていまして、SwiftUIで開発をしています。 開発エンジニアも8名となり、かなり人数が増えてきました。
僕のポジションは、iOSとAndroidを担当しています。得意な方は圧倒的にiOSですが、なんとかAndroidも進めることができました。
リモートワークの生活の中では、稼働が上がっています。元々開発が好きなので、自然と稼働してしまいます。
そんな中で、植物を4つ買いました。今後も植物を増やしていこうと思います。
全く関連はないのですが、一年前ぐらいに書いた。 Android FCMのソースコードです。どうぞ。ソースを寄付します。
class MainActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFailedListener { companion object { var msg = "" var message = "" var notificationKey = "" var pm: PowerManager? = null var sendService: GoogleapisSendService? = null var notificationService: GoogleapisNotificationService? = null var MY_REQUESTPERMISSIONS = 1 var MY_IGNORE_BATTERZY_REQUEST = 2 private const val TAG = "MainActivity" private const val sendURL = "https://fcm.googleapis.com/fcm/send" private const val notificationURL = "https://iid.googleapis.com/iid/v1/" } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) FirebaseMessaging.getInstance().subscribeToTopic("test") .addOnCompleteListener { task -> var msg = getString(R.string.msg_subscribed) if (!task.isSuccessful) { msg = getString(R.string.msg_subscribe_failed) } Log.d(TAG, msg) Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show() } FirebaseInstanceId.getInstance().instanceId .addOnCompleteListener(OnCompleteListener { task -> if (!task.isSuccessful) { Log.w(TAG, "getInstanceId failed", task.exception) return@OnCompleteListener } msg = task.result?.token.toString() }) FirebaseMessaging.getInstance().isAutoInitEnabled = true //バッテリー制限のパーミッション pm = getSystemService(Context.POWER_SERVICE) as PowerManager // アカウントの取得パーミッション if (ContextCompat.checkSelfPermission( this, Manifest.permission.GET_ACCOUNTS ) != PackageManager.PERMISSION_GRANTED ) { requestPermissions() } CallButton.setOnClickListener { sharedPreferencesSet(st = "Notification") } } @SuppressLint("MissingSuperCall") override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { notificationService = GoogleapisNotificationService() // AWSからのデータを取得想定 notificationService!!.execute("test", msg, notificationURL) } override fun onConnectionFailed(p0: ConnectionResult) { TODO("not implemented") } // 初回起動後通知キーを永続化させる処理 override fun onStop() { super.onStop() val data = getSharedPreferences("Notification", Context.MODE_PRIVATE) if (MainActivity.notificationKey != "") { val editor = data.edit() editor.putString("notificationKey", MainActivity.notificationKey) editor?.apply() } } // バッテリーパーミッションの設定 fun requestPermissions() { ActivityCompat.requestPermissions( this, arrayOf(Manifest.permission.GET_ACCOUNTS), MY_REQUESTPERMISSIONS ) val isIgnoringBatteryOptimizations: Boolean = pm!!.isIgnoringBatteryOptimizations(packageName) if (!isIgnoringBatteryOptimizations) { val intent = Intent() intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS intent.data = Uri.parse("package:$packageName") startActivityForResult(intent, MY_IGNORE_BATTERZY_REQUEST) } } // FCM通知文言の設定、FCM送信の設定 fun sharedPreferencesSet(st: String) { val setContentText = getSharedPreferences("Data", Context.MODE_PRIVATE) val editor = setContentText.edit() if (setContentText.getString("setContentText", null) == null) { message = if (message == "終了") "開始" else "終了" } else { message = if (setContentText.getString("setContentText", null) == "終了") "開始" else "終了" } editor.putString("setContentText", message) editor?.apply() sendMessage(st = "Notification") } // FCM送信の設定 fun sendMessage(st: String) { val data = getSharedPreferences(st, Context.MODE_PRIVATE) if (MainActivity.notificationKey != "") { val editor = data.edit() editor.putString("notificationKey", MainActivity.notificationKey) editor?.apply() } sendService = GoogleapisSendService() sendService!!.execute(message, "/topics/test", sendURL) } }
以上、貴重なお時間お読み下さいまして、ありがとうごいざいます。
コメントを残す