List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:net.sourceforge.servestream.activity.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }//from w w w . j a v a2 s .c o m // Handle action buttons switch (item.getItemId()) { case (R.id.menu_item_settings): startActivity(new Intent(this, SettingsActivity.class)); return true; case (R.id.menu_item_scan): try { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.setPackage("com.google.zxing.client.android"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, 0); } catch (ActivityNotFoundException ex) { showDialog(DOWNLOAD_SCANNER_DIALOG); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.mb.android.playbackmediator.notification.VideoCastNotificationService.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void buildForLollipopAndAbove(SessionInfoDto info, Bitmap bitmap, boolean isPlaying) throws CastException, TransientNetworkDisconnectionException, NoConnectionException { // Playback PendingIntent Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK); playbackIntent.setPackage(getPackageName()); PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0); // Disconnect PendingIntent Intent stopIntent = new Intent(ACTION_STOP); stopIntent.setPackage(getPackageName()); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0); // Main Content PendingIntent mTargetActivity = RemoteControlActivity.class; Intent contentIntent = new Intent(this, mTargetActivity); contentIntent.putExtra("LAUNCHED_BY_NOTIFICATION", true); // Media metadata String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(mTargetActivity); stackBuilder.addNextIntent(contentIntent); PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT); mNotification = new Notification.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification) .setContentTitle(info.getNowPlayingItem().getName()).setContentText(castingTo) .setContentIntent(contentPendingIntent).setLargeIcon(bitmap) .addAction(isPlaying ? R.drawable.ic_av_pause_dark : R.drawable.ic_av_play_dark, "Pause", playbackPendingIntent) .addAction(R.drawable.ic_cast_stop_wht, "Disconnect", stopPendingIntent) .setStyle(new Notification.MediaStyle().setShowActionsInCompactView(new int[] { 0, 1 })) .setOngoing(true).setShowWhen(false).setVisibility(Notification.VISIBILITY_PUBLIC).build(); }
From source file:com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService.java
/** * Returns the {@link NotificationCompat.Action} for toggling play/pause/stop of the currently * playing item./*from w w w. j av a 2 s . c om*/ */ protected NotificationCompat.Action getPlayPauseAction(MediaInfo info, boolean isPlaying) { int pauseOrStopResourceId; if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) { pauseOrStopResourceId = R.drawable.ic_notification_stop_48dp; } else { pauseOrStopResourceId = R.drawable.ic_notification_pause_48dp; } int pauseOrPlayTextResourceId = isPlaying ? R.string.ccl_pause : R.string.ccl_play; int pauseOrPlayResourceId = isPlaying ? pauseOrStopResourceId : R.drawable.ic_notification_play_48dp; Intent intent = new Intent(ACTION_TOGGLE_PLAYBACK); intent.setPackage(getPackageName()); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); return new NotificationCompat.Action.Builder(pauseOrPlayResourceId, getString(pauseOrPlayTextResourceId), pendingIntent).build(); }
From source file:com.nokia.example.pepperfarm.iap.Payment.java
/** * Binds to Nokia in-app payment service. * * @param ctx/*w w w . j a v a2 s. c o m*/ * @throws GeneralSecurityException If Nokia In-App payment enabler fingerprint is not valid */ public void connectToService(Context ctx) throws GeneralSecurityException { activity = (Activity) ctx; //Verifies enabler fingerprint if (!verifyFingreprint()) { npayAvailable = false; errorAlert("Nokia In-App Payment Enabler is not available."); throw new GeneralSecurityException("Enabler fingerprint incorrect. Billing unavailable"); } else { //Enabler fingerprint OK. Continue with binding. Intent paymentEnabler = new Intent("com.nokia.payment.iapenabler.InAppBillingService.BIND"); paymentEnabler.setPackage(ENABLER_PACKAGENAME); activity.bindService(paymentEnabler, this, Context.BIND_AUTO_CREATE); } }
From source file:com.limemobile.app.plugin.PluginHostDelegateFragmentActivity.java
@Override public void startActivityForResult(Intent intent, int requestCode, Bundle options) { List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfos == null || resolveInfos.isEmpty()) { intent.setPackage(mDelegatedActivity.getPackageName()); } else {// w w w.ja va2 s.c om super.startActivityForResult(intent, requestCode, options); return; } PluginClientManager.sharedInstance(this).startActivityForResult(this, intent, requestCode, options); }
From source file:com.limemobile.app.plugin.PluginHostDelegateFragmentActivity.java
@Override public boolean bindService(Intent service, ServiceConnection conn, int flags) { List<ResolveInfo> resolveInfos = getPackageManager().queryIntentServices(service, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfos == null || resolveInfos.isEmpty()) { service.setPackage(mDelegatedActivity.getPackageName()); } else {/* w w w. j a va 2s. c o m*/ return super.bindService(service, conn, flags); } return PluginClientManager.sharedInstance(this).bindService(this, service, conn, flags); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppReferenceObj.java
@Override public void handleDirectMessage(Context context, Contact from, JSONObject obj) { String packageName = obj.optString(PACKAGE_NAME); String arg = obj.optString(ARG); Intent launch = new Intent(); launch.setAction(Intent.ACTION_MAIN); launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.putExtra(AppState.EXTRA_APPLICATION_ARGUMENT, arg); launch.putExtra("creator", false); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); launch.setPackage(packageName); final PackageManager mgr = context.getPackageManager(); List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0); if (resolved == null || resolved.size() == 0) { Toast.makeText(context, "Could not find application to handle invite", Toast.LENGTH_SHORT).show(); return;//from www . j a v a 2 s.c o m } ActivityInfo info = resolved.get(0).activityInfo; launch.setComponent(new ComponentName(info.packageName, info.name)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch, PendingIntent.FLAG_CANCEL_CURRENT); (new PresenceAwareNotify(context)).notify("New Invitation", "Invitation received from " + from.name, "Click to launch application.", contentIntent); }
From source file:com.android.settings.SettingsLicenseActivity.java
private void showHtmlFromUri(Uri uri) { // Kick off external viewer due to WebView security restrictions; we // carefully point it at HTMLViewer, since it offers to decompress // before viewing. final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "text/html"); intent.putExtra(Intent.EXTRA_TITLE, getString(R.string.settings_license_activity_title)); if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); }/*www .ja v a 2s. c om*/ intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setPackage("com.android.htmlviewer"); try { startActivity(intent); finish(); } catch (ActivityNotFoundException e) { Log.e(TAG, "Failed to find viewer", e); showErrorAndFinish(); } }
From source file:fr.bde_eseo.eseomega.events.EventsFragment.java
@Override public View onCreateView(LayoutInflater rootInfl, ViewGroup container, Bundle savedInstanceState) { // UI//from w w w . j av a 2 s . co m View rootView = rootInfl.inflate(R.layout.fragment_event_list, container, false); swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.events_refresh); swipeRefreshLayout.setColorSchemeColors(R.color.md_blue_800); progCircle = (ProgressBar) rootView.findViewById(R.id.progressEvent); tv1 = (TextView) rootView.findViewById(R.id.tvListNothing); tv2 = (TextView) rootView.findViewById(R.id.tvListNothing2); img = (ImageView) rootView.findViewById(R.id.imgNoEvent); progCircle.setVisibility(View.GONE); progCircle.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.md_grey_500), PorterDuff.Mode.SRC_IN); tv1.setVisibility(View.GONE); tv2.setVisibility(View.GONE); img.setVisibility(View.GONE); disabler = new RecyclerViewDisabler(); // I/O cache data cachePath = getActivity().getCacheDir() + "/"; cacheFileEseo = new File(cachePath + "events.json"); // Init static model TicketStore.getInstance().reset(); // Model / objects eventItems = TicketStore.getInstance().getEventItems(); mAdapter = new MyEventsAdapter(getActivity(), eventItems); recList = (RecyclerView) rootView.findViewById(R.id.recyList); recList.setAdapter(mAdapter); recList.setHasFixedSize(false); LinearLayoutManager llm = new LinearLayoutManager(getActivity()); llm.setOrientation(LinearLayoutManager.VERTICAL); recList.setLayoutManager(llm); mAdapter.setEventItems(eventItems); mAdapter.notifyDataSetChanged(); // Start download of data AsyncJSON asyncJSON = new AsyncJSON(true); // circle needed for first call asyncJSON.execute(Constants.URL_JSON_EVENTS); // On click listener recList.addOnItemTouchListener( new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { final EventItem ei = eventItems.get(position); if (!ei.isHeader()) { boolean hasUrl = ei.getUrl() != null && ei.getUrl().length() != 0; boolean hasPlace = ei.getLieu() != null && ei.getLieu().length() != 0; boolean isAllDay = false; MaterialDialog.Builder mdb = new MaterialDialog.Builder(getActivity()) .customView(R.layout.dialog_event, false).positiveText("Ajouter au calendrier"); if (hasUrl) mdb.neutralText("Consulter le site"); if (hasPlace) mdb.negativeText("Y aller"); mdb.callback(new MaterialDialog.ButtonCallback() { @Override public void onNegative(MaterialDialog dialog) { // Intent : go to address super.onNegative(dialog); try { Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + Uri.encode(ei.getLieu())); Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); mapIntent.setPackage("com.google.android.apps.maps"); startActivity(mapIntent); } catch (ActivityNotFoundException ex) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps")); startActivity(intent); } } @Override public void onPositive(MaterialDialog dialog) { // Intent : add to calendar super.onPositive(dialog); startActivity(ei.toCalendarIntent()); } @Override public void onNeutral(MaterialDialog dialog) { // Intent : go to website super.onNeutral(dialog); String url = ei.getUrl(); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } }); MaterialDialog md = mdb.show(); View mdView = md.getView(); ((TextView) mdView.findViewById(R.id.tvEventName)).setText(ei.getName()); (mdView.findViewById(R.id.rlBackDialogEvent)).setBackgroundColor(ei.getColor()); if (ei.getDetails() != null && ei.getDetails().length() > 0) { ((TextView) mdView.findViewById(R.id.tvEventDetails)).setText(ei.getDetails()); } else { ((TextView) mdView.findViewById(R.id.tvEventDetails)) .setText("Que souhaitez vous faire ?"); } if (ei.getLieu() != null && ei.getLieu().length() > 0) { ((TextView) mdView.findViewById(R.id.tvEventPlace)) .setText("Lieu : " + ei.getLieu()); ((TextView) mdView.findViewById(R.id.tvEventPlace)).setVisibility(View.VISIBLE); } else { ((TextView) mdView.findViewById(R.id.tvEventPlace)).setVisibility(View.GONE); } } } })); // Swipe-to-refresh implementations timestamp = 0; swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { //Toast.makeText(getActivity(), "Refreshing ...", Toast.LENGTH_SHORT).show(); long t = System.currentTimeMillis() / 1000; if (t - timestamp > LATENCY_REFRESH) { // timestamp in seconds) timestamp = t; AsyncJSON asyncJSON = new AsyncJSON(false); // no circle here (already in SwipeLayout) asyncJSON.execute(Constants.URL_JSON_EVENTS); } else { swipeRefreshLayout.setRefreshing(false); } } }); return rootView; }
From source file:es.uma.lcc.tasks.EncryptionUploaderTask.java
private void showGooglePlusShareButton(String path) { Button shareButton = (Button) mMainActivity.findViewById(R.id.shareButton); shareButton.setVisibility(View.VISIBLE); final String file = path; shareButton.setOnClickListener(new OnClickListener() { @Override// w w w . j av a2s . c o m public void onClick(View v) { File f = new File(file); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("image/jpeg"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); intent.setPackage("com.google.android.apps.plus"); try { mMainActivity.startActivity(intent); } catch (ActivityNotFoundException anfex) { intent.setPackage(null); mMainActivity.startActivity(intent); } } }); }