-1

I wonder if there is a way to programmatically detect if the pen is physically in the phone (Samsung Note 8/9)? Like getting readings directly from the sensor?

I am aware that there is the SpenPenDetachmentListener which catches detach and attach events. But I need to get a status of the pen without actually taking the pen out.

I also tried using the InputDevicesManager to detect the pen as an input device, yet this won't tell whether the pen is attached or not.

Any idea would be appreciated!

Lumi Wang
  • 73
  • 3
  • 10

1 Answers1

1

From SPEN sdk 2.2 onwards you can detect when spen is detached. You need to setup SPEN sdk and use below method to listen to detach event.

mSPenEventLibrary.registerSPenDetachmentListener( mContext, new SPenDetachmentListener()
{
    @Override
    public void onSPenDetached(boolean bDetached) 
        {
        if( bDetached ) 
                   Toast.makeText( mContext, " SPen Detached",
                                 Toast.LENGTH_SHORT ).show();
        else 
                   Toast.makeText(mContext, "S Pen Inserted", Toast.LENGTH_SHORT).show();
    }
} );

You can read more documentation from here

karan
  • 8,637
  • 3
  • 41
  • 78
  • I wonder if it would be activated if the pen was never attached. But thanks for the idea. Would check it out. – Lumi Wang Feb 11 '19 at 13:17
  • check this documentation you might find something https://developer.samsung.com/html/techdoc/ProgrammingGuide_Pen.pdf – karan Feb 11 '19 at 13:28
  • Yes I was checking that guide. Thanks! – Lumi Wang Feb 11 '19 at 14:14
  • Yes you are right, it turns out that the `DetachmentListener` doesn't require a real detachment action. It would tell directly if the pen is detached or attached. – Lumi Wang Feb 12 '19 at 11:25