List of usage examples for android.content Intent getComponent
public @Nullable ComponentName getComponent()
From source file:com.android.launcher3.Launcher.java
public boolean startActivitySafely(View v, Intent intent, ItemInfo item) { if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); return false; }/*from ww w .j a va 2 s . com*/ // Only launch using the new animation if the shortcut has not opted out (this is a // private contract between launcher and may be ignored in the future). boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); Bundle optsBundle = useLaunchAnimation ? getActivityLaunchOptions(v) : null; UserHandleCompat user = null; if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); user = UserManagerCompat.getInstance(this).getUserForSerialNumber(serialNumber); } // Prepare intent intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (v != null) { intent.setSourceBounds(getViewBounds(v)); } try { if (Utilities.ATLEAST_MARSHMALLOW && item != null && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) && ((ShortcutInfo) item).promisedIntent == null) { // Shortcuts need some special checks due to legacy reasons. startShortcutIntentSafely(intent, optsBundle, item); } else if (user == null || user.equals(UserHandleCompat.myUserHandle())) { // Could be launching some bookkeeping activity startActivity(intent, optsBundle); if (isAllAppsVisible()) { predictiveAppsProvider.updateComponentCount(intent.getComponent()); } } else { LauncherAppsCompat.getInstance(this).startActivityForProfile(intent.getComponent(), user, intent.getSourceBounds(), optsBundle); } return true; } catch (ActivityNotFoundException | SecurityException e) { Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Unable to launch. tag=" + item + " intent=" + intent, e); } return false; }
From source file:android.app.Activity.java
final void attach(Context context, ActivityThread aThread, Instrumentation instr, IBinder token, int ident, Application application, Intent intent, ActivityInfo info, CharSequence title, Activity parent, String id, NonConfigurationInstances lastNonConfigurationInstances, Configuration config) { attachBaseContext(context);//from w ww.j a v a 2 s .co m mFragments.attachActivity(this, mContainer, null); mWindow = PolicyManager.makeNewWindow(this); mWindow.setCallback(this); mWindow.getLayoutInflater().setPrivateFactory(this); if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { mWindow.setSoftInputMode(info.softInputMode); } if (info.uiOptions != 0) { mWindow.setUiOptions(info.uiOptions); } mUiThread = Thread.currentThread(); mMainThread = aThread; mInstrumentation = instr; mToken = token; mIdent = ident; mApplication = application; mIntent = intent; mComponent = intent.getComponent(); mActivityInfo = info; mTitle = title; mParent = parent; mEmbeddedID = id; mLastNonConfigurationInstances = lastNonConfigurationInstances; mWindow.setWindowManager((WindowManager) context.getSystemService(Context.WINDOW_SERVICE), mToken, mComponent.flattenToString(), (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0); if (mParent != null) { mWindow.setContainer(mParent.getWindow()); } mWindowManager = mWindow.getWindowManager(); mCurrentConfig = config; }
From source file:com.klinker.android.launcher.launcher3.Launcher.java
private boolean startActivity(View v, Intent intent, Object tag) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try {//from w w w . j av a2 s . co m // Only launch using the new animation if the shortcut has not opted out (this is a // private contract between launcher and may be ignored in the future). boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); UserManagerCompat userManager = UserManagerCompat.getInstance(this); UserHandleCompat user = null; if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); user = userManager.getUserForSerialNumber(serialNumber); } Bundle optsBundle = null; if (useLaunchAnimation) { ActivityOptions opts = null; if (sClipRevealMethod != null) { // TODO: call method directly when Launcher3 can depend on M APIs int left = 0, top = 0; int width = v.getMeasuredWidth(), height = v.getMeasuredHeight(); if (v instanceof TextView) { // Launch from center of icon, not entire view Drawable icon = Workspace.getTextViewIcon((TextView) v); if (icon != null) { Rect bounds = icon.getBounds(); left = (width - bounds.width()) / 2; top = v.getPaddingTop(); width = bounds.width(); height = bounds.height(); } } try { opts = (ActivityOptions) sClipRevealMethod.invoke(null, v, left, top, width, height); } catch (IllegalAccessException e) { Log.d(TAG, "Could not call makeClipRevealAnimation: " + e); sClipRevealMethod = null; } catch (InvocationTargetException e) { Log.d(TAG, "Could not call makeClipRevealAnimation: " + e); sClipRevealMethod = null; } } if (opts == null && !Utilities.isLmpOrAbove()) { // Below L, we use a scale up animation opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); } else if (opts == null && Utilities.isLmpMR1()) { // On L devices, we use the device default slide-up transition. // On L MR1 devices, we a custom version of the slide-up transition which // doesn't have the delay present in the device default. opts = ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim); } optsBundle = opts != null ? opts.toBundle() : null; } if (user == null || user.equals(UserHandleCompat.myUserHandle())) { // Could be launching some bookkeeping activity startActivity(intent, optsBundle); } else { // TODO Component can be null when shortcuts are supported for secondary user launcherApps.startActivityForProfile(intent.getComponent(), user, intent.getSourceBounds(), optsBundle); } return true; } catch (SecurityException e) { Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Launcher does not have the permission to launch " + intent + ". Make sure to create a MAIN intent-filter for the corresponding activity " + "or use the exported attribute for this activity. " + "tag=" + tag + " intent=" + intent, e); } return false; }
From source file:xyz.klinker.blur.launcher3.Launcher.java
private boolean startActivity(View v, Intent intent, Object tag) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try {// w w w . j a v a 2 s .c o m // Only launch using the new animation if the shortcut has not opted out (this is a // private contract between launcher and may be ignored in the future). boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); UserManagerCompat userManager = UserManagerCompat.getInstance(this); UserHandleCompat user = null; if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); user = userManager.getUserForSerialNumber(serialNumber); } Bundle optsBundle = null; if (useLaunchAnimation) { ActivityOptions opts = null; if (Utilities.ATLEAST_MARSHMALLOW) { int left = 0, top = 0; int width = v.getMeasuredWidth(), height = v.getMeasuredHeight(); if (v instanceof TextView) { // Launch from center of icon, not entire view Drawable icon = Workspace.getTextViewIcon((TextView) v); if (icon != null) { Rect bounds = icon.getBounds(); left = (width - bounds.width()) / 2; top = v.getPaddingTop(); width = bounds.width(); height = bounds.height(); } } opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height); } else if (!Utilities.ATLEAST_LOLLIPOP) { // Below L, we use a scale up animation opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); } else if (Utilities.ATLEAST_LOLLIPOP_MR1) { // On L devices, we use the device default slide-up transition. // On L MR1 devices, we a custom version of the slide-up transition which // doesn't have the delay present in the device default. opts = ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim); } optsBundle = opts != null ? opts.toBundle() : null; } if (user == null || user.equals(UserHandleCompat.myUserHandle())) { StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy(); try { // Temporarily disable deathPenalty on all default checks. For eg, shortcuts // containing file Uris would cause a crash as penaltyDeathOnFileUriExposure // is enabled by default on NYC. StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build()); // Could be launching some bookkeeping activity startActivity(intent, optsBundle); } finally { StrictMode.setVmPolicy(oldPolicy); } } else { // TODO Component can be null when shortcuts are supported for secondary user launcherApps.startActivityForProfile(intent.getComponent(), user, intent.getSourceBounds(), optsBundle); } return true; } catch (SecurityException e) { if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) { // Due to legacy reasons, direct call shortcuts require Launchers to have the // corresponding permission. Show the appropriate permission prompt if that // is the case. if (intent.getComponent() == null && Intent.ACTION_CALL.equals(intent.getAction()) && checkSelfPermission( Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { // TODO: Rename sPendingAddItem to a generic name. sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent, 0, (ItemInfo) tag); requestPermissions(new String[] { Manifest.permission.CALL_PHONE }, REQUEST_PERMISSION_CALL_PHONE); return false; } } Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Launcher does not have the permission to launch " + intent + ". Make sure to create a MAIN intent-filter for the corresponding activity " + "or use the exported attribute for this activity. " + "tag=" + tag + " intent=" + intent, e); } return false; }
From source file:org.restcomm.android.sdk.RCDevice.java
void onNotificationIntent(Intent intent) { String intentAction = intent.getAction(); //if (!intentAction.equals(ACTION_NOTIFICATION_MESSAGE_DEFAULT)) { if (intentAction.equals(ACTION_NOTIFICATION_CALL_DEFAULT) || intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_VIDEO) || intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_AUDIO) || intentAction.equals(ACTION_NOTIFICATION_CALL_DECLINE) || intentAction.equals(ACTION_NOTIFICATION_CALL_DELETE)) { // The user has acted on a call notification, let's cancel it String username = intent.getStringExtra(EXTRA_DID).replaceAll(".*?sip:", "").replaceAll("@.*$", ""); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(callNotifications.get(username)); //callNotifications.remove(username); activeCallNotification = false;/*from www .jav a 2 s . co m*/ } Intent actionIntent = null; /* if (intentAction.equals(ACTION_NOTIFICATION_CALL_OPEN)) { RCConnection connection = getLiveConnection(); if (connection != null) { if (connection.isIncoming()) { callIntent.setAction(ACTION_INCOMING_CALL); } else { callIntent.setAction(ACTION_OUTGOING_CALL); } callIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // don't forget to copy the extras to callIntent callIntent.putExtras(intent); actionIntent = callIntent; } } */ if (intentAction.equals(ACTION_NOTIFICATION_CALL_DEFAULT)) { if (callIntent != null) { callIntent.setAction(ACTION_INCOMING_CALL); // don't forget to copy the extras to callIntent callIntent.putExtras(intent); actionIntent = callIntent; } else { Context context = getApplicationContext(); PackageManager packageManager = context.getPackageManager(); actionIntent = packageManager.getLaunchIntentForPackage(context.getPackageName()); } } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_VIDEO)) { callIntent.setAction(ACTION_INCOMING_CALL_ANSWER_VIDEO); // don't forget to copy the extras callIntent.putExtras(intent); actionIntent = callIntent; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_AUDIO)) { callIntent.setAction(ACTION_INCOMING_CALL_ANSWER_AUDIO); // don't forget to copy the extras callIntent.putExtras(intent); actionIntent = callIntent; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_DECLINE) || intentAction.equals(ACTION_NOTIFICATION_CALL_DELETE)) { RCConnection pendingConnection = getPendingConnection(); if (pendingConnection != null) { pendingConnection.reject(); } release(); // if the call has been requested to be declined, we shouldn't do any UI handling return; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_MUTE_AUDIO)) { RCConnection liveConnection = getLiveConnection(); if (liveConnection != null) { if (liveConnection.isAudioMuted()) { liveConnection.setAudioMuted(false); } else { liveConnection.setAudioMuted(true); } } // if the call has been requested to be muted, we shouldn't do any UI handling return; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_DISCONNECT)) { RCConnection liveConnection = getLiveConnection(); if (liveConnection != null) { liveConnection.disconnect(); if (!isAttached()) { // if the call has been requested to be disconnected, we shouldn't do any UI handling callIntent.setAction(ACTION_CALL_DISCONNECT); //callIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); actionIntent = callIntent; startActivity(actionIntent); } /* // Important if we just trigger the call intent, then after the call is disconnected we will land to the previous screen in // that Task Stack, which is not what we want. Instead, we want the call activity to be finished and to just remain where // we were. To do that we need to create a new Task Stack were we only place the call activity TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the target Intent to the top of the stack stackBuilder.addNextIntent(actionIntent); // Gets a PendingIntent containing the entire back stack, but with Component as the active Activity PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); try { resultPendingIntent.send(); } catch (PendingIntent.CanceledException e) { throw new RuntimeException("Pending Intent cancelled", e); } */ } return; } else if (intentAction.equals(ACTION_NOTIFICATION_MESSAGE_DEFAULT)) { if (messageIntent == null) { storageManagerPreferences = new StorageManagerPreferences(this); String messageIntentString = storageManagerPreferences .getString(RCDevice.ParameterKeys.INTENT_INCOMING_MESSAGE, null); if (messageIntentString != null) { try { messageIntent = Intent.parseUri(messageIntentString, Intent.URI_INTENT_SCHEME); //service was stopped and user taps on Notification case if (!isInitialized()) { HashMap<String, Object> parameters = StorageUtils.getParams(storageManagerPreferences); try { initialize(null, parameters, null); } catch (RCException e) { RCLogger.e(TAG, e.toString()); } } } catch (URISyntaxException e) { throw new RuntimeException("Failed to handle Notification"); } } } messageIntent.setAction(ACTION_INCOMING_MESSAGE); // don't forget to copy the extras messageIntent.putExtras(intent); actionIntent = messageIntent; //we want to stop foreground (notification is tapped) stopForeground(true); stopRepeatingTask(); } else { throw new RuntimeException("Failed to handle Notification"); } // We need to create a Task Stack to make sure we maintain proper flow at all times TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds either call or message intent's Component in the stack together with all its parent activities (remember that for this to work the App Manifest needs to describe their relationship) stackBuilder.addParentStack(actionIntent.getComponent()); // Adds the target Intent to the top of the stack stackBuilder.addNextIntent(actionIntent); // Gets a PendingIntent containing the entire back stack, but with Component as the active Activity PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); try { resultPendingIntent.send(); } catch (PendingIntent.CanceledException e) { throw new RuntimeException("Pending Intent cancelled", e); } }