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:com.android.tv.settings.users.AppRestrictionsFragment.java

/**
 * Send a broadcast to the app to query its restrictions
 * @param packageName package name of the app with restrictions
 * @param preference the preference item for the app toggle
 *//*w  ww.  jav  a 2s .c  o  m*/
private void requestRestrictionsForApp(String packageName, AppRestrictionsPreference preference) {
    Bundle oldEntries = mUserManager.getApplicationRestrictions(packageName, mUser);
    Intent intent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES);
    intent.setPackage(packageName);
    intent.putExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE, oldEntries);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    getActivity().sendOrderedBroadcast(intent, null, new RestrictionsResultReceiver(packageName, preference),
            null, Activity.RESULT_OK, null, null);
}

From source file:me.piebridge.prevent.ui.PreventActivity.java

private void showDisableDialog(String result) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.app_name) + "(" + BuildConfig.VERSION_NAME + ")");
    if (result == null) {
        builder.setMessage(R.string.xposed_disabled);
    } else {//from   w  w w.  jav  a  2  s . c  o m
        builder.setMessage(result);
    }
    builder.setIcon(R.drawable.ic_launcher);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent("de.robv.android.xposed.installer.OPEN_SECTION");
            intent.setPackage("de.robv.android.xposed.installer");
            intent.putExtra("section", "modules");
            intent.putExtra("module", getPackageName());
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                startActivity(intent);
            } catch (ActivityNotFoundException e) { // NOSONAR
                finish();
            }
        }
    });
    builder.create().show();
}

From source file:de.schildbach.wallet.elysium.service.BlockchainServiceImpl.java

private void sendBroadcastBlockchainState(final Date chainDate, final int chainHeight, final boolean replaying,
        final int download) {

    final Intent broadcast = new Intent(ACTION_BLOCKCHAIN_STATE);
    broadcast.setPackage(getPackageName());
    broadcast.putExtra(ACTION_BLOCKCHAIN_STATE_BEST_CHAIN_DATE, chainDate);
    broadcast.putExtra(ACTION_BLOCKCHAIN_STATE_BEST_CHAIN_HEIGHT, chainHeight);
    broadcast.putExtra(ACTION_BLOCKCHAIN_STATE_REPLAYING, replaying);
    broadcast.putExtra(ACTION_BLOCKCHAIN_STATE_DOWNLOAD, download);

    sendStickyBroadcast(broadcast);// ww  w . j  a v a2 s.c  o  m
}

From source file:com.mikecorrigan.bohrium.pubsub.RegistrationClient.java

private void c2dmRegister(Context context, String senderId) {
    Log.d(TAG, "c2dmRegister: context=" + context + ", senderId=" + senderId);

    Intent intent = new Intent(REQUEST_REGISTRATION_INTENT);
    intent.setPackage(GSF_PACKAGE);
    intent.putExtra(EXTRA_APPLICATION_PENDING_INTENT, PendingIntent.getBroadcast(context, 0, new Intent(), 0));
    intent.putExtra(EXTRA_SENDER, senderId);
    ComponentName name = context.startService(intent);
    if (name == null) {
        // Service not found.
        setStateAndNotify(REGISTRATION_STATE_ERROR, REGISTRATION_SUBSTATE_ERROR_C2DM_NOT_FOUND);
    }//from   ww  w  . ja v a2s  . c om
}

From source file:kr.go.hf.hfappandroid.app.intro.IntroActivity.java

@Override
protected void onDestroy() {
    if (mLoginCode == LOGIN_CODE_FAIL) {
        Intent realscan_intent = new Intent(Constants.VGUARD_SERVICE_NAME);
        if (realscan_intent != null) {
            realscan_intent.putExtra("VGUARD", "STOP_RUNAPP_SCAN");
            realscan_intent.putExtra("PKG", "kr.go.hf.hfappandroid");
            if (realscan_intent != null) {
                realscan_intent.setPackage("kr.co.ittech.bank");
                startService(realscan_intent);
            }//from w  w w. j av  a 2 s .  c om
        }
        CLog.e(TAG, "c finish");
    }
    super.onDestroy();
}

From source file:com.mikecorrigan.bohrium.pubsub.RegistrationClient.java

private void c2dmUnregister(Context context) {
    Log.d(TAG, "c2dmUnregister: context=" + context);

    Intent intent = new Intent(REQUEST_UNREGISTRATION_INTENT);
    intent.setPackage(GSF_PACKAGE);
    intent.putExtra(EXTRA_APPLICATION_PENDING_INTENT, PendingIntent.getBroadcast(context, 0, new Intent(), 0));
    ComponentName name = context.startService(intent);
    if (name == null) {
        // Service not found.
        setStateAndNotify(REGISTRATION_STATE_ERROR, REGISTRATION_SUBSTATE_ERROR_C2DM_NOT_FOUND);
    }//w  w  w .j  a v  a2s  . c  o m
}

From source file:com.soomla.store.billing.google.GoogleIabHelper.java

/**
 * See parent/*from   w w  w  .  j a  va 2s.  c  o  m*/
 */
protected void startSetupInner() {
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            SoomlaUtils.LogDebug(TAG, "Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            SoomlaUtils.LogDebug(TAG, "Billing service connected.");
            mService = IInAppBillingService.Stub.asInterface(service);
            String packageName = SoomlaApp.getAppContext().getPackageName();
            try {
                SoomlaUtils.LogDebug(TAG, "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 != IabResult.BILLING_RESPONSE_RESULT_OK) {
                    setupFailed(new IabResult(response, "Error checking for billing v3 support."));
                    return;
                }
                SoomlaUtils.LogDebug(TAG, "In-app billing version 3 supported for " + packageName);

                setupSuccess();
            } catch (RemoteException e) {
                setupFailed(new IabResult(IabResult.IABHELPER_REMOTE_EXCEPTION,
                        "RemoteException while setting up in-app billing."));
                e.printStackTrace();
            }
        }
    };

    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    List<ResolveInfo> intentServices = SoomlaApp.getAppContext().getPackageManager()
            .queryIntentServices(serviceIntent, 0);
    if (intentServices != null && !intentServices.isEmpty()) {
        // service available to handle that Intent
        SoomlaApp.getAppContext().bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    } else {
        // no service available to handle that Intent
        setupFailed(new IabResult(IabResult.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                "Billing service unavailable on device."));
    }
}

From source file:com.soomla.store.billing.tapclash.TapClashIabHelper.java

/**
 * See parent/*from   w ww  . ja  va  2  s.  c  o  m*/
 */
protected void startSetupInner() {
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            SoomlaUtils.LogDebug(TAG, "Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            SoomlaUtils.LogDebug(TAG, "Billing service connected.");
            mService = IInAppBillingService.Stub.asInterface(service);
            String packageName = SoomlaApp.getAppContext().getPackageName();
            try {
                SoomlaUtils.LogDebug(TAG, "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 != IabResult.BILLING_RESPONSE_RESULT_OK) {
                    setupFailed(new IabResult(response, "Error checking for billing v3 support."));
                    return;
                }
                SoomlaUtils.LogDebug(TAG, "In-app billing version 3 supported for " + packageName);

                setupSuccess();
            } catch (RemoteException e) {
                setupFailed(new IabResult(IabResult.IABHELPER_REMOTE_EXCEPTION,
                        "RemoteException while setting up in-app billing."));
                e.printStackTrace();
            }
        }
    };

    Intent serviceIntent = new Intent("com.gametree.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.gametree.estore");
    List<ResolveInfo> intentServices = SoomlaApp.getAppContext().getPackageManager()
            .queryIntentServices(serviceIntent, 0);
    if (intentServices != null && !intentServices.isEmpty()) {
        // service available to handle that Intent
        SoomlaApp.getAppContext().bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    } else {
        // no service available to handle that Intent
        setupFailed(new IabResult(IabResult.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                "Billing service unavailable on device."));
    }
}

From source file:com.e2g.ecocicle.barcode.IntentIntegrator.java

/**
 * Shares the given text by encoding it as a barcode, such that another user can
 * scan the text off the screen of the device.
 *
 * @param text the text string to encode as a barcode
 * @param type type of data to encode. See {@code com.google.zxing.client.android.Contents.Type} constants.
 * @return the {@link android.app.AlertDialog} that was shown to the user prompting them to download the app
 *   if a prompt was needed, or null otherwise
 *//*from w ww . ja v  a  2 s .  com*/
public final AlertDialog shareText(CharSequence text, CharSequence type) {
    Intent intent = new Intent();
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setAction(BS_PACKAGE + ".ENCODE");
    intent.putExtra("ENCODE_TYPE", type);
    intent.putExtra("ENCODE_DATA", text);
    String targetAppPackage = findTargetAppPackage(intent);
    if (targetAppPackage == null) {
        return showDownloadDialog();
    }
    intent.setPackage(targetAppPackage);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    attachMoreExtras(intent);
    if (fragment == null) {
        activity.startActivity(intent);
    } else {
        fragment.startActivity(intent);
    }
    return null;
}

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

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_ACTIVITY_CALLOUT) {
        mCurrentCallout.handleResult(resultCode, data);
        return;/*from w w  w  . j a v a 2  s.c o m*/
    }

    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (result != null && result.getContents() != null) {
        try {
            Uri uri = Uri.parse(result.getContents());
            Intent i = new Intent(Intent.ACTION_VIEW, uri);
            i.setPackage(getPackageName());
            startActivity(i);
            finish();
        } catch (IllegalArgumentException e) {
        }
        return;
    }
    if (requestCode == RESULT_BT_ENABLE) {
        if (resultCode == Activity.RESULT_CANCELED) {
            finish();
        } else {
            findBluetooth();
        }
    }
}