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.doplgangr.secrecy.views.FileViewer.java

private Intent generateCustomChooserIntent(Intent prototype, ArrayList<Uri> uris) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    List<HashMap<String, String>> intentMetaInfo = new ArrayList<HashMap<String, String>>();
    Intent chooserIntent;/*from  w  w w  .  ja v  a  2 s  .com*/

    Intent dummy = new Intent(prototype.getAction());
    dummy.setType(prototype.getType());
    List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(dummy, 0);

    if (!resInfo.isEmpty()) {
        for (ResolveInfo resolveInfo : resInfo) {
            if (resolveInfo.activityInfo == null
                    || resolveInfo.activityInfo.packageName.equalsIgnoreCase("com.doplgangr.secrecy"))
                continue;

            HashMap<String, String> info = new HashMap<String, String>();
            info.put("packageName", resolveInfo.activityInfo.packageName);
            info.put("className", resolveInfo.activityInfo.name);
            info.put("simpleName",
                    String.valueOf(resolveInfo.activityInfo.loadLabel(context.getPackageManager())));
            intentMetaInfo.add(info);
            for (Uri uri : uris)
                context.grantUriPermission(resolveInfo.activityInfo.packageName, uri,
                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }

        if (!intentMetaInfo.isEmpty()) {
            // sorting for nice readability
            Collections.sort(intentMetaInfo, new Comparator<HashMap<String, String>>() {
                @Override
                public int compare(HashMap<String, String> map, HashMap<String, String> map2) {
                    return map.get("simpleName").compareTo(map2.get("simpleName"));
                }
            });

            // create the custom intent list
            for (HashMap<String, String> metaInfo : intentMetaInfo) {
                Intent targetedShareIntent = (Intent) prototype.clone();
                targetedShareIntent.setPackage(metaInfo.get("packageName"));
                targetedShareIntent.setClassName(metaInfo.get("packageName"), metaInfo.get("className"));
                targetedShareIntents.add(targetedShareIntent);
            }
            chooserIntent = Intent.createChooser(targetedShareIntents.remove(targetedShareIntents.size() - 1),
                    CustomApp.context.getString(R.string.Dialog__send_file));
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                    targetedShareIntents.toArray(new Parcelable[targetedShareIntents.size()]));
            return chooserIntent;
        }
    }

    return new Intent(Intent.ACTION_SEND); //Unable to do anything. Duh.
}

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

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

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_PROGRESS);

    setContentView(R.layout.simple_fragment_activity);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setTitle(R.string.title_manage_subscription);

    if (savedInstanceState != null && !savedInstanceState.isEmpty()) {
        if (!DavAccount.build(savedInstanceState.getBundle(KEY_DAV_ACCOUNT_BUNDLE)).isPresent()) {
            Log.e(TAG, "where did my dav account bundle go?! :(");
            finish();/*from  w  w  w.  j av a 2 s  .  c o  m*/
            return;
        }

        davAccount = DavAccount.build(savedInstanceState.getBundle(KEY_DAV_ACCOUNT_BUNDLE)).get();
        currentFragment = savedInstanceState.getInt(KEY_CURRENT_FRAGMENT, -1);
        activityRequestCode = Optional.fromNullable(savedInstanceState.getInt(KEY_REQUEST_CODE));
        activityResultCode = Optional.fromNullable(savedInstanceState.getInt(KEY_RESULT_CODE));
        activityResultData = Optional.fromNullable((Intent) savedInstanceState.getParcelable(KEY_RESULT_DATA));
    } else if (getIntent().getExtras() != null) {
        if (!DavAccount.build(getIntent().getExtras().getBundle(KEY_DAV_ACCOUNT_BUNDLE)).isPresent()) {
            Log.e(TAG, "where did my dav account bundle go?! :(");
            finish();
            return;
        }

        davAccount = DavAccount.build(getIntent().getExtras().getBundle(KEY_DAV_ACCOUNT_BUNDLE)).get();
        currentFragment = getIntent().getExtras().getInt(KEY_CURRENT_FRAGMENT, -1);
        activityRequestCode = Optional.fromNullable(getIntent().getExtras().getInt(KEY_REQUEST_CODE));
        activityResultCode = Optional.fromNullable(getIntent().getExtras().getInt(KEY_RESULT_CODE));
        activityResultData = Optional
                .fromNullable((Intent) getIntent().getExtras().getParcelable(KEY_RESULT_DATA));
    }

    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
}

From source file:com.pemikir.youtubeplus.ActionBarHandler.java

public void playWithKodi() {
    if (!videoTitle.isEmpty()) {
        try {/*from   ww w  . j a va  2s  .  c om*/
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setPackage(KORE_PACKET);
            intent.setData(Uri.parse(webisteUrl.replace("https", "http")));
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage(R.string.koreNotFound)
                    .setPositiveButton(R.string.installeKore, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent();
                            intent.setAction(Intent.ACTION_VIEW);
                            intent.setData(Uri.parse(context.getString(R.string.fdroidKoreUrl)));
                            context.startActivity(intent);
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    });
            builder.create().show();
        }
    }
}

From source file:com.tingtingapps.securesms.service.KeyCachingService.java

private void broadcastNewSecret() {
    Log.w("service", "Broadcasting new secret...");

    Intent intent = new Intent(NEW_KEY_EVENT);
    intent.setPackage(getApplicationContext().getPackageName());

    sendBroadcast(intent, KEY_PERMISSION);
}

From source file:com.samuelcastro.cordova.InstagramSharePlugin.java

private void shareVideo(String videoString, String captionString) {

    // Create the URI from the media
    File media = new File(this.getRealVideoPathFromURI(Uri.parse(videoString)));
    Uri uri = Uri.fromFile(media);//from   w  ww.  java  2s  . com

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("video/*");
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.putExtra(Intent.EXTRA_TEXT, captionString);
    shareIntent.setPackage("com.instagram.android");

    this.cordova.startActivityForResult((CordovaPlugin) this, shareIntent, 12345);

}

From source file:com.android.tv.settings.about.AboutFragment.java

private void sendFeedback() {
    String reporterPackage = DeviceInfoUtils.getFeedbackReporterPackage(getActivity());
    if (TextUtils.isEmpty(reporterPackage)) {
        return;//from   w w w  . ja v a2 s.  com
    }
    Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
    intent.setPackage(reporterPackage);
    startActivityForResult(intent, 0);
}

From source file:com.xamoom.android.xamoomcontentblocks.XamoomMapFragment.java

private void showActiveMarker(final Marker marker) {
    mActiveMarker = marker;//from www  .  j ava2 s. co  m
    mActiveMarker.showInfoWindow();
    zoomToMarker(mActiveMarker, false);
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
    mFloatingActionButton.show();

    final Spot spot = mMarkerSpotMap.get(marker);

    mSpotTitleTextView.setText(spot.getName());
    mSpotExcerptTextView.setText(spot.getDescription());
    Glide.with(this).load(spot.getPublicImageUrl()).into(mSpotImageView);

    if (spot.getContent() != null && spot.getContent().getId() != null) {
        mSpotContentButton.setVisibility(View.VISIBLE);
        final String contentId = spot.getContent().getId();
        mSpotContentButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.clickedSpotMapContentLink(contentId);
            }
        });
    } else {
        mSpotContentButton.setVisibility(View.GONE);
    }

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            double lat = marker.getPosition().latitude;
            double lon = marker.getPosition().longitude;
            String query = lat + "," + lon + "(" + spot.getName() + ")";
            Uri gmmIntentUri = Uri.parse("geo:" + lat + "+," + lon + "?q=" + query);
            Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
            mapIntent.setPackage("com.google.android.apps.maps");
            if (mapIntent.resolveActivity(getContext().getPackageManager()) != null) {
                startActivity(mapIntent);
            }
        }
    });
}

From source file:com.parse.CN1ParsePushBroadcastReceiver.java

@Override
protected void onPushReceive(Context context, Intent intent) {
    /*//from  w w w.jav a  2 s .co  m
     Adapted from ParsePushBroadcastReceiver.onPushReceived(). Main changes:
     1. Implemented callbacks to ParsePush with the push payload based on
    app state
     */

    JSONObject pushData = null;
    try {
        pushData = new JSONObject(intent.getStringExtra(ParsePushBroadcastReceiver.KEY_PUSH_DATA));
    } catch (JSONException e) {
        writeErrorLog("Unexpected JSONException when parsing received push data:\n" + e);
    }
    writeDebugLog("Push received: " + (pushData == null ? "<no payload>" : pushData.toString()));

    boolean handled = false;
    if (pushData != null && CN1AndroidApplication.isAppRunning()) {
        if (CN1AndroidApplication.isAppInForeground()) {
            writeDebugLog("App in foreground; will allow app to directly handle push message, if desired");
            handled = ParsePush.handlePushReceivedForeground(pushData.toString());
        } else if (CN1AndroidApplication.isAppInBackground()) {
            writeDebugLog("App in background; will allow app to directly handle push message, if desired");
            handled = ParsePush.handlePushReceivedBackground(pushData.toString());
        }
    }

    if (!handled) {
        // If the push data includes an action string, that broadcast intent is fired.
        String action = null;
        if (pushData != null) {
            action = pushData.optString("action", null);
        }
        if (action != null) {
            writeDebugLog("Firing broadcast for action " + action);
            Bundle extras = intent.getExtras();
            Intent broadcastIntent = new Intent();
            broadcastIntent.putExtras(extras);
            broadcastIntent.setAction(action);
            broadcastIntent.setPackage(context.getPackageName());
            context.sendBroadcast(broadcastIntent);
        }

        Notification notification = getNotification(context, intent);

        if (notification != null) {
            writeDebugLog("Scheduling notification for push message since it was not handled by app");
            ParseNotificationManager.getInstance().showNotification(context, notification);
        } else {
            // If, for any reason, creating the notification fails (typically because
            // the push is a 'hidden' push with no alert/title fields),
            // store it for later processing.
            if (pushData != null) {
                writeDebugLog("Requesting ParsePush to handle unprocessed (hidden?) push message");
                ParsePush.handleUnprocessedPushReceived(pushData.toString());
            }
        }
    } else {
        writeDebugLog("Push already handled by app so not scheduling any notification");
    }
}

From source file:com.securecomcode.text.service.KeyCachingService.java

private void broadcastNewSecret() {
    Log.w("service", "Broadcasting new secret...");

    Intent intent = new Intent(NEW_KEY_EVENT);
    intent.putExtra("master_secret", masterSecret);
    intent.setPackage(getApplicationContext().getPackageName());

    sendBroadcast(intent, KEY_PERMISSION);
}

From source file:com.subzero.runners.android.AndroidLauncher.java

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

    //       Create the GameHelper
    _gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
    _gameHelper.enableDebugLog(false);// www . j  a v a  2s. c  o  m

    GameHelperListener gameHelperListener = new GameHelper.GameHelperListener() {

        @Override
        public void onSignInSucceeded() {
            // TODO Auto-generated method stub

        }

        @Override
        public void onSignInFailed() {
            // TODO Auto-generated method stub

        }
    };

    _gameHelper.setup(gameHelperListener);

    //      signIn();

    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    //      queryPurchases();

    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    config.useImmersiveMode = true;
    initialize(new Runners(this), config);
}