Skip to first unread message

Tim Carter

unread,
Aug 9, 2017, 1:08:38 PM8/9/17
to MIT App Inventor Forum
Leading on from my initial enquiry here:

Using Google Now on your Android phone you can start several "Google" apps with voice commands.

It is possible to convert your AI2 app for the same thing. For the purposes of this howto:

The apk filename is  MyVoiceApp.apk

The appname is "My Voice App"   << what you see in the App Name on Screen 1 Designer

1. What you will need:

  • A PC
  • apktool (Windows/Linux) or AppToMarket (Windows)
  • Your apk file
2. Decode your apk using your preferred decoder/encoder

3. Browse to the res folder in the decoded apk and create a new folder called xml

4. Browse into the xml folder you have just created and create a new text file called searchable.xml

5. Open up searchable.xml and copy and paste this into it:

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="My Voice App" >
</searchable>

whilst replacing "My Voice App" with the appname of your app

Save searchable.xml.

6. In the root folder of your expanded apk, find the file "AndroidManifest.xml" and open it with your preferred text editor.

It may look something like this:  (the apkfilename and the appname should be correct in this file and match that of your apk)

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="appinventor.ai_XXXuserXXX.MyVoiceApp" platformBuildVersionCode="22" platformBuildVersionName="5.1.1-1819727">
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application android:debuggable="false" android:icon="@drawable/ya" android:label="My Voice App" android:name="com.google.appinventor.components.runtime.multidex.MultiDexApplication">
        <activity android:configChanges="keyboard|keyboardHidden|orientation" android:name=".Screen1" android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

7. You now need to add a new intent filter section and some configuration lines. Do this just above the <intent-filter> line

This is what you should add:

            <intent-filter>
<action android:name="android.intent.action.SEARCH" />
            </intent-filter>
            <meta-data android:name="android.app.searchable"
            android:resource="@xml/searchable"/>

and your resultant AndroidManifest.xml file should then look like this:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="appinventor.ai_user.MyVoiceApp" platformBuildVersionCode="22" platformBuildVersionName="5.1.1-1819727">
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application android:debuggable="false" android:icon="@drawable/ya" android:label="My Voice App" android:name="com.google.appinventor.components.runtime.multidex.MultiDexApplication">
        <activity android:configChanges="keyboard|keyboardHidden|orientation" android:name=".Screen1" android:windowSoftInputMode="stateHidden">
            <intent-filter>
<action android:name="android.intent.action.SEARCH" />
            </intent-filter>
            <meta-data android:name="android.app.searchable"
            android:resource="@xml/searchable"/>            
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

Once this is done, save AndroidManifest.xml, and your work on editing the apk is done!

8. Now re-encode your apk using your preferred encoder/decoder, deal with the signing and zip aligning of apk as needed.


Sideload you new apk onto your device

Get Google Now running and ask it to: "run 'My Voice App'" or "start 'My Voice App'"  (both seem to work for different things???)

Your app should open up from closed or in the background.


If you need help with how to use apktool, just ask.

Tim 


Credits due to the original poster on techrepublic here



Reply all
Reply to author
Forward
0 new messages