android handle media projection canceled
This commit is contained in:
		
							parent
							
								
									1662dadfc2
								
							
						
					
					
						commit
						bc00375c44
					
				| @ -43,7 +43,7 @@ class MainActivity : FlutterActivity() { | |||||||
|                         Intent(activity, MainService::class.java).also { |                         Intent(activity, MainService::class.java).also { | ||||||
|                             bindService(it, serviceConnection, Context.BIND_AUTO_CREATE) |                             bindService(it, serviceConnection, Context.BIND_AUTO_CREATE) | ||||||
|                         } |                         } | ||||||
|                         if(mainService?.isReady == true){ |                         if (mainService?.isReady == true) { | ||||||
|                             result.success(false) |                             result.success(false) | ||||||
|                             return@setMethodCallHandler |                             return@setMethodCallHandler | ||||||
|                         } |                         } | ||||||
| @ -58,7 +58,7 @@ class MainActivity : FlutterActivity() { | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     "stop_service" -> { |                     "stop_service" -> { | ||||||
|                         Log.d(logTag,"Stop service") |                         Log.d(logTag, "Stop service") | ||||||
|                         mainService?.let { |                         mainService?.let { | ||||||
|                             it.destroy() |                             it.destroy() | ||||||
|                             result.success(true) |                             result.success(true) | ||||||
| @ -67,14 +67,14 @@ class MainActivity : FlutterActivity() { | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     "check_permission" -> { |                     "check_permission" -> { | ||||||
|                         if(call.arguments is String){ |                         if (call.arguments is String) { | ||||||
|                             result.success(checkPermission(context, call.arguments as String)) |                             result.success(checkPermission(context, call.arguments as String)) | ||||||
|                         } else { |                         } else { | ||||||
|                             result.success(false) |                             result.success(false) | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     "request_permission" -> { |                     "request_permission" -> { | ||||||
|                         if(call.arguments is String){ |                         if (call.arguments is String) { | ||||||
|                             requestPermission(context, call.arguments as String) |                             requestPermission(context, call.arguments as String) | ||||||
|                             result.success(true) |                             result.success(true) | ||||||
|                         } else { |                         } else { | ||||||
| @ -117,14 +117,13 @@ class MainActivity : FlutterActivity() { | |||||||
|                     "cancel_notification" -> { |                     "cancel_notification" -> { | ||||||
|                         try { |                         try { | ||||||
|                             val id = call.arguments as Int |                             val id = call.arguments as Int | ||||||
|                             Log.d(logTag,"cancel_notification id:$id") |  | ||||||
|                             mainService?.cancelNotification(id) |                             mainService?.cancelNotification(id) | ||||||
|                         }finally { |                         } finally { | ||||||
|                             result.success(true) |                             result.success(true) | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     else -> { |                     else -> { | ||||||
|                         result.error("-1","No such method",null) |                         result.error("-1", "No such method", null) | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @ -181,10 +180,13 @@ class MainActivity : FlutterActivity() { | |||||||
| 
 | 
 | ||||||
|     override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |     override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||||||
|         super.onActivityResult(requestCode, resultCode, data) |         super.onActivityResult(requestCode, resultCode, data) | ||||||
|         if (requestCode == MEDIA_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) { |         if (requestCode == MEDIA_REQUEST_CODE) { | ||||||
|             Log.d(logTag, "got mediaProjectionResultIntent ok") |             if (resultCode == Activity.RESULT_OK && data != null) { | ||||||
|                 mediaProjectionResultIntent = data |                 mediaProjectionResultIntent = data | ||||||
|                 initService() |                 initService() | ||||||
|  |             } else { | ||||||
|  |                 flutterMethodChannel.invokeMethod("on_media_projection_canceled", null) | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -82,8 +82,8 @@ class ServerPage extends StatelessWidget implements PageShape { | |||||||
| void checkService() async { | void checkService() async { | ||||||
|   FFI.invokeMethod("check_service"); // jvm |   FFI.invokeMethod("check_service"); // jvm | ||||||
|   // for Android 10/11,MANAGE_EXTERNAL_STORAGE permission from a system setting page |   // for Android 10/11,MANAGE_EXTERNAL_STORAGE permission from a system setting page | ||||||
|   if(PermissionManager.isWaitingFile() && !FFI.serverModel.fileOk){ |   if (PermissionManager.isWaitingFile() && !FFI.serverModel.fileOk) { | ||||||
|     PermissionManager.complete("file",await PermissionManager.check("file")); |     PermissionManager.complete("file", await PermissionManager.check("file")); | ||||||
|     debugPrint("file permission finished"); |     debugPrint("file permission finished"); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @ -280,15 +280,20 @@ class ConnectionManager extends StatelessWidget { | |||||||
|                       children: [ |                       children: [ | ||||||
|                         clientInfo(entry.value), |                         clientInfo(entry.value), | ||||||
|                         entry.value.isFileTransfer |                         entry.value.isFileTransfer | ||||||
|                             ?SizedBox.shrink() |                             ? SizedBox.shrink() | ||||||
|                             :IconButton(onPressed: (){ |                             : IconButton( | ||||||
|  |                                 onPressed: () { | ||||||
|                                   FFI.chatModel.changeCurrentID(entry.value.id); |                                   FFI.chatModel.changeCurrentID(entry.value.id); | ||||||
|                                   final bar = navigationBarKey.currentWidget; |                                   final bar = navigationBarKey.currentWidget; | ||||||
|                               if(bar!=null){ |                                   if (bar != null) { | ||||||
|                                     bar as BottomNavigationBar; |                                     bar as BottomNavigationBar; | ||||||
|                                     bar.onTap!(1); |                                     bar.onTap!(1); | ||||||
|                                   } |                                   } | ||||||
|                         }, icon: Icon(Icons.chat,color: MyTheme.accent80,)) |                                 }, | ||||||
|  |                                 icon: Icon( | ||||||
|  |                                   Icons.chat, | ||||||
|  |                                   color: MyTheme.accent80, | ||||||
|  |                                 )) | ||||||
|                       ], |                       ], | ||||||
|                     ), |                     ), | ||||||
|                     ElevatedButton.icon( |                     ElevatedButton.icon( | ||||||
| @ -406,6 +411,11 @@ void toAndroidChannelInit() { | |||||||
|             PermissionManager.complete(type, result); |             PermissionManager.complete(type, result); | ||||||
|             break; |             break; | ||||||
|           } |           } | ||||||
|  |         case "on_media_projection_canceled": | ||||||
|  |           { | ||||||
|  |             FFI.serverModel.stopService(); | ||||||
|  |             break; | ||||||
|  |           } | ||||||
|       } |       } | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       debugPrint("MethodCallHandler err:$e"); |       debugPrint("MethodCallHandler err:$e"); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user