Intent setPackage - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Intent setPackage method.

This code example shows how to use the following methods:putExtra, setPackage
    /** 
     * Initiate c2d messaging registration for the current application 
     */ 
    public static void register(Context context,
            String senderId) {
        Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT);
        registrationIntent.setPackage(GSF_PACKAGE);
        registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT,
                PendingIntent.getBroadcast(context, 0, new Intent(), 0));
        registrationIntent.putExtra(EXTRA_SENDER, senderId);
        context.startService(registrationIntent);
        // TODO: if intent not found, notification on need to have GSF 
    } 
 
    /** 
     * Unregister the application. New messages will be blocked by server. 
     */ 
    public static void unregister(Context context) {
        Intent regIntent = new Intent(REQUEST_UNREGISTRATION_INTENT);
        regIntent.setPackage(GSF_PACKAGE);
8
CodeRank
This code example shows how to use the following methods:setAction, setPackage
          // no-op -- client must be gone 
        } 
      } 
    } 
    else { 
      data.setPackage(intent.getStringExtra(BROADCAST_PACKAGE));
      data.setAction(broadcast);
 
      sendBroadcast(data);
    } 
  } 
   
  private String getStackTrace(Throwable t) {
    final StringWriter result=new StringWriter();
    final PrintWriter printWriter=new PrintWriter(result);
     
    t.printStackTrace(printWriter);
     
    return(result.toString());
  } 
7
CodeRank
This code example shows how to use the following methods:setPackage
 
    public void upgradeSettingsIfNeeded() { 
    } 
 
    public Intent getSearchableItemsIntent() {
        Intent intent = new Intent(ACTION_SEARCHABLE_ITEMS);
        intent.setPackage(getContext().getPackageName());
        return intent;
    } 
 
    /** 
     * Gets the preference key of the preference for whether the given corpus 
     * is enabled. The preference is stored in the {@link #PREFERENCES_NAME} 
     * preferences file. 
     */ 
    public static String getCorpusEnabledPreference(Corpus corpus) {
        return CORPUS_ENABLED_PREF_PREFIX + corpus.getName();
    } 
 
    public boolean isCorpusEnabled(Corpus corpus) {
6
CodeRank
This code example shows how to use the following methods:putExtra, setPackage
    /** 
     * Initiate c2d messaging registration for the current application 
     */ 
    public static void register(Context context,
            String senderId) {
        Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT);
        registrationIntent.setPackage(GSF_PACKAGE);
        registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT,
                PendingIntent.getBroadcast(context, 0, new Intent(), 0));
        registrationIntent.putExtra(EXTRA_SENDER, senderId);
        context.startService(registrationIntent);
        // TODO: if intent not found, notification on need to have GSF 
    } 
 
    /** 
     * Unregister the application. New messages will be blocked by server. 
     */ 
    public static void unregister(Context context) {
        Intent regIntent = new Intent(REQUEST_UNREGISTRATION_INTENT);
        regIntent.setPackage(GSF_PACKAGE);
8
CodeRank
This code example shows how to use the following methods:setPackage
  @Test 
  public void testLaunchIntentForPackage() { 
    Intent intent = rpm.getLaunchIntentForPackage(TEST_PACKAGE_LABEL);
    assertThat(intent).isNull();
 
    Intent launchIntent = new Intent(Intent.ACTION_MAIN);
    launchIntent.setPackage(TEST_PACKAGE_LABEL);
    launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    ResolveInfo resolveInfo = new ResolveInfo();
    resolveInfo.activityInfo = new ActivityInfo();
    resolveInfo.activityInfo.packageName = TEST_PACKAGE_LABEL;
    resolveInfo.activityInfo.name = "LauncherActivity";
    Robolectric.packageManager.addResolveInfoForIntent(launchIntent, resolveInfo);
 
    intent = rpm.getLaunchIntentForPackage(TEST_PACKAGE_LABEL);
    assertThat(intent).isNotNull();
  } 
 
  @Test 
  public void shouldAssignTheAppMetaDataFromTheManifest() throws Exception { 
8
CodeRank
This code example shows how to use the following methods:addFlags, setPackage, toUri
     * Ask the current default engine to launch the matching INSTALL_TTS_DATA activity 
     * so the required TTS files are properly installed. 
     */ 
    private void installVoiceData() { 
        if (TextUtils.isEmpty(getEngineName())) return;
        Intent intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setPackage(getEngineName());
        try { 
            Log.v(TAG, "Installing voice data: " + intent.toUri(0));
            startActivity(intent);
        } catch (ActivityNotFoundException ex) {
            Log.e(TAG, "Failed to install TTS data, no acitivty found for " + intent + ")");
        } 
    } 
 
    @Override 
    public boolean onPreferenceClick(Preference preference) {
        if (preference == mInstallVoicesPreference) {
            installVoiceData(); 
8
CodeRank
This code example shows how to use the following methods:addCategory, setComponent, setFlags, setPackage
This code example shows how to use the following methods:addFlags, setPackage, queryIntentActivities
This code example shows how to use the following methods:resolveTypeIfNeeded, setPackage
     */ 
    private ComponentName findWebSearchActivity(ComponentName globalSearchActivity) {
        if (globalSearchActivity == null) {
            return null; 
        } 
        Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
        intent.setPackage(globalSearchActivity.getPackageName());
        List<ResolveInfo> activities =
                queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
 
        if (activities != null && !activities.isEmpty()) {
            ActivityInfo ai = activities.get(0).activityInfo;
            // TODO: do some sanity checks here? 
            return new ComponentName(ai.packageName, ai.name);
        } 
        Log.w(LOG_TAG, "No web search activity found");
        return null; 
    } 
 
    private List<ResolveInfo> queryIntentActivities(Intent intent, int flags) {

6
CodeRank
This code example shows how to use the following methods:addCategory, putExtra, setPackage
    public void startSearch(Context context, String query, Bundle appData, String extraData) {
        String uri = mSearchEngineInfo.getSearchUriForQuery(query);
        if (uri == null) {
            Log.e(TAG, "Unable to get search URI for " + mSearchEngineInfo);
        } else { 
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
            // Make sure the intent goes to the Browser itself 
            intent.setPackage(context.getPackageName());
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.putExtra(SearchManager.QUERY, query);
            if (appData != null) {
                intent.putExtra(SearchManager.APP_DATA, appData);
            } 
            if (extraData != null) {
                intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
            } 
            intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
            context.startActivity(intent);
        } 
    } 

8
CodeRank

Related Intent setPackage Questions & Answers:

setPackage Method Overview
(Usually optional) Set an explicit application package name that limits the components this Intent will resolve to.
See Code Examples for other Android Intent Methods: