@@ -24,6 +24,7 @@ pub struct JPeripheral<'a: 'b, 'b> {
2424 get_notifications : JMethodID < ' a > ,
2525 read_descriptor : JMethodID < ' a > ,
2626 write_descriptor : JMethodID < ' a > ,
27+ get_device_name : JMethodID < ' a > ,
2728 env : & ' b JNIEnv < ' a > ,
2829}
2930
@@ -102,6 +103,8 @@ impl<'a: 'b, 'b> JPeripheral<'a, 'b> {
102103 "writeDescriptor" ,
103104 "(Ljava/util/UUID;Ljava/util/UUID;[BI)Lio/github/gedgygedgy/rust/future/Future;" ,
104105 ) ?;
106+ let get_device_name =
107+ env. get_method_id ( class, "getDeviceName" , "()Ljava/lang/String;" ) ?;
105108 Ok ( Self {
106109 internal : obj,
107110 connect,
@@ -114,6 +117,7 @@ impl<'a: 'b, 'b> JPeripheral<'a, 'b> {
114117 get_notifications,
115118 read_descriptor,
116119 write_descriptor,
120+ get_device_name,
117121 env,
118122 } )
119123 }
@@ -265,6 +269,24 @@ impl<'a: 'b, 'b> JPeripheral<'a, 'b> {
265269 JFuture :: from_env ( self . env , future_obj)
266270 }
267271
272+ pub fn get_device_name ( & self ) -> Result < Option < String > > {
273+ let obj = self
274+ . env
275+ . call_method_unchecked (
276+ self . internal ,
277+ self . get_device_name ,
278+ JavaType :: Object ( "Ljava/lang/String;" . to_string ( ) ) ,
279+ & [ ] ,
280+ ) ?
281+ . l ( ) ?;
282+ if obj. is_null ( ) {
283+ Ok ( None )
284+ } else {
285+ let name_str = self . env . get_string ( obj. into ( ) ) ?;
286+ Ok ( Some ( name_str. into ( ) ) )
287+ }
288+ }
289+
268290 pub fn write_descriptor (
269291 & self ,
270292 characteristic : JUuid < ' a , ' b > ,
@@ -732,8 +754,8 @@ impl<'a: 'b, 'b> TryFrom<JScanResult<'a, 'b>> for (BDAddr, Option<PeripheralProp
732754 Some ( PeripheralProperties {
733755 address : addr,
734756 address_type : None ,
735- local_name : device_name,
736- advertisement_name : None ,
757+ local_name : device_name. clone ( ) ,
758+ advertisement_name : device_name ,
737759 tx_power_level,
738760 manufacturer_data,
739761 service_data,
0 commit comments