本文整理匯總了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;
}