OSDN Git Service

intentで記録を受信できるようにする(実装中)
[gokigen/JoggingTimer.git] / wear / src / main / java / net / osdn / gokigen / joggingtimer / stopwatch / MainActivity.kt
index cef8992..3048715 100644 (file)
@@ -9,6 +9,7 @@ import android.view.View
 import android.widget.ImageButton
 import android.widget.ListView
 import android.widget.TextView
+import android.widget.Toast
 import androidx.appcompat.app.AppCompatActivity
 import androidx.constraintlayout.widget.ConstraintLayout
 import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
@@ -80,24 +81,38 @@ class MainActivity : AppCompatActivity(), IClickCallback, ITimeoutReceiver, ICou
 
         try
         {
-            val receivedAction = intent.action
-            if (receivedAction == Intent.ACTION_SEND)
+            if (Intent.ACTION_SEND == intent.action)
             {
-                val thread = Thread {
-                    // 取得したSENDインテントを処理する
-                    val importer = IntentSendImporter()
-                    importer.handleIntent(intent)
+                importReceivedIntent()
+            }
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+    }
+
+    private fun importReceivedIntent()
+    {
+        try
+        {
+            val thread = Thread {
+                // 取得したSENDインテントを処理する
+                IntentSendImporter(this.applicationContext, intent).start()
+                val title = intent.getStringExtra(Intent.EXTRA_SUBJECT)
+                runOnUiThread {
+                    Toast.makeText(this, getString(R.string.data_imported) + title, Toast.LENGTH_SHORT).show()
                 }
-                thread.start()
             }
+            thread.start()
         }
         catch (e: Exception)
         {
             e.printStackTrace()
         }
+    }
 
 
-    }
 
     /**
      *