gpt4 book ai didi

java - 如何使用 Assist API android m

转载 作者:太空宇宙 更新时间:2023-11-03 12:51:23 24 4
gpt4 key购买 nike

你好,我有一个使用 Assist API 打开的应用程序,它适用于 4.1 到 5.1.1,但是在 android M dev 预览中,当我在主页按钮上向上滑动时,我在屏幕上看到了卡片,但没有得到选项选择我想使用的应用程序如何在我的代码中解决这个问题这是我的 java 类:

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);

}

}

这是我的 list :

<?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>

任何帮助都会很棒

提前致谢!

最佳答案

当您长按 Marshmallow 设备中的主屏幕按钮时,它会调用在“设置”>“应用”>“配置应用”(工具栏上的设置图标)>“默认应用”>“辅助和语音输入”>“辅助应用”中设置的默认辅助应用。

Assist App settings screen

您可以检查您的应用是否设置为默认的 Assist 应用,并可以通过以下代码在您的 Activity 中将用户重定向到设置屏幕,用户可以在其中选择默认的 Assist 应用。

        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));
}

关于java - 如何使用 Assist API android m,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30519193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com