private void onIntent(final Intent intent) {
		Log.i(TAG, "API request: " + intent.toUri(0));
		if (intent.getAction() != null) {
			String result;
			final ComponentName caller = getCallingActivity();
			if (caller != null) try { @SuppressLint("WrongConstant")		// Invoked with startActivityForResult()
				final ActivityInfo info = getPackageManager().getActivityInfo(caller, Hacks.RESOLVE_ANY_USER_AND_UNINSTALLED);
				int uid = info.applicationInfo.uid;
				if (UserHandles.getUserId(uid) != 0) {
					final String[] potential_pkgs = getPackageManager().getPackagesForUid(uid);
					if (potential_pkgs == null) uid = UserHandles.getAppId(uid);	// Caller is not in this user, just assume it is from the owner user.
				}
				result = ApiDispatcher.verifyCaller(this, intent, caller.getPackageName(), uid);
			} catch (final PackageManager.NameNotFoundException e) {
				result = "Unverifiable caller activity: " + caller.flattenToShortString();
			} else {
				final String caller_pkg = getCallingPackage();
				int caller_uid = -1;
				try {
					caller_uid = getPackageManager().getPackageUid(caller_pkg, 0);
				} catch (final PackageManager.NameNotFoundException ignored) {}
				result = ApiDispatcher.verifyCaller(this, intent, caller_pkg, caller_uid);
			}

			if (result == null) {
				result = ApiDispatcher.dispatch(this, intent);
				if (result == null) {
					setResult(Activity.RESULT_OK);
					Log.i(TAG, "API result: Success");
				} else {
					setResult(Activity.RESULT_CANCELED, new Intent(result));
					Log.i(TAG, "API result: " + result);
				}
			} else {
				setResult(Api.latest.RESULT_UNVERIFIED_IDENTITY, new Intent(result));
				Log.w(TAG, "Unverified client: " + result);
			}
		} else setResult(RESULT_CANCELED, new Intent("No action"));
		finish();
	}
API via activity (better for crossing the user border)

Created by Oasis on 2016/6/16.
engine/src/main/java/com/oasisfeng/island/api/ApiActivity.java