Accessing Phone Buttons

johnthomcode

Member
Licensed User
Longtime User
Hi,

I've got an LG Optimus S670 (LG Optimus S LS670 Purple Cell Phones & Mobile Phones - LG Electronics US), and it has external camera and voice command buttons. I would like to make an app to respond to a button being pushed, but don't know how to get it. I searched "buttons", but it's pulling up too much. I looked at the help, but I can't find where this might be at. I did find this (Button Shortcut ~ Android Application v1.6.0 By Notes | Tools) which allows you to...

Make your own button shortcuts. Replace long press functions of your camera button and search button.

Long press camera button or search button to launch your favorite applications like Contacts and Dialer.

Devs can add custom activity for shortcut.

Can I make my own version with BASIC4Android?

Thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can add an "intent filter" to your activity and let it handle a long search button press by editing AndroidManifest.xml (in Objects folder) and adding the following node:
B4X:
<intent-filter>
                <action android:name="android.intent.action.SEARCH_LONG_PRESS" />
                <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Add it right after the current intent filter.
Change AndroidManifest.xml to be read-only or the IDE will overwrite it.

The camera button is a different kind of intent. It is possible to handle it with a Service.
 
Upvote 0

johnthomcode

Member
Licensed User
Longtime User
Hi,

Thanks for your help. Is this used only to start an application, or can it be accessed from within the application? Also, does the application have to have previously ran for it to work?

I downloaded this (http://www.b4x.com/forum/basic4andr...rials/6891-take-pictures-internal-camera.html) ZIP and added the intent filter below the existing intent filter:

B4X:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="anywheresoftware.b4a.samples.camera"
      android:versionCode="1"
      android:versionName=""
     android:installLocation="preferExternal">
      <uses-sdk android:minSdkVersion="4" />
      <supports-screens
          android:largeScreens="true"
          android:normalScreens="true"
          android:smallScreens="true"
          android:anyDensity="true"/>
    <application android:icon="@drawable/icon" android:label="Camera example">
       
        <activity android:windowSoftInputMode="stateHidden" android:launchMode="singleTop" android:name=".main"
                  android:label="Camera example" android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
         <intent-filter>
                <action android:name="android.intent.action.SEARCH_LONG_PRESS" />
                <category android:name="android.intent.category.DEFAULT" />
         </intent-filter>         
        </activity>
        

    </application>
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>


</manifest>

I couldn't get it to launch the application though (tried both buttons, they worked as they did previously).

I've been searching, but can't find any examples. If you could point me towards any or help explain I'd greatly appreciate it!

Thanks!
 
Upvote 0

johnthomcode

Member
Licensed User
Longtime User
Hi,

Thanks for the explanation. Yes, I did it again and got the same results. The file is read only and still has the original content (see screenshot). Would debug settings alter the behavior at all?

Thanks!
 

Attachments

  • screenshot.jpg
    screenshot.jpg
    13.9 KB · Views: 259
Upvote 0

johnthomcode

Member
Licensed User
Longtime User
Hi,

Thanks for your help. I tried that (code below), but still no change.

B4X:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="anywheresoftware.b4a.samples.camera"
      android:versionCode="1"
      android:versionName=""
     android:installLocation="preferExternal">
      <uses-sdk android:minSdkVersion="4" />
      <supports-screens
          android:largeScreens="true"
          android:normalScreens="true"
          android:smallScreens="true"
          android:anyDensity="true"/>
    <application android:icon="@drawable/icon" android:label="Camera example">
       
        <activity android:windowSoftInputMode="stateHidden" android:launchMode="singleTop" android:name=".main"
                  android:label="Camera example" android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
         <intent-filter android:priority="10000">
                <action android:name="android.intent.action.SEARCH_LONG_PRESS" />
                <category android:name="android.intent.category.DEFAULT" />
         </intent-filter>         
        </activity>
        

    </application>
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>


</manifest>

Is it maybe just my phone this method doesn't work on? Android 2.2.2

Thanks!
 
Upvote 0

johnthomcode

Member
Licensed User
Longtime User
Oops!

It does work, just not where I was expecting. If I long click on the search button (with the magnifying glass) then it comes up.

Is it also possible to do this with the voice search button on the right side of my phone? In the picture (original post link) these buttons are on the right side of the phone. From the top down (on the right side), it's volume up, volume down, voice search, and camera.

When I click on the voice search, it starts "Voice Dialer".

Thanks!
 
Upvote 0
Top