Java Code Examples for android.content.Intent#setPackage()

The following examples show how to use android.content.Intent#setPackage() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: delion   File: Tab.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
 *         foreground, or null if this isn't possible.
 */
public static Intent createBringTabToFrontIntent(int tabId) {
    // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
    // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
    List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> ref : list) {
        Activity activity = ref.get();
        if (activity instanceof CustomTabActivity
                && ((CustomTabActivity) activity).getActivityTab() != null
                && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
            return null;
        }
    }

    String packageName = ContextUtils.getApplicationContext().getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName);
    intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId);
    intent.setPackage(packageName);
    return intent;
}
 
Example 2
private boolean connect() {
    synchronized (this) {
        if (!connecting) {
            try {
                ResolveInfo resolveInfo = context.getPackageManager().resolveService(searchIntent, 0);
                if (resolveInfo != null) {
                    Intent intent = new Intent(bindAction);
                    intent.setPackage(resolveInfo.serviceInfo.packageName);
                    intent.setClassName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
                    connecting = context.bindService(intent, this, Context.BIND_AUTO_CREATE);
                    if (!connecting) Log.d(TAG, "Could not connect to: " + intent);
                    return connecting;
                }
                return false;
            } catch (Exception e) {
                Log.w(TAG, e);
            }
        }
        return true;
    }
}
 
Example 3
Source Project: SoloPi   File: SchemeActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void startOrigin() {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setPackage(LauncherApplication.getContext().getPackageName());
    ResolveInfo resolveInfo = LauncherApplication.getContext().getPackageManager().resolveActivity(intent, 0);
    if (resolveInfo == null) {
        finish();
        return;
    }

    String targetActivity = resolveInfo.activityInfo.name;
    try {
        Intent mainActivity = new Intent(this, Class.forName(targetActivity));
        startActivity(mainActivity);
        finish();
    } catch (ClassNotFoundException e) {
        LogUtil.e(TAG, "Catch java.lang.ClassNotFoundException: " + e.getMessage(), e);
    }
}
 
Example 4
Source Project: delion   File: GSAState.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This is used to check whether GSA package is available to handle search requests and if
 * the Chrome experiment to do so is enabled.
 * @return Whether the search intent this class creates will resolve to an activity.
 */
public boolean isGsaAvailable() {
    if (mGsaAvailable != null) return mGsaAvailable;
    mGsaAvailable = false;
    PackageManager pm = mContext.getPackageManager();
    Intent searchIntent = new Intent(SEARCH_INTENT_ACTION);
    searchIntent.setPackage(GSAState.SEARCH_INTENT_PACKAGE);
    List<ResolveInfo> resolveInfo = pm.queryIntentActivities(searchIntent, 0);
    if (resolveInfo.size() == 0) {
        mGsaAvailable = false;
    } else if (!isPackageAboveVersion(SEARCH_INTENT_PACKAGE, GSA_VERSION_FOR_DOCUMENT)
            || !isPackageAboveVersion(GMS_CORE_PACKAGE, GMS_CORE_VERSION)) {
        mGsaAvailable = false;
    } else {
        mGsaAvailable = true;
    }
    return mGsaAvailable;
}
 
Example 5
@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    Intent serviceIntent = new Intent(SipManager.INTENT_SIP_SERVICE);
    // Optional, but here we bundle so just ensure we are using csipsimple package
    serviceIntent.setPackage(activity.getPackageName());
    getActivity().bindService(serviceIntent, connection,
            Context.BIND_AUTO_CREATE);
    // timings.addSplit("Bind asked for two");
    if (prefsWrapper == null) {
        prefsWrapper = new PreferencesWrapper(getActivity());
    }
    if (dialFeedback == null) {
        dialFeedback = new DialingFeedback(getActivity(), false);
    }

    dialFeedback.resume();
    
}
 
Example 6
/** @hide */
@RestrictTo(LIBRARY_GROUP)
@VisibleForTesting
static void launchIntent(Context context, Intent intent, List<ResolveInfo> handlers) {
    if (handlers == null || handlers.size() == 0) {
        openFallbackBrowserActionsMenu(context, intent);
        return;
    } else if (handlers.size() == 1) {
        intent.setPackage(handlers.get(0).activityInfo.packageName);
    } else {
        Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(TEST_URL));
        PackageManager pm = context.getPackageManager();
        ResolveInfo defaultHandler =
                pm.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY);
        if (defaultHandler != null) {
            String defaultPackageName = defaultHandler.activityInfo.packageName;
            for (int i = 0; i < handlers.size(); i++) {
                if (defaultPackageName.equals(handlers.get(i).activityInfo.packageName)) {
                    intent.setPackage(defaultPackageName);
                    break;
                }
            }
        }
    }
    ContextCompat.startActivity(context, intent, null);
}
 
Example 7
@Override
public ResolveInfo resolveActivity(Intent intent, int flags) {
    ComponentName componentName = intent.getComponent();
    Log.d(TAG,"resolveActivity" + componentName.getClassName());
    intent.setComponent(new ComponentName(realPackageName,componentName.getClassName()));
    intent.setPackage(realPackageName);
    return packageManager.resolveActivity(intent,flags);
}
 
Example 8
private void setPackageNameExtra(Intent intent) {
    synchronized (mAppPendingIntentLock) {
        if (mAppPendingIntent == null) {
            Intent target = new Intent();
            // Fill in the package, to prevent the intent from being used.
            target.setPackage("com.google.example.invalidpackage");
            mAppPendingIntent = PendingIntent.getBroadcast(
                    ContextUtils.getApplicationContext(), 0, target, 0);
        }
    }
    intent.putExtra(INTENT_PARAM_APP, mAppPendingIntent);
}
 
Example 9
/**
 * Unregister the application. New messages will be blocked by server.
 */
private void unregister() {
  Intent regIntent = new Intent(REQUEST_UNREGISTRATION_INTENT);
  regIntent.setPackage(GSF_PACKAGE);
  regIntent.putExtra(
      EXTRA_APPLICATION_PENDING_INTENT, PendingIntent.getBroadcast(context, 0, new Intent(), 0));
  setUnregisteringInProcess(true);
  context.startService(regIntent);
}
 
Example 10
public static void shareMessenger(String text, Context context) {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, text);
    sendIntent.setType("text/plain");
    sendIntent.setPackage("com.facebook.orca");
    try {
        context.startActivity(sendIntent);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(context, "Please Install Facebook Messenger", Toast.LENGTH_LONG).show();
    }
}
 
Example 11
private void AviateLauncher() {
    Intent aviate = new Intent("com.tul.aviate.SET_THEME");
    aviate.setPackage("com.tul.aviate");
    aviate.putExtra("THEME_PACKAGE", BuildConfig.APPLICATION_ID);
    aviate.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    openActivity(aviate);
}
 
Example 12
@Override
public void startActivity(Intent intent) {
	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	List<ResolveInfo> resolveInfos = getPackageManager()
			.queryIntentActivities(intent,
					PackageManager.MATCH_DEFAULT_ONLY);
	if (resolveInfos == null || resolveInfos.isEmpty()) {
		intent.setPackage(mDelegatedService.getPackageName());
	} else {
		super.startActivity(intent);
		return;
	}
	PluginClientManager.sharedInstance(this).startActivity(this, intent);
}
 
Example 13
Source Project: raygun4android   File: CrashReporting.java    License: MIT License 5 votes vote down vote up
private static void enqueueWorkForCrashReportingService(String apiKey, String jsonPayload) {
    Intent intent = new Intent(RaygunClient.getApplicationContext(), CrashReportingPostService.class);
    intent.setAction("com.raygun.raygun4android.intent.action.LAUNCH_CRASHREPORTING_POST_SERVICE");
    intent.setPackage("com.raygun.raygun4android");
    intent.setComponent(new ComponentName(RaygunClient.getApplicationContext(), CrashReportingPostService.class));

    intent.putExtra("msg", jsonPayload);
    intent.putExtra("apikey", apiKey);

    CrashReportingPostService.enqueueWork(RaygunClient.getApplicationContext(), intent);
}
 
Example 14
Source Project: android   File: VideoCastManager.java    License: Apache License 2.0 5 votes vote down vote up
private boolean startNotificationService() {
    if (!isFeatureEnabled(FEATURE_NOTIFICATION)) {
        return true;
    }
    LOGD(TAG, "startNotificationService() ");
    Intent service = new Intent(mContext, VideoCastNotificationService.class);
    service.setPackage(mContext.getPackageName());
    return null != mContext.startService(service);
}
 
Example 15
/**
 * Returns an {@link android.content.Intent} suitable for passing to
 * {@link android.app.Activity#startActivityForResult(android.content.Intent, int)}
 * which prompts the user to grant permissions to this application.
 *
 * @throws NullPointerException if {@code permissions} is {@code null} or empty.
 *
 * @hide
 */
public Intent buildRequestPermissionsIntent(@NonNull String[] permissions) {
    if (ArrayUtils.isEmpty(permissions)) {
       throw new NullPointerException("permission cannot be null or empty");
    }
    Intent intent = new Intent(ACTION_REQUEST_PERMISSIONS);
    intent.putExtra(EXTRA_REQUEST_PERMISSIONS_NAMES, permissions);
    intent.setPackage(getPermissionControllerPackageName());
    return intent;
}
 
Example 16
@Override
public void onOpenInChrome(String linkUrl, String pageUrl) {
    Intent chromeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl));
    chromeIntent.setPackage(mTab.getApplicationContext().getPackageName());
    chromeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    boolean activityStarted = false;
    if (pageUrl != null) {
        try {
            URI pageUri = URI.create(pageUrl);
            if (UrlUtilities.isInternalScheme(pageUri)) {
                IntentHandler.startChromeLauncherActivityForTrustedIntent(chromeIntent);
                activityStarted = true;
            }
        } catch (IllegalArgumentException ex) {
            // Ignore the exception for creating the URI and launch the intent
            // without the trusted intent extras.
        }
    }

    if (!activityStarted) {
        Context context = mTab.getActivity();
        if (context == null) context = mTab.getApplicationContext();
        context.startActivity(chromeIntent);
        activityStarted = true;
    }
}
 
Example 17
Source Project: materialup   File: CustomTabsHelper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Goes through all apps that handle VIEW intents and have a warmup service. Picks
 * the one chosen by the user if there is one, otherwise makes a best effort to return a
 * valid package name.
 * <p>
 * This is <strong>not</strong> threadsafe.
 *
 * @param context {@link Context} to use for accessing {@link PackageManager}.
 * @return The package name recommended to use for connecting to custom tabs related components.
 */
public static String getPackageNameToUse(Context context) {
    if (sPackageNameToUse != null) return sPackageNameToUse;

    PackageManager pm = context.getPackageManager();
    // Get default VIEW intent handler.
    Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
    String defaultViewHandlerPackageName = null;
    if (defaultViewHandlerInfo != null) {
        defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
    }

    // Get all apps that can handle VIEW intents.
    List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
    List<String> packagesSupportingCustomTabs = new ArrayList<>();
    for (ResolveInfo info : resolvedActivityList) {
        Intent serviceIntent = new Intent();
        serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
        serviceIntent.setPackage(info.activityInfo.packageName);
        if (pm.resolveService(serviceIntent, 0) != null) {
            packagesSupportingCustomTabs.add(info.activityInfo.packageName);
        }
    }

    // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
    // and service calls.
    if (packagesSupportingCustomTabs.isEmpty()) {
        sPackageNameToUse = null;
    } else if (packagesSupportingCustomTabs.size() == 1) {
        sPackageNameToUse = packagesSupportingCustomTabs.get(0);
    } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
            && !hasSpecializedHandlerIntents(context, activityIntent)
            && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
        sPackageNameToUse = defaultViewHandlerPackageName;
    } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
        sPackageNameToUse = STABLE_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
        sPackageNameToUse = BETA_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
        sPackageNameToUse = DEV_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
        sPackageNameToUse = LOCAL_PACKAGE;
    }
    return sPackageNameToUse;
}
 
Example 18
private PendingIntent getActionIntent(Context context, int mediaKeyEvent) {
	Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
	intent.setPackage(context.getPackageName());
	intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, mediaKeyEvent));
	return PendingIntent.getBroadcast(context, mediaKeyEvent, intent, 0);
}
 
Example 19
Source Project: MaterialHome   File: CustomTabsHelper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Goes through all apps that handle VIEW intents and have a warmup service. Picks
 * the one chosen by the user if there is one, otherwise makes a best effort to return a
 * valid package name.
 *
 * This is <strong>not</strong> threadsafe.
 *
 * @param context {@link Context} to use for accessing {@link PackageManager}.
 * @return The package name recommended to use for connecting to custom tabs related components.
 */
public static String getPackageNameToUse(Context context) {
    if (sPackageNameToUse != null) return sPackageNameToUse;

    PackageManager pm = context.getPackageManager();
    // Get default VIEW intent handler.
    Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
    String defaultViewHandlerPackageName = null;
    if (defaultViewHandlerInfo != null) {
        defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
    }

    // Get all apps that can handle VIEW intents.
    List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
    List<String> packagesSupportingCustomTabs = new ArrayList<>();
    for (ResolveInfo info : resolvedActivityList) {
        Intent serviceIntent = new Intent();
        serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
        serviceIntent.setPackage(info.activityInfo.packageName);
        if (pm.resolveService(serviceIntent, 0) != null) {
            packagesSupportingCustomTabs.add(info.activityInfo.packageName);
        }
    }

    // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
    // and service calls.
    if (packagesSupportingCustomTabs.isEmpty()) {
        sPackageNameToUse = null;
    } else if (packagesSupportingCustomTabs.size() == 1) {
        sPackageNameToUse = packagesSupportingCustomTabs.get(0);
    } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
            && !hasSpecializedHandlerIntents(context, activityIntent)
            && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
        sPackageNameToUse = defaultViewHandlerPackageName;
    } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
        sPackageNameToUse = STABLE_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
        sPackageNameToUse = BETA_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
        sPackageNameToUse = DEV_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
        sPackageNameToUse = LOCAL_PACKAGE;
    }
    return sPackageNameToUse;
}
 
Example 20
private void sendTwitterIntent() {
	log("current conditions sharing to twitter");

	String twitterCondition = "";
	String tweet = "";
	if (condition.getGeneral_condition().equals(
			getString(R.string.precipitation))) {
		if (condition.getPrecipitation_type().equals(
				getString(R.string.rain))) {
			twitterCondition = "raining";
		} else if (condition.getPrecipitation_type().equals(
				getString(R.string.snow))) {
			twitterCondition = "snowing";
		} else if (condition.getPrecipitation_type().equals(
				getString(R.string.hail))) {
			twitterCondition = "hailing";
		}
	} else if (condition.getGeneral_condition().equals(
			getString(R.string.cloudy))) {
		twitterCondition = "cloudy";
	} else if (condition.getGeneral_condition().equals(
			getString(R.string.foggy))) {
		twitterCondition = "foggy";
	} else if (condition.getGeneral_condition().equals(
			getString(R.string.thunderstorm))) {
		twitterCondition = "thunderstorming";
	} else if (condition.getGeneral_condition().equals(
			getString(R.string.sunny))) {
		twitterCondition = "clear";
	} else {
		twitterCondition = condition.getGeneral_condition();
	}

	if (condition.getGeneral_condition()
			.equals(getString(R.string.extreme))) {
		tweet = "#" + condition.getUser_comment() + " "
				+ getString(R.string.currentConditionsTweet);
	} else {
		tweet = "It's #" + twitterCondition + " "
				+ getString(R.string.currentConditionsTweet);
	}

	String tweetUrl = String
			.format("https://twitter.com/intent/tweet?text=%s&url=%s",
					URLEncoder.encode(tweet),
					URLEncoder
							.encode("http://bit.ly/1IvRM8w"));
	Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tweetUrl));

	// Narrow down to official Twitter app, if available:
	List<ResolveInfo> matches = getPackageManager().queryIntentActivities(
			intent, 0);
	for (ResolveInfo info : matches) {
		if (info.activityInfo.packageName.toLowerCase().startsWith(
				"com.twitter")) {
			intent.setPackage(info.activityInfo.packageName);
		}
	}

	startActivity(intent);
}