Java Question Need Help to develop java lib to handle key/buttons press

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi

I need some help to develop and library that to handle Key/Button presses on a specific Android Device. The device is a smart phone that has a panic button on the Top (Physical). The only documentation I have is as follows ;

B4X:
// BW Add for SOS/PTT Key Start
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_EXT_PTTDOWN = "com.BrighterWirelessMain.Main.PTTDown";
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_EXT_PTTUP = "com.BrighterWirelessMain.Main.PTTUp";
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_EXT_SOSDOWN = "com.BrighterWirelessMain.Main.SOSDown";
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_EXT_SOSUP = "com.BrighterWirelessMain.Main.SOSUp";
// BW Add for SOS/PTT Key end
Please note:
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_EXT_PTTDOWN = "com.BrighterWirelessMain.Main.PTTDown";
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_EXT_PTTUP = "com.BrighterWirelessMain.Main.PTTUp";
Both the PTT up and PTT down intent are useful.
int ACTION_DOWN getAction() value: the key has been pressed down.
int ACTION_UP getAction() value: the key has been released.
Please refer to the following link for more information:
http://developer.android.com/reference/android/view/KeyEvent.html

So, if anyone can help/assist I would be very grateful and would obviously reward such efforts.

Many thanks.

John.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Is that all the documentation?
It seems like all you need is an intent filter to receive this broadcast.

Either in a service with:
B4X:
AddReceiverText(myservice,
<intent-filter>
    <action android:name="com.BrighterWirelessMain.Main.PTTDown"/>
</intent-filter>)

or in an activity:

B4X:
AddActivityText(Main, <intent-filter>
  <action android:name="com.BrighterWirelessMain.Main.PTTDown" />
</intent-filter>)
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
Is that all the documentation?
It seems like all you need is an intent filter to receive this broadcast.

Either in a service with:
B4X:
AddReceiverText(myservice,
<intent-filter>
    <action android:name="com.BrighterWirelessMain.Main.PTTDown"/>
</intent-filter>)

or in an activity:

B4X:
AddActivityText(Main, <intent-filter>
  <action android:name="com.BrighterWirelessMain.Main.PTTDown" />
</intent-filter>)

Hi

Thanks for the reply. I have never used this method before. Where do I add the intent filters ?

Regards

John
 

thedesolatesoul

Expert
Licensed User
Longtime User
You need to add them in the manifest file (Project > Manifest Editor)
Then add a filter with the correct activity/service name.

When you test it, trigger the broadcast, (by pressing PTT button down),
but to check if your manifest triggered you should look at the activity starting intent.

Something like:

B4X:
Sub Activity_Resume
Dim in as Intent
in = Activity.GetStartingIntent
If in <> null Then
    Log(in.Action)
End If
End Sub

For more information about intents see this post: http://www.b4x.com/android/forum/threads/tutorial-inter-app-communication-with-intents.30608/
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi

This is very helpful. The button I am interested in is the SOSdown/SOSup. I have added both as intents in the manifest file and assigned each one to a separate service(I need to know how long the user has pressed it for).

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddPermission("android.permission.READ_SMS")
AddPermission("android.permission.WRITE_SMS")
AddPermission("android.permission.RECEIVE_SMS")
AddPermission("android.permission.CALL_PHONE")
AddPermission("android.permission.ACCESS_WIFI_STATE")
AddPermission("android.permission.CHANGE_WIFI_STATE")
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_FINE_LOCATION")
AddReceiverText(sms_manager,
<intent-filter>
    <action android:name="android.provider.Telephoney.SMS_RECEIVED" />
</intent-filter> )
AddServiceText(sosdown_manager,
<intent-filter>
    <action android:name="com.BrighterWirelessMain.Main.SOSDown" />
</intent-filter> )
AddServiceText(sosup_manager,
<intent-filter>
    <action android:name="com.BrighterWirelessMain.Main.SOSUp" />
</intent-filter> )

'End of default text.

In each of the services startup's I have a log statement to log the action. When I press the button, and release it neither of the services get called, btw the services are not started with in the APP as they need to be started by the intent receiver, right ?

I do understand it can be a bit of hassle helping someone out like this, but I am willing to compensate you.

Regards

John.
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
There is an app that has been written for the phone on Google Play store, I have installed it and it works fine, maybe I should have a look at the broadcast receiver or offer $$$ for this to be done as a library. I don't know why the services are not getting's triggered, I read your post on intents' very informative.

I will keep at it.
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
Solved !!!! Big Thanks to theDesolatesoul for taking the time to educate me in intents and also XverhelstX for writting
BroadcastReceiver !!!!
 
Top