List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:com.csipsimple.service.SipService.java
private void applyComponentEnablingState(boolean active) { int enableState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (active && prefsWrapper.getPreferenceBooleanValue(SipConfigManager.INTEGRATE_TEL_PRIVILEGED)) { // Check whether we should register for stock tel: intents // Useful for devices without gsm enableState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; }/*from w w w. j ava 2 s . c o m*/ PackageManager pm = getPackageManager(); ComponentName cmp = new ComponentName(this, "com.csipsimple.ui.PrivilegedOutgoingCallBroadcaster"); try { if (pm.getComponentEnabledSetting(cmp) != enableState) { pm.setComponentEnabledSetting(cmp, enableState, PackageManager.DONT_KILL_APP); } } catch (IllegalArgumentException e) { Log.d(THIS_FILE, "Current manifest has no PrivilegedOutgoingCallBroadcaster -- you can ignore this if voluntary", e); } }
From source file:com.aimfire.gallery.GalleryActivity.java
/** * share only to certain apps. code based on "http://stackoverflow.com/questions/ * 9730243/how-to-filter-specific-apps-for-action-send-intent-and-set-a-different- * text-for/18980872#18980872"/*w w w.j a v a 2s . c o m*/ * * "copy link" inspired by http://cketti.de/2016/06/15/share-url-to-clipboard/ * * in general, "deep linking" is supported by the apps below. Facebook, Wechat, * Telegram are exceptions. click on the link would bring users to the landing * page. * * Facebook doesn't take our EXTRA_TEXT so user will have to "copy link" first * then paste the link */ private void shareMedia(Intent data) { /* * we log this as "share complete", but user can still cancel the share at this point, * and we wouldn't be able to know */ mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_SHARE_COMPLETE, null); Resources resources = getResources(); /* * get the resource id for the shared file */ String id = data.getStringExtra(MainConsts.EXTRA_ID_RESOURCE); /* * construct link */ String link = "https://" + resources.getString(R.string.app_domain) + "/?id=" + id + "&name=" + ((mPreviewName != null) ? mPreviewName : mMediaName); /* * message subject and text */ String emailSubject, emailText, twitterText; if (MediaScanner.isPhoto(mMediaPath)) { emailSubject = resources.getString(R.string.emailSubjectPhoto); emailText = resources.getString(R.string.emailBodyPhotoPrefix) + link; twitterText = resources.getString(R.string.emailBodyPhotoPrefix) + link + resources.getString(R.string.twitterHashtagPhoto) + resources.getString(R.string.app_hashtag); } else if (MediaScanner.is3dMovie(mMediaPath)) { emailSubject = resources.getString(R.string.emailSubjectVideo); emailText = resources.getString(R.string.emailBodyVideoPrefix) + link; twitterText = resources.getString(R.string.emailBodyVideoPrefix) + link + resources.getString(R.string.twitterHashtagVideo) + resources.getString(R.string.app_hashtag); } else //if(MediaScanner.is2dMovie(mMediaPath)) { emailSubject = resources.getString(R.string.emailSubjectVideo2d); emailText = resources.getString(R.string.emailBodyVideoPrefix2d) + link; twitterText = resources.getString(R.string.emailBodyVideoPrefix2d) + link + resources.getString(R.string.twitterHashtagVideo) + resources.getString(R.string.app_hashtag); } Intent emailIntent = new Intent(); emailIntent.setAction(Intent.ACTION_SEND); // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); emailIntent.putExtra(Intent.EXTRA_TEXT, emailText); //emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native))); emailIntent.setType("message/rfc822"); PackageManager pm = getPackageManager(); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text)); List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0); List<LabeledIntent> intentList = new ArrayList<LabeledIntent>(); for (int i = 0; i < resInfo.size(); i++) { // Extract the label, append it, and repackage it in a LabeledIntent ResolveInfo ri = resInfo.get(i); String packageName = ri.activityInfo.packageName; if (packageName.contains("android.email")) { emailIntent.setPackage(packageName); } else if (packageName.contains("twitter") || packageName.contains("facebook") || packageName.contains("whatsapp") || packageName.contains("tencent.mm") || //wechat packageName.contains("line") || packageName.contains("skype") || packageName.contains("viber") || packageName.contains("kik") || packageName.contains("sgiggle") || //tango packageName.contains("kakao") || packageName.contains("telegram") || packageName.contains("nimbuzz") || packageName.contains("hike") || packageName.contains("imoim") || packageName.contains("bbm") || packageName.contains("threema") || packageName.contains("mms") || packageName.contains("android.apps.messaging") || //google messenger packageName.contains("android.talk") || //google hangouts packageName.contains("android.gm")) { Intent intent = new Intent(); intent.setComponent(new ComponentName(packageName, ri.activityInfo.name)); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); if (packageName.contains("twitter")) { intent.putExtra(Intent.EXTRA_TEXT, twitterText); } else if (packageName.contains("facebook")) { /* * the warning below is wrong! at least on GS5, Facebook client does take * our text, however it seems it takes only the first hyperlink in the * text. * * Warning: Facebook IGNORES our text. They say "These fields are intended * for users to express themselves. Pre-filling these fields erodes the * authenticity of the user voice." * One workaround is to use the Facebook SDK to post, but that doesn't * allow the user to choose how they want to share. We can also make a * custom landing page, and the link will show the <meta content ="..."> * text from that page with our link in Facebook. */ intent.putExtra(Intent.EXTRA_TEXT, link); } else if (packageName.contains("tencent.mm")) //wechat { /* * wechat appears to do this similar to Facebook */ intent.putExtra(Intent.EXTRA_TEXT, link); } else if (packageName.contains("android.gm")) { // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); intent.putExtra(Intent.EXTRA_TEXT, emailText); //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail))); intent.setType("message/rfc822"); } else if (packageName.contains("android.apps.docs")) { /* * google drive - no reason to send link to it */ continue; } else { intent.putExtra(Intent.EXTRA_TEXT, emailText); } intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon)); } } /* * create "Copy Link To Clipboard" Intent */ Intent clipboardIntent = new Intent(this, CopyToClipboardActivity.class); clipboardIntent.setData(Uri.parse(link)); intentList.add(new LabeledIntent(clipboardIntent, getPackageName(), getResources().getString(R.string.clipboard_activity_name), R.drawable.ic_copy_link)); // convert intentList to array LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]); openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents); startActivity(openInChooser); }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static void linkButtons(Context context, RemoteViews views, boolean playerActive) { Intent intent = new Intent(context, playerActive ? DownloadActivity.class : MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.appwidget_coverart, pendingIntent); views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent); // Emulate media button clicks. intent = new Intent("1"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_play, pendingIntent); intent = new Intent("2"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_next, pendingIntent); intent = new Intent("3"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_previous, pendingIntent); intent = new Intent("4"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_stop, pendingIntent); }
From source file:com.irccloud.android.Notifications.java
public NotificationCompat.Builder alert(int bid, String title, String body) { NotificationCompat.Builder builder = new NotificationCompat.Builder( IRCCloudApplication.getInstance().getApplicationContext()).setContentTitle(title) .setContentText(body).setTicker(body).setAutoCancel(true).setColor(IRCCloudApplication .getInstance().getApplicationContext().getResources().getColor(R.color.dark_blue)) .setSmallIcon(R.drawable.ic_stat_notify); Intent i = new Intent(); i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), "com.irccloud.android.MainActivity")); i.putExtra("bid", bid); i.setData(Uri.parse("bid://" + bid)); builder.setContentIntent(// ww w . jav a 2 s . com PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext()).notify(bid, builder.build()); return builder; }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java
/** * Starts playback of a previously opened file. *///from www .j a v a 2 s . com public void play() { mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); mAudioManager.registerMediaButtonEventReceiver( new ComponentName(this.getPackageName(), MediaButtonIntentReceiver.class.getName())); if (mPlayer.isInitialized()) { // if we are at the end of the song, go to the next song first long duration = mPlayer.duration(); if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) { gotoNext(true); } mPlayer.start(); // make sure we fade in, in case a previous fadein was stopped because // of another focus loss mMediaplayerHandler.removeMessages(FADEDOWN); mMediaplayerHandler.sendEmptyMessage(FADEUP); updateNotification(); if (!mIsSupposedToBePlaying) { mIsSupposedToBePlaying = true; notifyChange(PLAYSTATE_CHANGED); } } else if (mPlayListLen <= 0) { // This is mostly so that if you press 'play' on a bluetooth headset // without every having played anything before, it will still play // something. setShuffleMode(SHUFFLE_AUTO); } }
From source file:com.linkbubble.Settings.java
public void setDefaultApp(String urlAsString, ResolveInfo resolveInfo, boolean save) { try {//from www . j ava 2 s.com URL url = new URL(urlAsString); String host = url.getHost(); if (host.length() > 1) { ComponentName componentName = new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name); addDefaultApp(host, componentName, save); } } catch (MalformedURLException e) { e.printStackTrace(); } }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** * Filter the intent to a single activity so a chooser won't pop up. Do not handle fall back here. * @param intent intent to filter.//from w w w .ja v a 2 s .c o m */ private void filterIntent(Intent intent) { for (ResolveInfo resolveInfo : mContext.getPackageManager().queryIntentActivities(intent, 0)) { ActivityInfo activityInfo = resolveInfo.activityInfo; String packageName = mContext.getPackageName(); if (activityInfo.packageName.equals(packageName)) { intent.setComponent(new ComponentName(packageName, activityInfo.name)); break; } } }
From source file:com.android.tv.MainActivity.java
/** * Starts setup activity for the given input {@code input}. * * @param calledByPopup If true, startSetupActivity is invoked from the setup fragment. *///from w w w. j av a2 s. c o m public void startSetupActivity(TvInputInfo input, boolean calledByPopup) { Intent intent = TvCommonUtils.createSetupIntent(input); if (intent == null) { Toast.makeText(this, R.string.msg_no_setup_activity, Toast.LENGTH_SHORT).show(); return; } // Even though other app can handle the intent, the setup launched by Live channels // should go through Live channels SetupPassthroughActivity. intent.setComponent(new ComponentName(this, SetupPassthroughActivity.class)); try { // Now we know that the user intends to set up this input. Grant permission for writing // EPG data. SetupUtils.grantEpgPermission(this, input.getServiceInfo().packageName); mInputIdUnderSetup = input.getId(); mIsSetupActivityCalledByPopup = calledByPopup; // Call requestVisibleBehind(false) before starting other activity. // In Activity.requestVisibleBehind(false), this activity is scheduled to be stopped // immediately if other activity is about to start. And this activity is scheduled to // to be stopped again after onPause(). stopTv("startSetupActivity()", false); startActivityForResult(intent, REQUEST_CODE_START_SETUP_ACTIVITY); } catch (ActivityNotFoundException e) { mInputIdUnderSetup = null; Toast.makeText(this, getString(R.string.msg_unable_to_start_setup_activity, input.loadLabel(this)), Toast.LENGTH_SHORT).show(); return; } if (calledByPopup) { mOverlayManager.hideOverlays(TvOverlayManager.FLAG_HIDE_OVERLAYS_WITHOUT_ANIMATION | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_FRAGMENT); } else { mOverlayManager.hideOverlays(TvOverlayManager.FLAG_HIDE_OVERLAYS_WITHOUT_ANIMATION | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_SIDE_PANEL_HISTORY); } }
From source file:com.andrew.apolloMod.service.ApolloService.java
/** * Starts playback of a previously opened file. *///w ww. j a v a 2 s. c o m public void play() { mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); mAudioManager.registerMediaButtonEventReceiver( new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName())); if (mPlayer.isInitialized()) { // if we are at the end of the song, go to the next song first mPlayer.start(); // make sure we fade in, in case a previous fadein was stopped // because // of another focus loss mMediaplayerHandler.removeMessages(FADEDOWN); mMediaplayerHandler.sendEmptyMessage(FADEUP); updateNotification(); if (!mIsSupposedToBePlaying) { mIsSupposedToBePlaying = true; notifyChange(PLAYSTATE_CHANGED); } } else if (mPlayListLen <= 0) { // This is mostly so that if you press 'play' on a bluetooth headset // without every having played anything before, it will still play // something. setShuffleMode(SHUFFLE_AUTO); } }
From source file:com.bluros.music.MusicService.java
private final PendingIntent retrievePlaybackAction(final String action) { final ComponentName serviceName = new ComponentName(this, MusicService.class); Intent intent = new Intent(action); intent.setComponent(serviceName);//from w ww . ja v a 2 s . c om return PendingIntent.getService(this, 0, intent, 0); }