本文整理匯總了Java中android.app.SearchManager.getGlobalSearchActivity方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchManager.getGlobalSearchActivity方法的具體用法?Java SearchManager.getGlobalSearchActivity怎麽用?Java SearchManager.getGlobalSearchActivity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.SearchManager
的用法示例。
在下文中一共展示了SearchManager.getGlobalSearchActivity方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: get
import android.app.SearchManager; //導入方法依賴的package包/類
/**
* - * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
* - * provided by the same package which is set to be global search activity.
* - * If widgetCategory is not supported, or no such widget is found, returns the first widget
* - * provided by the package.
* -
*/
public static AppWidgetProviderInfo get(Context context) {
SearchManager searchManager =
(SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
ComponentName searchComponent = searchManager.getGlobalSearchActivity();
if (searchComponent == null) return null;
String providerPkg = searchComponent.getPackageName();
AppWidgetProviderInfo defaultWidgetForSearchPackage = null;
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) {
if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
return info;
} else if (defaultWidgetForSearchPackage == null) {
defaultWidgetForSearchPackage = info;
}
}
}
return defaultWidgetForSearchPackage;
}
示例2: startGoogleSearchActivity
import android.app.SearchManager; //導入方法依賴的package包/類
public static void startGoogleSearchActivity(View view) {
final Context context = view.getContext();
final SearchManager searchManager =
(SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
if (searchManager == null) {
return;
}
ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
if (globalSearchActivity == null) {
return;
}
Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(globalSearchActivity);
Bundle appSearchData = new Bundle();
appSearchData.putString("source", context.getPackageName());
intent.putExtra(SearchManager.APP_DATA, appSearchData);
intent.setSourceBounds(getViewBounds(view));
try {
context.startActivity(intent);
} catch (ActivityNotFoundException ex) {
ex.printStackTrace();
}
}
示例3: getSearchWidgetProvider
import android.app.SearchManager; //導入方法依賴的package包/類
/**
* Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
* provided by the same package which is set to be global search activity.
* If widgetCategory is not supported, or no such widget is found, returns the first widget
* provided by the package.
*/
public static AppWidgetProviderInfo getSearchWidgetProvider(Context context) {
SearchManager searchManager =
(SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
ComponentName searchComponent = searchManager.getGlobalSearchActivity();
if (searchComponent == null) return null;
String providerPkg = searchComponent.getPackageName();
AppWidgetProviderInfo defaultWidgetForSearchPackage = null;
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) {
if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
return info;
} else if (defaultWidgetForSearchPackage == null) {
defaultWidgetForSearchPackage = info;
}
}
}
return defaultWidgetForSearchPackage;
}