Java Code Examples for android.app.Activity#getIntent()

The following examples show how to use android.app.Activity#getIntent() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void initData(Activity activity) {
    final Intent intent = activity.getIntent();
    if (intent.getData() != null) {
        mView.onStartFromUri();
    } else {
        // 避免从桌面启动程序后,会重新实例化入口类的activity
        if (!activity.isTaskRoot()) {
            final String intentAction = intent.getAction();
            if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
                mView.finish();
                return;
            }
        }

        if (mView.getPreferences().getBoolean(mView.getContext().getString(R.string.pk_default_read), false)) {
            openBookFromRecent();
        } else {
            mView.onStartNormal(START_DELAY);
        }
    }
}
 
Example 2
Source Project: Abelana-Android   File: AppLinkData.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parses out any app link data from the Intent of the Activity passed in.
 * @param activity Activity that was started because of an app link
 * @return AppLinkData if found. null if not.
 */
public static AppLinkData createFromActivity(Activity activity) {
    Validate.notNull(activity, "activity");
    Intent intent = activity.getIntent();
    if (intent == null) {
        return null;
    }

    AppLinkData appLinkData = createFromAlApplinkData(intent);
    if (appLinkData == null) {
        String appLinkArgsJsonString = intent.getStringExtra(BUNDLE_APPLINK_ARGS_KEY);
        appLinkData = createFromJson(appLinkArgsJsonString);
    }
    if (appLinkData == null) {
        // Try regular app linking
        appLinkData = createFromUri(intent.getData());
    }

    return appLinkData;
}
 
Example 3
Source Project: KlyphMessenger   File: AppLinkData.java    License: MIT License 6 votes vote down vote up
/**
 * Parses out any app link data from the Intent of the Activity passed in.
 * @param activity Activity that was started because of an app link
 * @return AppLinkData if found. null if not.
 */
public static AppLinkData createFromActivity(Activity activity) {
    Validate.notNull(activity, "activity");
    Intent intent = activity.getIntent();
    if (intent == null) {
        return null;
    }

    String appLinkArgsJsonString = intent.getStringExtra(BUNDLE_APPLINK_ARGS_KEY);
    // Try v2 app linking first
    AppLinkData appLinkData = createFromJson(appLinkArgsJsonString);
    if (appLinkData == null) {
        // Try regular app linking
        appLinkData = createFromUri(intent.getData());
    }

    return appLinkData;
}
 
Example 4
@Override
public void onHostResume() {
    setIsForeground(true);

    Activity activity = getCurrentActivity();
    if (activity != null) {
        Intent intent = activity.getIntent();
        if (intent != null) {
            Bundle bundle = ReactNativeUtil.getBundleFromIntent(intent);
            if (bundle != null) {
                ReactNativeUtil.removeNotificationFromIntent(intent);
                bundle.putBoolean(KEY_REMOTE_NOTIFICATION_FOREGROUND, false);
                bundle.putBoolean(KEY_REMOTE_NOTIFICATION_USER_INTERACTION, true);
                bundle.putBoolean(KEY_REMOTE_NOTIFICATION_COLDSTART, true);
                ReactNativeNotificationsHandler.sendBroadcast(
                        mReactContext, bundle, NOTIFICATION_DELAY_ON_START);
            }
        }
    }
}
 
Example 5
Source Project: FastLib   File: FastLifecycleCallbacks.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityDestroyed(Activity activity) {
    //横竖屏会重绘将状态重置
    if (activity.getIntent() != null) {
        activity.getIntent().removeExtra(FastConstant.IS_SET_STATUS_VIEW_HELPER);
        activity.getIntent().removeExtra(FastConstant.IS_SET_NAVIGATION_VIEW_HELPER);
        activity.getIntent().removeExtra(FastConstant.IS_SET_CONTENT_VIEW_BACKGROUND);
        activity.getIntent().removeExtra(FastConstant.IS_SET_REFRESH_VIEW);
        activity.getIntent().removeExtra(FastConstant.IS_SET_TITLE_BAR_VIEW);
    }
    LoggerManager.i(TAG, "onActivityDestroyed:" + activity.getClass().getSimpleName() + ";isFinishing:" + activity.isFinishing());
    FastStackUtil.getInstance().pop(activity, false);

    //清除下拉刷新代理FastRefreshDelegate
    FastDelegateManager.getInstance().removeFastRefreshDelegate(activity.getClass());
    //清除标题栏代理类FastTitleDelegate
    FastDelegateManager.getInstance().removeFastTitleDelegate(activity.getClass());
    //清除BasisHelper
    FastDelegateManager.getInstance().removeBasisHelper(activity);
    //回调给开发者实现自己应用逻辑
    if (mActivityLifecycleCallbacks != null) {
        mActivityLifecycleCallbacks.onActivityDestroyed(activity);
    }
}
 
Example 6
Source Project: Neptune   File: ActivityRecoveryHelper.java    License: Apache License 2.0 6 votes vote down vote up
void saveIcicle(Activity activity, Bundle icicle) {
    if (shouldIgnore(activity)) {
        return;
    }
    String id = UUID.randomUUID().toString();
    Intent intent = activity.getIntent();
    try {
        intent.putExtra(KEY_RECOVERY_ICICLE, id);
        mPendingIcicleMap.put(id, icicle);
    } catch (RuntimeException e) {
        // Intent里放置了插件自定义的序列化数据,进程重启时操作Intent会导致反序列数据失败
        ErrorUtil.throwErrorIfNeed(e);
    } catch (OutOfMemoryError error) {
        // Intent反序列化时可能数据量很大发生OOM
        ErrorUtil.throwErrorIfNeed(error);
    }
}
 
Example 7
Source Project: react-native-GPay   File: IntentModule.java    License: MIT License 6 votes vote down vote up
/**
 * Return the URL the activity was started with
 *
 * @param promise a promise which is resolved with the initial URL
 */
@ReactMethod
public void getInitialURL(Promise promise) {
  try {
    Activity currentActivity = getCurrentActivity();
    String initialURL = null;

    if (currentActivity != null) {
      Intent intent = currentActivity.getIntent();
      String action = intent.getAction();
      Uri uri = intent.getData();

      if (Intent.ACTION_VIEW.equals(action) && uri != null) {
        initialURL = uri.toString();
      }
    }

    promise.resolve(initialURL);
  } catch (Exception e) {
    promise.reject(new JSApplicationIllegalArgumentException(
        "Could not get the initial URL : " + e.getMessage()));
  }
}
 
Example 8
Source Project: CC   File: CCUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 在组件类中通过{@link #navigateTo(CC, Class)}跳转页面后,可通过此方法快捷获取CC的callId
 */
public static String getNavigateCallId(@NonNull Activity activity) {
    Intent intent = activity.getIntent();
    if (intent != null) {
        return intent.getStringExtra(EXTRA_KEY_CALL_ID);
    }
    return null;
}
 
Example 9
/**
 * Returns an {@link Intent} if the sending app is signed by one of
 * the trusted signing keys as set in {@link #addTrustedSigner(Class)}.
 *
 * @returns {@code null} if there is no {@code Intent} or if the
 * sender is not trusted.
 * @see #addTrustedSigner(Class)
 */
public Intent getIntentFromTrustedSender(Activity activity) {
    Intent intent = activity.getIntent();
    String packageName = getCallingPackageName(activity);
    if (TextUtils.isEmpty(packageName)) {
        return null;
    }
    if (isPackageNameTrusted(packageName)) {
        return intent;
    }
    return null;
}
 
Example 10
public static void restartIfLocaleChanged(@NonNull Activity activity, boolean oldIsArabic)
{
    final boolean isUpdatedLocaleArabic=isArabicUi(activity);
    if (isUpdatedLocaleArabic != oldIsArabic) {
        final Intent i = activity.getIntent();
        activity.finish();
        activity.startActivity(i);
    }
}
 
Example 11
Source Project: AcgClub   File: ActivityLifecycle.java    License: MIT License 5 votes vote down vote up
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
  //如果intent包含了此字段,并且为true说明不加入到list
  // 默认为false,如果不需要管理(比如不需要在退出所有activity(killAll)时,退出此activity就在intent加此字段为true)
  boolean isNotAdd = false;
  if (activity.getIntent() != null) {
    isNotAdd = activity.getIntent().getBooleanExtra(IS_NOT_ADD_ACTIVITY_LIST, false);
  }

  if (!isNotAdd) {
    mAppManager.addActivity(activity);
  }
  ActivityStackManager.getInstance().addActivity(activity);
}
 
Example 12
Source Project: Camera2   File: MainActivityLayout.java    License: Apache License 2.0 5 votes vote down vote up
public MainActivityLayout(Context context, AttributeSet attrs)
{
    super(context, attrs);
    mSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    Activity activity = (Activity) context;
    Intent intent = activity.getIntent();
    String action = intent.getAction();
    mIsCaptureIntent = (MediaStore.ACTION_IMAGE_CAPTURE.equals(action)
            || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(action)
            || MediaStore.ACTION_VIDEO_CAPTURE.equals(action));
}
 
Example 13
public static @NonNull ArrayList<Uri> getSharedUris(Activity activity) {
    if (activity != null) {
        Intent i = activity.getIntent();
        if (i != null) {
            ArrayList<Uri> uris = i.getParcelableArrayListExtra(SHARED_URIS);
            if (uris != null) return uris;
        }
    }
    return new ArrayList<>();
}
 
Example 14
private void onActivityDestory(Activity activity) throws RemoteException {
    Intent targetIntent = activity.getIntent();
    if (targetIntent != null) {
        ActivityInfo targetInfo = targetIntent.getParcelableExtra(Env.EXTRA_TARGET_INFO);
        ActivityInfo stubInfo = targetIntent.getParcelableExtra(Env.EXTRA_STUB_INFO);
        if (targetInfo != null && stubInfo != null) {
            PluginManager.getInstance().onActivityDestory(stubInfo, targetInfo);
        }
    }
}
 
Example 15
Source Project: OkDeepLink   File: BundleCompact.java    License: Apache License 2.0 5 votes vote down vote up
private static Bundle getBundle(Activity activity) {

        if (activity == null || activity.getIntent() == null) {
            return null;
        }
        return activity.getIntent().getExtras();
    }
 
Example 16
/**
 * @hide 内部方法,插件框架使用
 * 插件的Activity的onCreate调用前调用此方法
 * @param activity
 * @param savedInstanceState
 */
public void handleActivityCreateBefore(Activity activity, Bundle savedInstanceState) {
    if (LOG) {
        LogDebug.d(PLUGIN_TAG, "activity create before: " + activity.getClass().getName() + " this=" + activity.hashCode() + " taskid=" + activity.getTaskId());
    }

    // 对FragmentActivity做特殊处理
    if (savedInstanceState != null) {
        //
        savedInstanceState.setClassLoader(activity.getClassLoader());
        //
        try {
            savedInstanceState.remove("android:support:fragments");
        } catch (Throwable e) {
            if (LOGR) {
                LogRelease.e(PLUGIN_TAG, "a.c.b1: " + e.getMessage(), e);
            }
        }
    }

    // 对FragmentActivity做特殊处理
    Intent intent = activity.getIntent();
    if (intent != null) {
        intent.setExtrasClassLoader(activity.getClassLoader());
        activity.setTheme(getThemeId(activity, intent));
    }
}
 
Example 17
Source Project: Neptune   File: PluginActivityDelegate.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 在插件Activity的onCreate调用前调用该方法
 */
void handleActivityOnCreateBefore(Activity activity, Bundle savedInstanceState) {

    if (PluginDebugLog.isDebug()) {
        PluginDebugLog.runtimeLog(TAG, "activity handleActivityOnCreateBefore() is called(): " + activity.getClass().getName());
    }

    if (mPlugin == null) {
        // 通过插件的Intent再去查找一遍
        String pkgName = IntentUtils.parsePkgNameFromActivity(activity);
        if (!TextUtils.isEmpty(pkgName)) {
            mPlugin = PluginManager.getPluginLoadedApkByPkgName(pkgName);
        }
    }

    ClassLoader cl = mPlugin != null ? mPlugin.getPluginClassLoader() : activity.getClassLoader();
    // 修正Intent的ClassLoader,解决序列化的问题
    Intent intent = activity.getIntent();
    intent.setExtrasClassLoader(cl);
    IntentUtils.resetAction(intent); //恢复Intent的Action

    // 对FragmentActivity做特殊处理,不保留Fragment的恢复数据
    if (savedInstanceState != null) {
        savedInstanceState.setClassLoader(cl);
        savedInstanceState.remove(SUPPORT_FRAGMENTS_TAG);
        savedInstanceState.remove(FRAGMENTS_TAG);
    }
    // 替换Application,不然插件内无法监听LifeCycle
    if (mPlugin != null) {
        ReflectionUtils.on(activity).setNoException("mApplication", mPlugin.getPluginApplication());
    }
    // 再次确保Activity的Base Context已经被替换了
    Context mBase = activity.getBaseContext();
    if (mBase instanceof PluginContextWrapper) {
        PluginDebugLog.runtimeLog(TAG, "activity " + activity.getClass().getName() + " base context already be replaced");
    } else if (mPlugin != null) {
        mBase = new PluginContextWrapper(mBase, mPlugin);
        // 反射替换mBase成员变量
        ReflectionUtils.on(activity, ContextWrapper.class).set("mBase", mBase);
        ReflectionUtils.on(activity, ContextThemeWrapper.class).setNoException("mBase", mBase);
    }
    // 给LayoutInflater设置privateFactory
    LayoutInflaterCompat.setPrivateFactory(activity.getLayoutInflater());
    // 修改Activity的ActivityInfo和主题信息
    PluginActivityControl.changeActivityInfo(activity, activity.getClass().getName(), mPlugin);
}
 
Example 18
private boolean shouldIgnore(Activity activity) {
    return activity == null || activity.getIntent() == null;
}
 
Example 19
Source Project: grouter-android   File: RouterInject.java    License: Apache License 2.0 4 votes vote down vote up
public static void inject(Activity activity) {
    Intent intent = activity.getIntent();
    inject(activity, intent);
}
 
Example 20
Source Project: guideshow   File: ShareCompat.java    License: MIT License 4 votes vote down vote up
private IntentReader(Activity activity) {
    mActivity = activity;
    mIntent = activity.getIntent();
    mCallingPackage = ShareCompat.getCallingPackage(activity);
    mCallingActivity = ShareCompat.getCallingActivity(activity);
}