大佬教程收集整理的这篇文章主要介绍了java – 如何使用Assist API android m,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
你好我有一个应用程序打开使用它适用于4.1到5.1.1的Assist API但是在Android M开发预览当我在主页按钮上向上滑动时我得到了屏幕上的卡片并且没有得到选项什么选择什么应用程序我想使用如何在我的代码中修复此问题继承我的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);
}
}
并且我的清单是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://scheR_861_11845@as.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应用程序,该应用程序在设置>中设置.应用>配置应用程序(工具栏上的设置图标)>默认应用>辅助和语音输入>协助应用程序.
您可以检查您的应用是否设置为默认的Assist App,并可以通过活动中的以下代码将用户重定向到设置屏幕,用户可以在其中选择默认的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全部内容,希望文章能够帮你解决java – 如何使用Assist API android m所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。