List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:com.scoreflex.ScoreflexView.java
/** * The constructor of the view./* ww w . j a va2 s . c o m*/ * @param activity The activity holding the view. * @param attrs * @param defStyle */ @SuppressWarnings("deprecation") public ScoreflexView(Activity activity, AttributeSet attrs, int defStyle) { super(activity, attrs, defStyle); // Keep a reference on the activity mParentActivity = activity; // Default layout params if (null == getLayoutParams()) { setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Scoreflex.getDensityIndependantPixel(R.dimen.scoreflex_panel_height))); } // Set our background color setBackgroundColor(getContext().getResources().getColor(R.color.scoreflex_background_color)); // Create the top bar View topBar = new View(getContext()); topBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height), Gravity.TOP)); topBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.scoreflex_gradient_background)); addView(topBar); // Create the retry button LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); mErrorLayout = (ViewGroup) inflater.inflate(R.layout.scoreflex_error_layout, null); if (mErrorLayout != null) { // Configure refresh button Button refreshButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_retry_button); if (null != refreshButton) { refreshButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (null == Scoreflex.getPlayerId()) { setUserInterfaceState(new LoadingState()); loadUrlAfterLoggedIn(mInitialResource, mInitialRequestParams); } else if (null == mWebView.getUrl()) { setResource(mInitialResource); } else { mWebView.reload(); } } }); } // Configure cancel button Button cancelButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_cancel_button); if (null != cancelButton) { cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { close(); } }); } // Get hold of the message view mMessageView = (TextView) mErrorLayout.findViewById(R.id.scoreflex_error_message_view); addView(mErrorLayout); } // Create the close button mCloseButton = new ImageButton(getContext()); Drawable closeButtonDrawable = getResources().getDrawable(R.drawable.scoreflex_close_button); int closeButtonMargin = (int) ((getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height) - closeButtonDrawable.getIntrinsicHeight()) / 2.0f); FrameLayout.LayoutParams closeButtonLayoutParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT); closeButtonLayoutParams.setMargins(0, closeButtonMargin, closeButtonMargin, 0); mCloseButton.setLayoutParams(closeButtonLayoutParams); mCloseButton.setImageDrawable(closeButtonDrawable); mCloseButton.setBackgroundDrawable(null); mCloseButton.setPadding(0, 0, 0, 0); mCloseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { close(); } }); addView(mCloseButton); // Create the web view mWebView = new WebView(mParentActivity); mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // mWebView.setBackgroundColor(Color.RED); mWebView.setWebViewClient(new ScoreflexWebViewClient()); mWebView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage cm) { Log.d("Scoreflex", "javascript Error: " + String.format("%s @ %d: %s", cm.message(), cm.lineNumber(), cm.sourceId())); return true; } public void openFileChooser(ValueCallback<Uri> uploadMsg) { // mtbActivity.mUploadMessage = uploadMsg; mUploadMessage = uploadMsg; String fileName = "picture.jpg"; ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, fileName); // mOutputFileUri = mParentActivity.getContentResolver().insert( // MediaStore.Images.Media.DATA, values); final List<Intent> cameraIntents = new ArrayList<Intent>(); final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); final PackageManager packageManager = mParentActivity.getPackageManager(); final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : listCam) { final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(packageName); cameraIntents.add(intent); } // Filesystem. final Intent galleryIntent = new Intent(); galleryIntent.setType("image/*"); galleryIntent.setAction(Intent.ACTION_GET_CONTENT); // Chooser of filesystem options. final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source please"); // Add the camera options. chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {})); mParentActivity.startActivityForResult(chooserIntent, Scoreflex.FILECHOOSER_RESULTCODE); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { openFileChooser(uploadMsg); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg); } }); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setDomStorageEnabled(true); mWebView.getSettings().setDatabasePath( getContext().getFilesDir().getPath() + "/data/" + getContext().getPackageName() + "/databases/"); addView(mWebView); TypedArray a = mParentActivity.obtainStyledAttributes(attrs, R.styleable.ScoreflexView, defStyle, 0); String resource = a.getString(R.styleable.ScoreflexView_resource); if (null != resource) setResource(resource); a.recycle(); // Create the animated spinner mProgressBar = (ProgressBar) ((LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.scoreflex_progress_bar, null); mProgressBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER)); addView(mProgressBar); LocalBroadcastManager.getInstance(activity).registerReceiver(mLoginReceiver, new IntentFilter(Scoreflex.INTENT_USER_LOGED_IN)); setUserInterfaceState(new InitialState()); }
From source file:com.forrestguice.suntimeswidget.SuntimesActivity.java
/** * Show the location on a map./* w w w . ja va 2 s. c o m*/ * Intent filtering code based off answer by "gumberculese"; * http://stackoverflow.com/questions/5734678/custom-filtering-of-intent-chooser-based-on-installed-android-package-name */ protected void showMap() { Intent mapIntent = new Intent(Intent.ACTION_VIEW); mapIntent.setData(location.getUri()); //if (mapIntent.resolveActivity(getPackageManager()) != null) //{ // startActivity(mapIntent); //} String myPackage = "com.forrestguice.suntimeswidget"; List<ResolveInfo> info = getPackageManager().queryIntentActivities(mapIntent, 0); List<Intent> geoIntents = new ArrayList<Intent>(); if (!info.isEmpty()) { for (ResolveInfo resolveInfo : info) { String packageName = resolveInfo.activityInfo.packageName; if (!TextUtils.equals(packageName, myPackage)) { Intent geoIntent = new Intent(Intent.ACTION_VIEW); geoIntent.setPackage(packageName); geoIntent.setData(location.getUri()); geoIntents.add(geoIntent); } } } if (geoIntents.size() > 0) { Intent chooserIntent = Intent.createChooser(geoIntents.remove(0), getString(R.string.configAction_mapLocation_chooser)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, geoIntents.toArray(new Parcelable[geoIntents.size()])); startActivity(chooserIntent); } else { Toast noAppError = Toast.makeText(this, getString(R.string.configAction_mapLocation_noapp), Toast.LENGTH_LONG); noAppError.show(); } }
From source file:com.firefly.sample.castcompanionlibrary.cast.VideoCastManager.java
private boolean startNotificationService() { if (!isFeatureEnabled(FEATURE_NOTIFICATION)) { return true; }/*w w w . ja v a2 s . c o m*/ LOGD(TAG, "startNotificationService() "); Intent service = new Intent(mContext, VideoCastNotificationService.class); service.setPackage(mContext.getPackageName()); return null != mContext.startService(service); }
From source file:org.mariotaku.twidere.activity.MediaViewerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { final ViewPager viewPager = findViewPager(); final PagerAdapter adapter = viewPager.getAdapter(); final int currentItem = viewPager.getCurrentItem(); if (currentItem < 0 || currentItem >= adapter.getCount()) return false; final Object object = adapter.instantiateItem(viewPager, currentItem); if (!(object instanceof MediaViewerFragment)) return false; switch (item.getItemId()) { case R.id.refresh: { if (object instanceof CacheDownloadMediaViewerFragment) { final CacheDownloadMediaViewerFragment fragment = (CacheDownloadMediaViewerFragment) object; fragment.startLoading(true); fragment.showProgress(true, 0); fragment.setMediaViewVisible(false); }// w w w . ja va2 s . c o m return true; } case R.id.share: { if (object instanceof CacheDownloadMediaViewerFragment) { requestAndShareMedia(currentItem); } else { final ParcelableMedia media = getMedia()[currentItem]; final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, media.url); startActivity(Intent.createChooser(intent, getString(R.string.share))); } return true; } case R.id.save: { requestAndSaveToStorage(currentItem); return true; } case R.id.open_in_browser: { final ParcelableMedia media = getMedia()[currentItem]; try { final Uri uri = Uri.parse(media.url); final Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setPackage(IntentUtils.getDefaultBrowserPackage(this, uri, true)); startActivity(intent); } catch (ActivityNotFoundException e) { // TODO show error, or improve app url } return true; } case android.R.id.home: { finish(); return true; } } return super.onOptionsItemSelected(item); }
From source file:ir.rasen.charsoo.view.fragment.FragmentUserRegisterOfferFriendInvite.java
@Override public void onItemClicked(String itemTag) { Intent myIntent; switch (itemTag) { case Params.EMAIL_APP: (view.findViewById(R.id.ll_EmailListContainer)).setVisibility(View.VISIBLE); if (noneCharsooEmailContactsAdapter == null) { noneCharsooEmailContactsAdapter = new AdapterInviteNoneCharsooContact(getActivity(), noneCharsooContactList, FragmentUserRegisterOfferFriendInvite.this); listViewEmailContacts.setAdapter(noneCharsooEmailContactsAdapter); }/* www . ja va 2 s. c o m*/ // startActivity(createEmailIntent("","subject","Body")); // String[] s=new String[]{"mhfathi.charsoo@gmail.com","cemhfathi@gmail.com"}; //// composeEmail(s,"this is subject","this is body"); // myIntent = new Intent(Intent.ACTION_SEND); // myIntent.setType("message/rfc822"); // myIntent.putExtra(Intent.EXTRA_EMAIL, s); // myIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject"); // myIntent.putExtra(Intent.EXTRA_TEXT, "I'm email body."); // startActivity(Intent.createChooser(myIntent, "Send Email")); break; case Params.SHARE_APP: myIntent = new Intent(Intent.ACTION_SEND); myIntent.setType("text/html"); myIntent.putExtra(Intent.EXTRA_TEXT, "Test Message");// getActivity().startActivity(Intent.createChooser(myIntent, "Share with")); break; default: myIntent = new Intent(Intent.ACTION_SEND); myIntent.setType("text/plain"); String s2 = applicationsHashtable.get(itemTag).pname; myIntent.setPackage(s2); myIntent.putExtra(Intent.EXTRA_TEXT, "Test Message");// getActivity().startActivity(Intent.createChooser(myIntent, "Share with")); break; } }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.messagehandler.MessageHandler.java
/** * Creates Subscriptions //from w w w.j av a 2s . c o m * @param c Cursor fetched from database with the necessary information to create a Subscription */ private void sendSubscription(Cursor c) { String eventType = c.getString(1); String eventID = c.getString(2); String timeStamp = c.getString(3); String producerID = c.getString(4); String packageName = c.getString(5); String subscribedEventType = c.getString(6); Intent intent = new Intent(); if (eventType.equals(ManagementEvent.SUBSCRIPITON)) { Subscription subscribe = new Subscription(eventID, timeStamp, producerID, packageName, subscribedEventType); intent.putExtra(Event.PARCELABLE_EXTRA_EVENT_TYPE, subscribe.getEventType()); intent.putExtra(Event.PARCELABLE_EXTRA_EVENT, subscribe); if (D_ANNOUNCEMENT) Log.d(TAG_ANNOUNCEMENT, "Subscription sent: " + producerID + ", packageNameShort: " + getLastStringAfterDot(packageName) + ", subscribedEventTypeShort: " + getLastStringAfterDot(subscribedEventType)); intent.setAction(AbstractChannel.MANAGEMENT); intent.setPackage(getPackageName()); sendBroadcast(intent); } //No need to send Unsubscription else if (eventType.equals(ManagementEvent.UNSUBSCRIPTION)) { Unsubscription unsubscribe = new Unsubscription(eventID, timeStamp, producerID, packageName, subscribedEventType); //intent.putExtra(Event.PARCELABLE_EXTRA_EVENT_TYPE, unsubscribe.getEventType()); //intent.putExtra(Event.PARCELABLE_EXTRA_EVENT, unsubscribe); if (D_ANNOUNCEMENT) Log.d(TAG_ANNOUNCEMENT, "Unsubscription restored but not sent: " + producerID + ", packageNameShort: " + getLastStringAfterDot(packageName) + ", subscribedEventTypeShort: " + getLastStringAfterDot(subscribedEventType)); } }
From source file:ir.rasen.charsoo.view.fragment.invite.FragmentInviteAppList.java
@Override public void onItemClicked(String itemTag) { Intent myIntent; switch (itemTag) { case Params.EMAIL_APP: (view.findViewById(R.id.ll_EmailListContainer)).setVisibility(View.VISIBLE); if (noneCharsooEmailContactsAdapter == null) { noneCharsooEmailContactsAdapter = new AdapterInviteContacts(getActivity(), noneCharsooContactList, FragmentInviteAppList.this); listViewEmailContacts.setAdapter(noneCharsooEmailContactsAdapter); }/* w w w .j a va2 s .co m*/ // startActivity(createEmailIntent("","subject","Body")); // String[] s=new String[]{"mhfathi.charsoo@gmail.com","cemhfathi@gmail.com"}; //// composeEmail(s,"this is subject","this is body"); // myIntent = new Intent(Intent.ACTION_SEND); // myIntent.setType("message/rfc822"); // myIntent.putExtra(Intent.EXTRA_EMAIL, s); // myIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject"); // myIntent.putExtra(Intent.EXTRA_TEXT, "I'm email body."); // startActivity(Intent.createChooser(myIntent, "Send Email")); break; case Params.SHARE_APP: myIntent = new Intent(Intent.ACTION_SEND); myIntent.setType("text/html"); myIntent.putExtra(Intent.EXTRA_TEXT, BODY);// getActivity().startActivity(Intent.createChooser(myIntent, "Share with")); break; default: myIntent = new Intent(Intent.ACTION_SEND); myIntent.setType("text/plain"); String s2 = applicationsHashtable.get(itemTag).pname; myIntent.setPackage(s2); myIntent.putExtra(Intent.EXTRA_TEXT, BODY);// getActivity().startActivity(Intent.createChooser(myIntent, "Share with")); break; } }
From source file:air.com.snagfilms.cast.chromecast.VideoChromeCastManager.java
private boolean startNotificationService() { if (!isFeatureEnabled(FEATURE_NOTIFICATION)) { return true; }/*from w w w . j a va2 s . com*/ Log.d(TAG, "startNotificationService() "); Intent service = new Intent(mContext, VideoCastNotificationService.class); service.setPackage(mContext.getPackageName()); return null != mContext.startService(service); }
From source file:com.google.sample.castcompanionlibrary.cast.VideoCastManager.java
private boolean startNotificationService(boolean visibility) { if (!isFeatureEnabled(FEATURE_NOTIFICATION)) { return true; }// w ww .j a v a2 s . c o m LOGD(TAG, "startNotificationService()"); Intent service = new Intent(mContext, VideoCastNotificationService.class); service.setPackage(mContext.getPackageName()); service.setAction(VideoCastNotificationService.ACTION_VISIBILITY); service.putExtra(VideoCastNotificationService.NOTIFICATION_VISIBILITY, !mUiVisible); return null != mContext.startService(service); }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.messagehandler.MessageHandler.java
/** * Sends an event to the local or global management channel depending on * the packageName. If the packageName equals the myHealthHub package name, * the event is send locally./* w w w .j a v a2s .co m*/ * @param event that needs to be send * @param packageName of the receiver */ private void sendToManagementChannel(Event evt, String packageName) { Intent intent = new Intent(); intent.putExtra(Event.PARCELABLE_EXTRA_EVENT_TYPE, evt.getEventType()); intent.putExtra(Event.PARCELABLE_EXTRA_EVENT, evt); // use local management channel for internal sensor modules if (packageName.equals(getPackageName())) { if (D) Log.d(TAG, "Sending on local management channel:" + evt.getEventType()); intent.setAction(AbstractChannel.LOCAL_MANAGEMENT); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); // use global management channel for external sensor modules (i.e. other applications) } else { if (D) Log.d(TAG, "Sending on global management channel:" + evt.getEventType()); //Implicit addressing intent.setAction(AbstractChannel.MANAGEMENT); //Explicit addressing intent.setPackage(packageName); getApplicationContext().sendBroadcast(intent); } }