4

Hello I have a app that open using the Assist API it works for 4.1 to 5.1.1 however in the android M dev preview when I swipe up on the home button i get the cards on screen and don't get the option the pick what app I want to use How to I fix this in my code heres my java class:

package com.d4a.toolbelt;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.d4a.toolbelt.R;

public class QuickLaunch extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quick_launch);
    }

     /** Called when the user clicks the  music button */
     public void music(View view) {
         Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         startActivity(intent);


     }





/** Called when the user clicks the play button */
public void play(View view) {
    Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");
    startActivity(launchIntent);
    }



/** Called when the user clicks the web button */
public void web(View view) {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com/"));
      startActivity(browserIntent);

}

       /** Called when the user clicks the email button */
public void email(View view) {
     Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.gm");
     startActivity(intent);

} 

/** Called when the user clicks the sms button */
public void chat(View view) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
 intent.setComponent(new ComponentName("com.d4a.sms","de.ub0r.android.smsdroid.ConversationListActivity"));
 intent.putExtra("grace", "Hi");
 startActivity(intent);


}


/** Called when the user clicks the settings button */
public void settings(View view) {
     Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.settings");
     startActivity(intent);

}




/** Called when the user clicks the camara button */
public void cam(View view) {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    startActivityForResult(intent, 0);

}

/** Called when the user clicks the video camara button */
public void video_cam(View view) {
    Intent intent = new Intent("android.media.action.VIDEO_CAPTURE");
    startActivityForResult(intent, 0);

}
/** Called when the user clicks the google now  button */
public void now(View view) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.googlequicksearchbox");
startActivity(intent);

} 

}

and heres my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.d4a.toolbelt"
    android:versionCode="5"
    android:versionName="1.5" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="22" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.d4a.toolbelt.QuickLaunch" android:launchMode="singleInstance" android:theme="@style/Theme.Transparent">
                      <intent-filter>
                <action android:name="android.intent.action.ASSIST" />
                <action android:name="android.intent.extra.ASSIST_CONTEXT" />
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

any help would be awesome

Thanks in advance!

Phoneswapshop
  • 1,367
  • 8
  • 24
  • 47

2 Answers2

5

When you long press home button in Marshmallow device, it invokes default Assist app which is set at Settings > Apps > Configure apps (settings icon on the toolbar) > Default Apps > Assist and voice input > Assist app.

Assist App settings screen

You can check whether your app is set as default Assist App or not and can redirect user to the settings screen through below code in your activity, where user can select default Assist app.

        String assistant =
                Settings.Secure.getString(getContentResolver(),
                        "voice_interaction_service");

        boolean areWeGood = false;

        if (assistant != null) {
            ComponentName cn = ComponentName.unflattenFromString(assistant);

            if (cn.getPackageName().equals(getPackageName())) {
                areWeGood = true;
            }
        }

        if (areWeGood) {
           // your app has already been set as Assist app.
            finish();
        } else {
            // your app has not been set as Assist app. Redirect user to the settings screen. 
            startActivity(new Intent(Settings.ACTION_VOICE_INPUT_SETTINGS));
        }
Bharat Dodeja
  • 1,137
  • 16
  • 22
  • 1
    Reading from the `voice_interaction_service` setting didn't work for me in Android 7.1; it returned an empty string when my app was set as the assist app. – Sam Jan 27 '17 at 10:36
  • instead of `"voice_interaction_service"` use `"assistant"` `Settings.Secure.getString(getContentResolver(), "assistant")`; – Deni Erdyneev Feb 23 '21 at 13:15
0

just a heads My app works again in M preview 2 and 3 without any changes!

I hope this will help someone else out!

Phoneswapshop
  • 1,367
  • 8
  • 24
  • 47