ããã«ã¡ã¯ãæ ªå¼ä¼ç¤¾ã¢ãã°ãã¼ã ã½ãªã¥ã¼ã·ã§ã³ç¬¬ä¸äºæ¥é¨Androidã¢ããªã¨ã³ã¸ãã¢ã®æ°äºã§ãã
æ¬æ¥ã¯Android14ããå¯è½ã«ãªã£ãã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºAPIã«ã¤ãã¦ç´¹ä»ãããã¨æãã¾ãã
- ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºæ©è½ã«ã¤ãã¦
- ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºã®å®è£ æé
- å®è£ ä¾ï¼ç»é¢ã®ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãç¦æ¢ã注æã¡ãã»ã¼ã¸ã表示ããå®è£ ãè¡ã
- ã¾ã¨ã
ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºæ©è½ã«ã¤ãã¦
ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºæ©è½ã¯ãæ
å ±æ¼æ´©ãä¸æ£å©ç¨é²æ¢ãã¦ã¼ã¶ã¼ä½é¨åä¸ãªã©ãæ§ã
ãªç¨éã§å©ç¨ã§ãããã®ã«ãªãã¾ãã
使ç¨ä¾ã¨ãã¦ã¯ã以ä¸ã®ãã®ãããã¾ãã
- ã¡ãã»ã¼ã¸ã®ããåããã¹ã¯ã·ã§ãã¦ä¿åãããç»é¢é²ç»ãããã¨ããã¨éç¥ããã
- æ©å¯æ§ã®é«ãæ
å ±ãåãæ±ãç»é¢ã§ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãç¦æ¢ã注æã¡ãã»ã¼ã¸ã表示ããã
- ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±å¾ãç»åãå
±æããããã«èªå°ããã¡ãã»ã¼ã¸ã表示ããã ç
ãã ãããã®æ©è½ã¯iOSå´ã§ã¯ç°¡åã«ã§ãããã®ã®Androidå´ã¯åéçºè
ãç¬èªã§å®è£
ããå¿
è¦ããããã¨ãããã¾ãè¦ãããªããã®ãã¨æãã¾ãã
ã¾ããã®ç¬èªã®å®è£
ããã©ã¢ã°ã©ã¦ã³ãã§ãã¡ã¤ã«ã®å¤æ´ãæ¤ç¥ãããã¨ã§ã¹ã¯ãªã¼ã³ã·ã§ãããæ®å½±ããããã¨ãæ¤ç¥ããã¨ããæéã®æããå®è£
ã«ãªãã¾ãã
ãããªä¸ãAndroid14ããã®æ°æ©è½ã¨ãã¦ã¹ã¯ãªã¼ã³ã·ã§ãããæ®å½±ãããã¨ãã«ã¢ããªã«éç¥ããæ°ãã API ãå°å
¥ãããã»ãã¥ãªãã£åä¸ä¸ã¤ç°¡åã«å°å
¥ã§ããããã«ãªãã¾ããã
ããããã¯ãã®æ©è½ã®å®è£
æé ã¨å®è£
ä¾ãç´¹ä»ãããã¨æãã¾ãã
ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºã®å®è£ æé
1.権éã宣è¨ãã
AndroidManifest.xmlã«ã¦ãDETECT_SCREEN_CAPTUREãã¤ã³ã¹ãã¼ã«æã®æ¨©éã«è¿½å ãã¾ãã
AmdroidManifest.xml
<uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" />
2.ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãæ¤åºããéã«è¡ãã³ã¼ã«ããã¯å¦çãå®è£ ãã
ããã§ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãæ¤åºããå¾ã®å¦çãå®è£
ãã¾ãã
ããã¾ã§æ¤åºã®ã¿ãªã®ã§ã¹ã¯ãªã¼ã³ã·ã§ããã®å
容ãåå¾ãããããªãã¨ã¯ã§ãã¾ããã
val screenCaptureCallback = Activity.ScreenCaptureCallback { // Add logic to take action in your app. }
3.ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºã®ã³ã¼ã«ããã¯ãç»é²/解é¤
ã¢ã¯ãã£ããã£ã®onStart()ã¡ã½ãã / onStop()ã¡ã½ããã§ãã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºã®ã³ã¼ã«ããã¯ãç»é² / 解é¤ãã¾ãã
override fun onStart() { super.onStart() // Pass in the callback created in the previous step // and the intended callback executor (e.g. Activity's mainExecutor). registerScreenCaptureCallback(mainExecutor, screenCaptureCallback) } override fun onStop() { super.onStop() unregisterScreenCaptureCallback(screenCaptureCallback) }
å®è£ ä¾ï¼ç»é¢ã®ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãç¦æ¢ã注æã¡ãã»ã¼ã¸ã表示ããå®è£ ãè¡ã
ç»é¢ã®ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãç¦æ¢ã注æã¡ãã»ã¼ã¸ã表示ããå®è£
ãè¡ãããã¨æãã¾ãã
ç»é¢ã®ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãç¦æ¢ããã«ã¯ä¸è¨ãActivityçã§è¨å®ãããã¨ã§ãã®ç»é¢ã®ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãç¡å¹åã§ãã¾ãã
WindowManagerã®LayoutParamsã« FLAG_SECURE ã¨ãããã®ããããActivityçã§è¨å®ãããã¨ã§ãã®ç»é¢ã®ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãç¡å¹åã§ãã¾ãã
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
端æ«ãOSã«ãã£ã¦æåã¯ç°ãªãã¾ãããåºæ¬çã«ã¹ã¯ãªã¼ã³ã·ã§ãããæ®ããã¨ããã¨çã£é»ãªç»é¢ã®ç»åãä¿åããã¦ç»é¢ã®å
容ãæ®å½±ã§ããªãããã«ãªãã¾ãã
ãã ããã¦ã¼ã¶ã¼ã«ã¯ãªãç»é¢ãçã£é»ã§å¡ãã¤ã¶ãããã®ãä½ã®èª¬æããªãããªãä¸è¦ªåã§ãã
ããã§ãä»åã®Android14ããå¯è½ã«ãªã£ãã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºAPIã使ç¨ãã¦æ³¨æã¡ãã»ã¼ã¸ã表示ãããã¨ã§è¦ªåãªã¦ã¼ã¶ä½é¨ãæä¾ã§ããããã«ãããã¨æãã¾ãã
å®è£ ã³ã¼ã
AmdroidManifest.xml
<uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" />
MainActivity.kt
class MainActivity : AppCompatActivity() { private val screenCaptureCallback = ScreenCaptureCallback { // 注æã¡ãã»ã¼ã¸ã¯ã·ã³ãã«ã«AlertDialogãå©ç¨ãã¦ãã¤ã¢ãã°è¡¨ç¤º AlertDialog.Builder(this) .setMessage("å人æ å ±ãå«ã¾ããçºã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ã¯ç¦æ¢ã§ãã") .setPositiveButton("OK",null) .show() } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãç¡å¹å window.addFlags(WindowManager.LayoutParams.FLAG_SECURE) } override fun onStart() { super.onStart() // Android14ã®æ©è½ã®çºAndroid13以åã§ã¯ä½¿ç¨ããªãããã«ãã if (Build.VERSION.SDK_INT >= 34) { registerScreenCaptureCallback(mainExecutor, screenCaptureCallback) } } override fun onStop() { super.onStop() if (Build.VERSION.SDK_INT >= 34) { ããã // Android14ã®æ©è½ã®çºAndroid13以åã§ã¯ä½¿ç¨ããªãããã«ãã unregisterScreenCaptureCallback(screenCaptureCallback) } } }
â»å®éã§ã¯AlertDialogã¯ç»é¢å転æã«ã¡ã¢ãªãªã¼ã¯ãçºçããå¯è½æ§ãããçºãDialogFragmentãç¶æ¿ããã¯ã©ã¹ãä½ã£ã¦ä½¿ç¨ãããã¨ããããããã¾ãã(ä»åã¯ç°¡ç¥åã®çºç´æ¥è¨è¼ãã¦ãã¾ã)
å®éã®æåã«ã¤ãã¦
ãããããã§ããããã¡ãã¯ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±å¾ãã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ããç»åã«ãªãã¾ãã
ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±ãç¡å¹åãã¦ããçºãå¾ãã¯çã£é»ãç»é¢ã«ãªã£ã¦ãã¾ãã
ããã¦ç»é¢ä¸å¤®ã«ã¯å®è£
ãã注æã¡ãã»ã¼ã¸ã®ãã¤ã¢ãã°ã表示ããã¦ã¾ããã
ãã以å¤ã®ç»é¢ä¸ã®ï¼ã¤ã«é¢ãã¦ã¯OSå´ããèªåçã«è¡¨ç¤ºããã¦ãããã®ã«ãªãã¾ãã
ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºAPIã«ãã£ã¦æ°ãã«è¡¨ç¤ºãããããã«ãªã£ãã®ã¯ããµã³ãã«ã¢ã㪠ããã®ã¹ã¯ãªã¼ã³ã·ã§ãããæ¤åºã表示ã®é¨åã§ã"ãµã³ãã«ã¢ããª"ã®é¨åã«é¢ãã¦ã¯è¨å®ããã¦ããã¢ããªåã表示ãããããã«ãªã£ã¦ãã¾ããã
ãã®ããã«ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºAPIãå©ç¨ãããã¨ã§ãã¦ã¼ã¶ã¨ãã¦ã¯ãã¹ã¯ãªã¼ã³ã·ã§ãããæ®ã£ãã®ã«ä½æ ãçã£é»ãç»é¢ã®ç»åãä¿åãããããªãï¼ãã¨ããäºã«ãªãããçç±ãæè¨ããã¦ãã¦ããã«ç解ãããã¨ãã§ãã¾ãã
ã¾ã¨ã
è¦ã¦ããã ããéãã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºAPIã«ãã£ã¦ã¨ã¦ãç°¡åã«ã¹ã¯ãªã¼ã³ã·ã§ããæ®å½±æ¤åºããããã¨ãã§ãã¾ãã
ãã¾ãæ´»ç¨ãããã¨ã§ããåªããã¦ã¼ã¶ã¼ä½é¨ãæä¾ã§ãããã®ã«ãªãã¾ãã
ä»å¾ãAndoroid14ãæ®åãããã¨å
±ã«åã¢ããªã«å°å
¥ããã¦æ´»ç¨ããã¦ããããããã¾ãããã
æå¾ã¾ã§ãèªã¿ããã ããããã¨ããããã¾ããã
ã¢ãã°ãã¼ãã§ã¯ããã¾ãã¾ãªãã¸ã·ã§ã³ã§ä¸ç·ã«åã仲éãåéãã¦ãã¾ãï¼
詳細ã«ã¤ãã¦ã¯ä¸è¨ããã確èªãã ãããã¿ãªãã¾ããã®ãå¿åãå¾
ã¡ãã¦ããã¾ãã