List of usage examples for android.content Intent hasCategory
public boolean hasCategory(String category)
From source file:com.example.trumpetproject.activities.MainActivity.java
/** * Set the appropriate fragment given the state of the Activity and the Intent used to start it. * If the intent is a launcher intent the Splash Fragment is shown otherwise the SignIn Fragment is shown. * * @param intent Intent used to determine which Fragment is used. *//*from ww w.j a v a 2 s . com*/ private void setFragment(Intent intent) { Fragment fragment; String tag; if (intent != null && intent.hasCategory(Intent.CATEGORY_LAUNCHER)) { fragment = new SplashFragment(); tag = SPLASH_TAG; } else { fragment = new SignInFragment(); tag = SIGN_IN_TAG; } String currentTag = getCurrentFragmentTag(); if (currentTag == null || !currentTag.equals(tag)) { // only change frag if it's different than the current one loaded getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, tag).commit(); } }
From source file:org.pquery.Main.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // We only want single instance of this activity at top // If launched via a notification and by normal icon android can try //to create another copy of activity down stack // Don't want that so pop superfluus activity ///*from w ww. java2 s. c om*/ // http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ if (!isTaskRoot()) { final Intent intent = getIntent(); final String intentAction = intent.getAction(); if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) { Logger.w("Not root. Finishing Main Activity instead of launching"); finish(); return; } } // Make Jericho form parsing case sensitive Config.CurrentCompatibilityMode = Config.CompatibilityMode.MOZILLA; // Enable logging (if pref set) // If first time logging has been initialised a new log file will be created Logger.setEnable(Prefs.getDebug(this)); Logger.d("enter"); // Enable progress bar at top of window requestWindowFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.main2); String title = getIntent().getStringExtra("title"); if (title != null) doDialog = true; }
From source file:com.android.deskclock.alarms.AlarmStateManager.java
public static void handleIntent(Context context, Intent intent) { final String action = intent.getAction(); LogUtils.v("AlarmStateManager received intent " + intent); if (CHANGE_STATE_ACTION.equals(action)) { Uri uri = intent.getData();//from w w w . java 2s. c o m AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Can not change state for unknown instance: " + uri); return; } int globalId = getGlobalIntentId(context); int intentId = intent.getIntExtra(ALARM_GLOBAL_ID_EXTRA, -1); int alarmState = intent.getIntExtra(ALARM_STATE_EXTRA, -1); if (intentId != globalId) { LogUtils.i("IntentId: " + intentId + " GlobalId: " + globalId + " AlarmState: " + alarmState); // Allows dismiss/snooze requests to go through if (!intent.hasCategory(ALARM_DISMISS_TAG) && !intent.hasCategory(ALARM_SNOOZE_TAG)) { LogUtils.i("Ignoring old Intent"); return; } } if (intent.getBooleanExtra(FROM_NOTIFICATION_EXTRA, false)) { if (intent.hasCategory(ALARM_DISMISS_TAG)) { Events.sendAlarmEvent(R.string.action_dismiss, R.string.label_notification); } else if (intent.hasCategory(ALARM_SNOOZE_TAG)) { Events.sendAlarmEvent(R.string.action_snooze, R.string.label_notification); } } if (alarmState >= 0) { setAlarmState(context, instance, alarmState); } else { registerInstance(context, instance, true); } } else if (SHOW_AND_DISMISS_ALARM_ACTION.equals(action)) { Uri uri = intent.getData(); AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Null alarminstance for SHOW_AND_DISMISS"); // dismiss the notification final int id = intent.getIntExtra(AlarmNotifications.EXTRA_NOTIFICATION_ID, -1); if (id != -1) { NotificationManagerCompat.from(context).cancel(id); } return; } long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId); viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX); viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId); viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(viewAlarmIntent); deleteInstanceAndUpdateParent(context, instance); } }
From source file:com.stasbar.knowyourself.alarms.AlarmStateManager.java
public static void handleIntent(Context context, Intent intent) { final String action = intent.getAction(); LogUtils.v("AlarmStateManager received intent " + intent); if (CHANGE_STATE_ACTION.equals(action)) { Uri uri = intent.getData();//from www .j a v a 2 s . co m AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Can not change state for unknown instance: " + uri); return; } int globalId = getGlobalIntentId(context); int intentId = intent.getIntExtra(ALARM_GLOBAL_ID_EXTRA, -1); int alarmState = intent.getIntExtra(ALARM_STATE_EXTRA, -1); if (intentId != globalId) { LogUtils.i("IntentId: " + intentId + " GlobalId: " + globalId + " AlarmState: " + alarmState); // Allows dismiss/snooze requests to go through if (!intent.hasCategory(ALARM_DISMISS_TAG) && !intent.hasCategory(ALARM_SNOOZE_TAG)) { LogUtils.i("Ignoring old Intent"); return; } } if (alarmState >= 0) { setAlarmState(context, instance, alarmState); } else { registerInstance(context, instance, true); } } else if (SHOW_AND_DISMISS_ALARM_ACTION.equals(action)) { Uri uri = intent.getData(); AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Null alarminstance for SHOW_AND_DISMISS"); // dismiss the notification final int id = intent.getIntExtra(AlarmNotifications.EXTRA_NOTIFICATION_ID, -1); if (id != -1) { NotificationManagerCompat.from(context).cancel(id); } return; } long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; final Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Open DeskClock which is now positioned on the alarms tab. context.startActivity(viewAlarmIntent); deleteInstanceAndUpdateParent(context, instance); } }
From source file:com.wizardsofm.deskclock.alarms.AlarmStateManager.java
public static void handleIntent(Context context, Intent intent) { final String action = intent.getAction(); LogUtils.v("AlarmStateManager received intent " + intent); if (CHANGE_STATE_ACTION.equals(action)) { Uri uri = intent.getData();/* ww w. ja v a2s .c o m*/ AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Can not change state for unknown instance: " + uri); return; } int globalId = getGlobalIntentId(context); int intentId = intent.getIntExtra(ALARM_GLOBAL_ID_EXTRA, -1); int alarmState = intent.getIntExtra(ALARM_STATE_EXTRA, -1); if (intentId != globalId) { LogUtils.i("IntentId: " + intentId + " GlobalId: " + globalId + " AlarmState: " + alarmState); // Allows dismiss/snooze requests to go through if (!intent.hasCategory(ALARM_DISMISS_TAG) && !intent.hasCategory(ALARM_SNOOZE_TAG)) { LogUtils.i("Ignoring old Intent"); return; } } if (intent.getBooleanExtra(FROM_NOTIFICATION_EXTRA, false)) { if (intent.hasCategory(ALARM_DISMISS_TAG)) { Events.sendAlarmEvent(com.wizardsofm.deskclock.R.string.action_dismiss, com.wizardsofm.deskclock.R.string.label_notification); } else if (intent.hasCategory(ALARM_SNOOZE_TAG)) { Events.sendAlarmEvent(com.wizardsofm.deskclock.R.string.action_snooze, com.wizardsofm.deskclock.R.string.label_notification); } } if (alarmState >= 0) { setAlarmState(context, instance, alarmState); } else { registerInstance(context, instance, true); } } else if (SHOW_AND_DISMISS_ALARM_ACTION.equals(action)) { Uri uri = intent.getData(); AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Null alarminstance for SHOW_AND_DISMISS"); // dismiss the notification final int id = intent.getIntExtra(AlarmNotifications.EXTRA_NOTIFICATION_ID, -1); if (id != -1) { NotificationManagerCompat.from(context).cancel(id); } return; } long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; final Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId) .putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Open DeskClock which is now positioned on the alarms tab. context.startActivity(viewAlarmIntent); deleteInstanceAndUpdateParent(context, instance); } }
From source file:com.detroitteatime.autocarfinder.Main.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainLayout = (LinearLayout) this.getLayoutInflater().inflate(R.layout.main, null); setContentView(mainLayout);/*from w w w. ja va 2 s .com*/ // Possible work around for market launches. See // http://code.google.com/p/android/issues/detail?id=2373 // for more details. Essentially, the market launches the main activity // on top of other activities. // we never want this to happen. Instead, we check if we are the root // and if not, we finish. if (!isTaskRoot()) { final Intent intent = getIntent(); final String intentAction = intent.getAction(); if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) { // Log.w("My Code", // "Main Activity is not the root. Finishing Main Activity instead of launching."); finish(); return; } } // set up buttons start = (Button) findViewById(R.id.start); manual = (Button) findViewById(R.id.manual); // progress = (ProgressBar) findViewById(R.id.progressBar1); start.setOnClickListener(this); start.getBackground().setColorFilter(Color.parseColor(COLOR), PorterDuff.Mode.MULTIPLY); manual.setOnClickListener(this); manual.getBackground().setColorFilter(Color.parseColor(COLOR), PorterDuff.Mode.MULTIPLY); monitor = (FrameLayout) findViewById(R.id.frameLayout1); data1 = this.getSharedPreferences("storage", 0); editor1 = data1.edit(); // firstTime = data1.getBoolean("first_time", true); editor1.putBoolean("first_time", false); editor1.commit(); pi = PendingIntent.getActivity(this, 0, new Intent(this, Main.class), 0); data1 = getSharedPreferences("storage", 0); editor1 = data1.edit(); // set a global layout listener which will be called when the layout // pass is completed and the view is drawn FragmentManager myFragmentManager = getSupportFragmentManager(); mySupportMapFragment = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.map); if (MapsInitializer.initialize(this) != ConnectionResult.SUCCESS) { Toast.makeText(this, "Map failed to initialize.", Toast.LENGTH_SHORT).show(); } map = mySupportMapFragment.getMap(); manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Define the criteria how to select the locatioin provider -> use // default criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); provider = manager.getBestProvider(criteria, false); manager.requestLocationUpdates(provider, 1000, 1, this); navigate = (Button) findViewById(R.id.navigate); navigate.setOnClickListener(this); type = (Button) findViewById(R.id.satellite); type.setOnClickListener(this); }
From source file:orbin.deskclock.alarms.AlarmStateManager.java
public static void handleIntent(Context context, Intent intent) { final String action = intent.getAction(); LogUtils.v("AlarmStateManager received intent " + intent); if (CHANGE_STATE_ACTION.equals(action)) { Uri uri = intent.getData();//from ww w . j av a 2 s. c o m AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Can not change state for unknown instance: " + uri); return; } int globalId = getGlobalIntentId(context); int intentId = intent.getIntExtra(ALARM_GLOBAL_ID_EXTRA, -1); int alarmState = intent.getIntExtra(ALARM_STATE_EXTRA, -1); if (intentId != globalId) { LogUtils.i("IntentId: " + intentId + " GlobalId: " + globalId + " AlarmState: " + alarmState); // Allows dismiss/snooze requests to go through if (!intent.hasCategory(ALARM_DISMISS_TAG) && !intent.hasCategory(ALARM_SNOOZE_TAG)) { LogUtils.i("Ignoring old Intent"); return; } } if (intent.getBooleanExtra(FROM_NOTIFICATION_EXTRA, false)) { if (intent.hasCategory(ALARM_DISMISS_TAG)) { Events.sendAlarmEvent(R.string.action_dismiss, R.string.label_notification); } else if (intent.hasCategory(ALARM_SNOOZE_TAG)) { Events.sendAlarmEvent(R.string.action_snooze, R.string.label_notification); } } if (alarmState >= 0) { setAlarmState(context, instance, alarmState); } else { registerInstance(context, instance, true); } } else if (SHOW_AND_DISMISS_ALARM_ACTION.equals(action)) { Uri uri = intent.getData(); AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Null alarminstance for SHOW_AND_DISMISS"); // dismiss the notification final int id = intent.getIntExtra(AlarmNotifications.EXTRA_NOTIFICATION_ID, -1); if (id != -1) { NotificationManagerCompat.from(context).cancel(id); } return; } long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; final Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId) .putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Open DeskClock which is now positioned on the alarms tab. context.startActivity(viewAlarmIntent); deleteInstanceAndUpdateParent(context, instance); } }
From source file:com.androidinspain.deskclock.alarms.AlarmStateManager.java
public static void handleIntent(Context context, Intent intent) { final String action = intent.getAction(); LogUtils.v("AlarmStateManager received intent " + intent); if (CHANGE_STATE_ACTION.equals(action)) { Uri uri = intent.getData();/*w w w .ja va 2 s .c om*/ AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Can not change state for unknown instance: " + uri); return; } int globalId = DataModel.getDataModel().getGlobalIntentId(); int intentId = intent.getIntExtra(ALARM_GLOBAL_ID_EXTRA, -1); int alarmState = intent.getIntExtra(ALARM_STATE_EXTRA, -1); if (intentId != globalId) { LogUtils.i("IntentId: " + intentId + " GlobalId: " + globalId + " AlarmState: " + alarmState); // Allows dismiss/snooze requests to go through if (!intent.hasCategory(ALARM_DISMISS_TAG) && !intent.hasCategory(ALARM_SNOOZE_TAG)) { LogUtils.i("Ignoring old Intent"); return; } } if (intent.getBooleanExtra(FROM_NOTIFICATION_EXTRA, false)) { if (intent.hasCategory(ALARM_DISMISS_TAG)) { Events.sendAlarmEvent(com.androidinspain.deskclock.R.string.action_dismiss, com.androidinspain.deskclock.R.string.label_notification); } else if (intent.hasCategory(ALARM_SNOOZE_TAG)) { Events.sendAlarmEvent(com.androidinspain.deskclock.R.string.action_snooze, com.androidinspain.deskclock.R.string.label_notification); } } if (alarmState >= 0) { setAlarmState(context, instance, alarmState); } else { registerInstance(context, instance, true); } } else if (SHOW_AND_DISMISS_ALARM_ACTION.equals(action)) { Uri uri = intent.getData(); AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Null alarminstance for SHOW_AND_DISMISS"); // dismiss the notification final int id = intent.getIntExtra(AlarmNotifications.EXTRA_NOTIFICATION_ID, -1); if (id != -1) { NotificationManagerCompat.from(context).cancel(id); } return; } long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; final Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId) .putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Open DeskClock which is now positioned on the alarms tab. context.startActivity(viewAlarmIntent); deleteInstanceAndUpdateParent(context, instance); } }
From source file:com.android.launcher3.Utilities.java
/** * Returns true if the intent is a valid launch intent for a launcher activity of an app. * This is used to identify shortcuts which are different from the ones exposed by the * applications' manifest file./*from w w w .j av a 2s . com*/ * * @param launchIntent The intent that will be launched when the shortcut is clicked. */ public static boolean isLauncherAppTarget(Intent launchIntent) { if (launchIntent != null && Intent.ACTION_MAIN.equals(launchIntent.getAction()) && launchIntent.getComponent() != null && launchIntent.getCategories() != null && launchIntent.getCategories().size() == 1 && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && TextUtils.isEmpty(launchIntent.getDataString())) { // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE. Bundle extras = launchIntent.getExtras(); if (extras == null) { return true; } else { Set<String> keys = extras.keySet(); return keys.size() == 1 && keys.contains(ItemInfo.EXTRA_PROFILE); } } ; return false; }