本文整理汇总了Java中android.view.MenuItem.getIntent方法的典型用法代码示例。如果您正苦于以下问题:Java MenuItem.getIntent方法的具体用法?Java MenuItem.getIntent怎么用?Java MenuItem.getIntent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MenuItem
的用法示例。
在下文中一共展示了MenuItem.getIntent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logMenuItemToFirebase
import android.view.MenuItem; //导入方法依赖的package包/类
void logMenuItemToFirebase(@NonNull MenuItem item) {
if (firebaseEnabled) {
final Intent intent = item.getIntent();
if (intent == null) {
Log.i(TAG, "logMenuItemToFirebase: Invalid menu item. Intent must be supplied!");
return;
}
final FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(this);
final Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, intent.getStringExtra(Kolibri.EXTRA_ID));
if (intent.hasExtra(Intent.EXTRA_TITLE)) {
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME,
intent.getStringExtra(Intent.EXTRA_TITLE));
}
bundle
.putString(FirebaseAnalytics.Param.CONTENT_TYPE, intent.getStringExtra(Kolibri.EXTRA_ID));
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
}
}
示例2: onNavigationItemSelected
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
KolibriApp.getInstance().logMenuItemToFirebase(item);
final MenuItem previouslySelected = getSelectedMenuItem();
final Intent intent = item.getIntent();
final PackageManager packageManager = getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
// Notify custom components in case they are activities
KolibriApp.getInstance().logEvent(null, intent.getData().toString());
// Post to navigation view and select previously one menu item
// because we won't to select components that are handled by activities.
navigationView.post(new Runnable() {
@Override
public void run() {
item.setChecked(false);
previouslySelected.setChecked(true);
}
});
return false;
}
notifyComponenets(intent);
drawer.closeDrawer(GravityCompat.START);
return true;
}
示例3: onContextItemSelected
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean onContextItemSelected(MenuItem item) {
if (item.getIntent() != null) {
startActivity(item.getIntent());
}
return true;
}