Example usage for android.content Intent setPackage

List of usage examples for android.content Intent setPackage

Introduction

In this page you can find the example usage for android.content Intent setPackage.

Prototype

public @NonNull Intent setPackage(@Nullable String packageName) 

Source Link

Document

(Usually optional) Set an explicit application package name that limits the components this Intent will resolve to.

Usage

From source file:org.glucosio.android.activity.MainActivity.java

public void openSupportDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getResources().getString(R.string.menu_support_title));
    builder.setItems(getResources().getStringArray(R.array.menu_support_options),
            new DialogInterface.OnClickListener() {
                @Override//from  w  w w  .  j av  a2 s  . c o m
                public void onClick(DialogInterface dialog, int which) {
                    if (which == 0) {
                        // Email
                        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                                Uri.parse("mailto:hello@glucosio.org"));
                        boolean activityExists = emailIntent.resolveActivityInfo(getPackageManager(),
                                0) != null;

                        if (activityExists) {
                            startActivity(emailIntent);
                        } else {
                            showSnackBar(getResources().getString(R.string.menu_support_error1),
                                    Snackbar.LENGTH_LONG);
                        }
                    } else {
                        // Forum
                        String url = "http://community.glucosio.org/";
                        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        i.setPackage("com.android.chrome");
                        try {
                            startActivity(i);
                        } catch (ActivityNotFoundException e) {
                            // Chrome is probably not installed
                            // Try with the default browser
                            i.setPackage(null);
                            startActivity(i);
                        }
                    }
                }
            });
    builder.show();
}

From source file:com.neighbor.ex.tong.ui.activity.MainActivity2Activity.java

private void bindService() {
    Intent intent = null;
    try {//from w  w w .  ja  v  a2 s.  c  o m
        intent = new Intent(getApplication().getApplicationContext(),
                Class.forName(LppService.class.getName()));
        intent.setPackage("com.neighbor.ex.tong");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    if (intent != null) {
        getApplicationContext().bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
    }
}

From source file:org.anhonesteffort.flock.MigrationService.java

private void handleStartMigration() {
    Log.d(TAG, "handleStartMigration()");

    handleInitializeNotification();/*from   www .j  a  v a2 s  . c  om*/
    handleStartKickingMigration();

    KeyStore.setUseCipherVersionZero(getBaseContext(), true);

    if (DavAccountHelper.isUsingOurServers(getBaseContext())) {
        try {

            new RegistrationApi(getBaseContext()).setAccountVersion(account, 2);

        } catch (RegistrationApiException e) {
            handleException(e);
            return;
        } catch (IOException e) {
            handleException(e);
            return;
        }
    }

    Intent intent = new Intent();
    intent.setPackage(MigrationHelperBroadcastReceiver.class.getPackage().getName());
    intent.setAction(ACTION_MIGRATION_STARTED);
    sendBroadcast(intent);

    setState(STATE_STARTED_MIGRATION);
}

From source file:edu.stanford.mobisocial.dungbeetle.NearbyActivity.java

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    NearbyItem g = mAdapter.getItem(position);

    if (g.type == NearbyItem.Type.PERSON) {
        long cid = FriendRequest.getExistingContactId(this, g.uri);
        if (cid != -1) {
            Contact.view(this, cid);
        } else {//w ww  .  j  av a  2  s  .c o m
            toast("Added new friend...");
            cid = FriendRequest.acceptFriendRequest(mContext, g.uri, false);
            String cap = g.uri.getQueryParameter("cap");
            FriendRequest.sendFriendRequest(mContext, cid, cap);
            Contact.view(this, cid);
        }
        return;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(g.uri, g.mimeType);
    intent.setPackage(getPackageName());
    startActivity(intent);
}

From source file:com.android.providers.downloads.DownloadInfo.java

public void sendIntentIfRequested() {
    if (mPackage == null) {
        return;/* w ww  .j  a v  a 2s.c om*/
    }

    Intent intent;
    if (mIsPublicApi) {
        intent = new Intent(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
        intent.setPackage(mPackage);
        intent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, mId);
    } else { // legacy behavior
        if (mClass == null) {
            return;
        }
        intent = new Intent(Downloads.Impl.ACTION_DOWNLOAD_COMPLETED);
        intent.setClassName(mPackage, mClass);
        if (mExtras != null) {
            intent.putExtra(Downloads.Impl.COLUMN_NOTIFICATION_EXTRAS, mExtras);
        }
        // We only send the content: URI, for security reasons. Otherwise, malicious
        //     applications would have an easier time spoofing download results by
        //     sending spoofed intents.
        intent.setData(getMyDownloadsUri());
    }
    mSystemFacade.sendBroadcast(intent);
}

From source file:com.limemobile.app.plugin.PluginClientFragmentActivity.java

@Override
public void startActivity(Intent intent, Bundle options) {
    if (mProxyActivity == null) {
        super.startActivity(intent, options);
        return;//w ww.j a  va2s . c om
    }

    List<ResolveInfo> resolveInfos = mContext.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfos != null && !resolveInfos.isEmpty()) {
        super.startActivity(intent, options);
    } else {
        intent.setPackage(mPluginPackage.mPackageName);
        PluginClientManager.sharedInstance(mContext).startActivity(mContext, intent, options);
    }
}

From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java

/**
 * Called when download has been completed.
 * @param content content.//from w  ww  . j a v  a2s  . c o m
 */
void onDownloadComplete(CapptainReachInteractiveContent content) {
    /* Cancel alarm */
    Intent intent = new Intent(INTENT_ACTION_DOWNLOAD_TIMEOUT);
    intent.setPackage(mContext.getPackageName());
    int requestCode = (int) content.getLocalId();
    PendingIntent operation = PendingIntent.getBroadcast(mContext, requestCode, intent, 0);
    AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(operation);

    /* Update notification if not too late e.g. notification not yet dismissed */
    notifyPendingContent(content);
}

From source file:chaitanya.im.searchforreddit.LauncherActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // get and set theme from shared preferences
    sharedPref = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    theme = sharedPref.getInt(getString(R.string.style_pref_key), 0);
    donate = sharedPref.getInt(getString(R.string.donate_check), 0);
    UtilMethods.onActivityCreateSetTheme(this, theme, SOURCE);

    mServiceConn = new ServiceConnection() {
        @Override//from w ww  .  j  a v  a 2 s  . c o m
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);
            Log.d(TAG, "Service Connected");
            getPrices();
        }
    };

    //ComponentName myService = startService(new Intent(this, LauncherActivity.class));
    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

    // IAP stuff
    skuList = new ArrayList<>();
    skuList.add("donate");
    skuList.add("donate2");
    skuList.add("donate3");
    querySkus = new Bundle();
    querySkus.putStringArrayList("ITEM_ID_LIST", skuList);

    setContentView(R.layout.activity_launcher);

    // Obtain the FirebaseAnalytics instance.
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    fontAwesome = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf");
    dialog = new GenericAlertDialog();
    dialog.setFontAwesome(fontAwesome);
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    LinearLayout searchBox = (LinearLayout) findViewById(R.id.search_box);
    searchOptions = (LinearLayout) findViewById(R.id.search_options);
    launcherRefresh = (SwipeRefreshLayout) findViewById(R.id.launcher_refresh);
    searchEditText = (EditText) findViewById(R.id.search_edit_text);
    clearSearchBoxButton = (ImageButton) findViewById(R.id.clearSearchBox);
    //filterButton = (Button) findViewById(R.id.filter_button);
    sortButton = (Button) findViewById(R.id.sort_button);
    timeButton = (Button) findViewById(R.id.time_button);
    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.launcher_coordinatorlayout);
    searchOptions.post(new Runnable() {
        @Override
        public void run() {
            searchOptionsCenter = searchOptions.getWidth() / 2;
            if (searchOptions.getVisibility() != View.VISIBLE) {
                UtilMethods.revealView(searchOptions, searchOptionsCenter, 0);
            }
        }
    });
    setSupportActionBar(toolbar);

    searchEditText.setOnKeyListener(onKeyListener);
    searchEditText.setOnTouchListener(searchEditTextTouchListener);

    sortButton.setOnLongClickListener(buttonLongClick);
    timeButton.setOnLongClickListener(buttonLongClick);
    //filterButton.setOnLongClickListener(buttonLongClick);

    rvResults = (RecyclerView) findViewById(R.id.result_view_launcher);
    ResultsAdapter adapter = new ResultsAdapter(resultList, this);
    rvResults.setAdapter(adapter);
    rvResults.setLayoutManager(new LinearLayoutManager(this));
    rvResults.addItemDecoration(new SimpleDividerItemDecoration(this, theme));

    //rvResults.setRecyclerListener(recyclerListener);
    urlSearch = new UrlSearch(BASE_URL, this, 1, adapter);

    // dp -> px : http://stackoverflow.com/a/9563438/1055475
    Resources resources = getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float px = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(px * 4);
        searchBox.setElevation(px * 3);
    } else {
        findViewById(R.id.shadow).setVisibility(View.VISIBLE);
        findViewById(R.id.shadow2).setVisibility(View.VISIBLE);
    }
    Log.d(TAG, "OnCreate");
    Log.d(TAG, "searchEditText - " + searchEditText.getText().toString());

    launcherRefresh.setOnRefreshListener(refreshListener);
    launcherRefresh.setColorSchemeResources(R.color.blue_tint, R.color.reddit_orange,
            R.color.material_light_black);

    UtilMethods.getLocation();

    Intent intent = getIntent();
    receiveIntent(intent);
}

From source file:org.kontalk.billing.GoogleBillingService.java

/**
 * Starts the setup process. This will start up the setup process asynchronously.
 * You will be notified through the listener when the setup process is complete.
 * This method is safe to call from a UI thread.
 *
 * @param listener The listener to notify when the setup process is complete.
 *//*w w w .ja  v  a  2  s  .  c o m*/
public void startSetup(final OnBillingSetupFinishedListener listener) {
    // If already set up, can't do it again.
    checkNotDisposed();
    if (mSetupDone)
        throw new IllegalStateException("IAB helper is already set up.");

    // Connection to IAB service
    logDebug("Starting in-app billing setup.");
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            logDebug("Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            if (mDisposed)
                return;
            logDebug("Billing service connected.");
            mService = IInAppBillingService.Stub.asInterface(service);
            String packageName = mContext.getPackageName();
            try {
                logDebug("Checking for in-app billing 3 support.");

                // check for in-app billing v3 support
                int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    if (listener != null)
                        listener.onSetupFinished(
                                new BillingResult(response, "Error checking for billing v3 support."));

                    // if in-app purchases aren't supported, neither are subscriptions.
                    mSubscriptionsSupported = false;
                    return;
                }
                logDebug("In-app billing version 3 supported for " + packageName);

                // check for v3 subscriptions support
                response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS);
                if (response == BILLING_RESPONSE_RESULT_OK) {
                    logDebug("Subscriptions AVAILABLE.");
                    mSubscriptionsSupported = true;
                } else {
                    logDebug("Subscriptions NOT AVAILABLE. Response: " + response);
                }

                mSetupDone = true;
            } catch (RemoteException e) {
                if (listener != null) {
                    listener.onSetupFinished(new BillingResult(IABHELPER_REMOTE_EXCEPTION,
                            "RemoteException while setting up in-app billing."));
                }
                e.printStackTrace();
                return;
            }

            if (listener != null) {
                listener.onSetupFinished(new BillingResult(BILLING_RESPONSE_RESULT_OK, "Setup successful."));
            }
        }
    };

    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");

    List<ResolveInfo> services = mContext.getPackageManager().queryIntentServices(serviceIntent, 0);
    if (services != null && !services.isEmpty()) {
        // service available to handle that Intent
        mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    } else {
        // no service available to handle that Intent
        if (listener != null) {
            listener.onSetupFinished(new BillingResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                    "Billing service unavailable on device."));
        }
    }
}

From source file:org.chromium.chrome.browser.download.OMADownloadHandler.java

/**
 * Shows a dialog to ask whether user wants to open the nextURL.
 *
 * @param omaInfo Information about the OMA content.
 *//*  w  w w.j a v  a 2s  .c  o m*/
private void showNextUrlDialog(OMAInfo omaInfo) {
    if (omaInfo.isValueEmpty(OMA_NEXT_URL)) {
        return;
    }
    final String nextUrl = omaInfo.getValue(OMA_NEXT_URL);
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.next_url_post_oma_download, null);
    TextView textView = (TextView) v.findViewById(R.id.oma_download_next_url);
    textView.setText(nextUrl);
    final Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
    DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == AlertDialog.BUTTON_POSITIVE) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(nextUrl));
                intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
                intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
                intent.setPackage(mContext.getPackageName());
                activity.startActivity(intent);
            }
        }
    };
    new AlertDialog.Builder(activity).setTitle(R.string.open_url_post_oma_download)
            .setPositiveButton(R.string.ok, clickListener).setNegativeButton(R.string.cancel, clickListener)
            .setView(v).setCancelable(false).show();
}