List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java
/** * .// w w w . ja v a 2 s.c o m * * @param mediaId ID * @param uri ??URI */ public void notifyDataAvailable(final String mediaId, final String uri) { List<Event> evts = EventManager.INSTANCE.getEventList(mDeviceId, MediaStreamRecordingProfileConstants.PROFILE_NAME, null, MediaStreamRecordingProfileConstants.ATTRIBUTE_ON_DATA_AVAILABLE); for (Event evt : evts) { Bundle media = new Bundle(); media.putString(MediaStreamRecordingProfile.PARAM_PATH, mediaId); media.putString(MediaStreamRecordingProfile.PARAM_URI, uri); media.putString(MediaStreamRecordingProfile.PARAM_MIME_TYPE, "image/jpg"); Intent intent = new Intent(IntentDConnectMessage.ACTION_EVENT); intent.setComponent(ComponentName.unflattenFromString(evt.getReceiverName())); intent.putExtra(DConnectMessage.EXTRA_DEVICE_ID, DEVICE_ID); intent.putExtra(DConnectMessage.EXTRA_PROFILE, MediaStreamRecordingProfile.PROFILE_NAME); intent.putExtra(DConnectMessage.EXTRA_ATTRIBUTE, MediaStreamRecordingProfile.ATTRIBUTE_ON_DATA_AVAILABLE); intent.putExtra(DConnectMessage.EXTRA_SESSION_KEY, evt.getSessionKey()); intent.putExtra(MediaStreamRecordingProfile.PARAM_MEDIA, media); sendEvent(intent, evt.getAccessToken()); } }
From source file:com.dzt.musicplay.player.AudioService.java
/** * Set up the remote control and tell the system we want to be the default * receiver for the MEDIA buttons/*w w w .j av a 2 s . c om*/ * * @see http * ://android-developers.blogspot.fr/2010/06/allowing-applications-to * -play-nicer.html */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void setUpRemoteControlClient() { Context context = getApplicationContext(); AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE); if (LibVlcUtil.isICSOrLater()) { audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent); if (mRemoteControlClient == null) { Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mRemoteControlClientReceiverComponent); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context, 0, mediaButtonIntent, 0); // create and register the remote control client mRemoteControlClient = new RemoteControlClient(mediaPendingIntent); audioManager.registerRemoteControlClient(mRemoteControlClient); } mRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP); } else if (LibVlcUtil.isFroyoOrLater()) { audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent); } }
From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java
/** * ?.// w w w . j a va2 s. c om * * @param mediaid ID */ public void notifyTakePhoto(final String mediaid) { for (String key : mOnPhotoCallback.keySet()) { Intent response = mOnPhotoCallback.get(key); ComponentName receiver = (ComponentName) response.getParcelableExtra("receiver"); Bundle photo = new Bundle(); photo.putString("mediaid", mediaid); photo.putString("mimetype", "image/png"); Intent intent = new Intent(); intent.setAction(IntentDConnectMessage.ACTION_EVENT); intent.setComponent(receiver); intent.putExtra("deviceid", "me"); intent.putExtra("profile", "mediastream_recording"); intent.putExtra("callback", "onphoto"); intent.putExtra("session_key", key); intent.putExtra("photo", photo); sendBroadcast(intent); } }
From source file:org.opendatakit.survey.activities.MainMenuActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == MENU_CLOUD_FORMS) { try {//from www .j a va2 s .c o m Intent syncIntent = new Intent(); syncIntent.setComponent( new ComponentName(IntentConsts.Sync.APPLICATION_NAME, IntentConsts.Sync.ACTIVITY_NAME)); syncIntent.setAction(Intent.ACTION_DEFAULT); Bundle bundle = new Bundle(); bundle.putString(IntentConsts.INTENT_KEY_APP_NAME, appName); syncIntent.putExtras(bundle); this.startActivityForResult(syncIntent, SYNC_ACTIVITY_CODE); } catch (ActivityNotFoundException e) { WebLogger.getLogger(getAppName()).printStackTrace(e); Toast.makeText(this, R.string.sync_not_found, Toast.LENGTH_LONG).show(); } return true; } else if (item.getItemId() == MENU_ABOUT) { swapToFragmentView(ScreenList.ABOUT_MENU); return true; } return super.onOptionsItemSelected(item); }
From source file:com.delexus.imitationzhihu.MySearchView.java
/** * Create and return an Intent that can launch the voice search activity, perform a specific * voice transcription, and forward the results to the searchable activity. * * @param baseIntent The voice app search intent to start from * @return A completely-configured intent ready to send to the voice search activity *///w w w . jav a 2s .c o m private Intent createVoiceAppSearchIntent(Intent baseIntent, SearchableInfo searchable) { ComponentName searchActivity = searchable.getSearchActivity(); // create the necessary intent to set up a search-and-forward operation // in the voice search system. We have to keep the bundle separate, // because it becomes immutable once it enters the PendingIntent Intent queryIntent = new Intent(Intent.ACTION_SEARCH); queryIntent.setComponent(searchActivity); PendingIntent pending = PendingIntent.getActivity(getContext(), 0, queryIntent, PendingIntent.FLAG_ONE_SHOT); // Now set up the bundle that will be inserted into the pending intent // when it's time to do the search. We always build it here (even if empty) // because the voice search activity will always need to insert "QUERY" into // it anyway. Bundle queryExtras = new Bundle(); if (mAppSearchData != null) { queryExtras.putParcelable(SearchManager.APP_DATA, mAppSearchData); } // Now build the intent to launch the voice search. Add all necessary // extras to launch the voice recognizer, and then all the necessary extras // to forward the results to the searchable activity Intent voiceIntent = new Intent(baseIntent); // Add all of the configuration options supplied by the searchable's metadata String languageModel = RecognizerIntent.LANGUAGE_MODEL_FREE_FORM; String prompt = null; String language = null; int maxResults = 1; Resources resources = getResources(); if (searchable.getVoiceLanguageModeId() != 0) { languageModel = resources.getString(searchable.getVoiceLanguageModeId()); } if (searchable.getVoicePromptTextId() != 0) { prompt = resources.getString(searchable.getVoicePromptTextId()); } if (searchable.getVoiceLanguageId() != 0) { language = resources.getString(searchable.getVoiceLanguageId()); } if (searchable.getVoiceMaxResults() != 0) { maxResults = searchable.getVoiceMaxResults(); } voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel); voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt); voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); voiceIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResults); voiceIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, searchActivity == null ? null : searchActivity.flattenToShortString()); // Add the values that configure forwarding the results voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, pending); voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE, queryExtras); return voiceIntent; }
From source file:org.opendatakit.survey.activities.MainMenuActivity.java
private void resolveAnyConflicts() { if (mConflictTables == null || mConflictTables.isEmpty()) { scanForConflictAllTables();// w w w .j a v a2s . c o m } if ((mConflictTables != null) && !mConflictTables.isEmpty()) { Iterator<String> iterator = mConflictTables.keySet().iterator(); String tableId = iterator.next(); mConflictTables.remove(tableId); Intent i; i = new Intent(); i.setComponent(new ComponentName(IntentConsts.ResolveConflict.APPLICATION_NAME, IntentConsts.ResolveConflict.ACTIVITY_NAME)); i.setAction(Intent.ACTION_EDIT); i.putExtra(IntentConsts.INTENT_KEY_APP_NAME, getAppName()); i.putExtra(IntentConsts.INTENT_KEY_TABLE_ID, tableId); try { this.startActivityForResult(i, CONFLICT_ACTIVITY_CODE); } catch (ActivityNotFoundException e) { Toast.makeText(this, getString(R.string.activity_not_found, IntentConsts.ResolveConflict.ACTIVITY_NAME), Toast.LENGTH_LONG).show(); } } }
From source file:com.scoreflex.ScoreflexView.java
/** * The constructor of the view.//from ww w . ja v a2 s .c om * @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:net.wequick.small.ApkBundleLauncher.java
@Override public void prelaunchBundle(Bundle bundle) { super.prelaunchBundle(bundle); Intent intent = new Intent(); bundle.setIntent(intent);// w w w. ja v a2 s . c o m // Intent extras - class String activityName = bundle.getActivityName(); if (!ActivityLauncher.containsActivity(activityName)) { if (!sLoadedActivities.containsKey(activityName)) { if (activityName.endsWith("Activity")) { throw new ActivityNotFoundException( "Unable to find explicit activity class " + "{ " + activityName + " }"); } String tempActivityName = activityName + "Activity"; if (!sLoadedActivities.containsKey(tempActivityName)) { throw new ActivityNotFoundException( "Unable to find explicit activity class " + "{ " + activityName + "(Activity) }"); } activityName = tempActivityName; } } intent.setComponent(new ComponentName(Small.getContext(), activityName)); // Intent extras - params String query = bundle.getQuery(); if (query != null) { intent.putExtra(Small.KEY_QUERY, '?' + query); } }
From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java
@Override protected void onPostResume() { super.onPostResume(); // Hijack the app here, after all screens have been resumed, // to ensure that all checkpoints and conflicts have been // resolved. If they haven't, we branch to the resolution // activity.//from w ww . j a va 2 s. com if (mConflictTables == null || mConflictTables.isEmpty()) { scanForConflictAllTables(); } if ((mConflictTables != null) && !mConflictTables.isEmpty()) { Iterator<String> iterator = mConflictTables.keySet().iterator(); String tableId = iterator.next(); mConflictTables.remove(tableId); Intent i; i = new Intent(); i.setComponent(new ComponentName(SYNC_PACKAGE_NAME, SYNC_CONFLICT_ACTIVITY_COMPONENT_NAME)); i.setAction(Intent.ACTION_EDIT); i.putExtra(APP_NAME, getAppName()); i.putExtra(SYNC_TABLE_ID_PARAMETER, tableId); try { this.startActivityForResult(i, CONFLICT_ACTIVITY_CODE); } catch (ActivityNotFoundException e) { Toast.makeText(this, getString(R.string.activity_not_found, SYNC_CONFLICT_ACTIVITY_COMPONENT_NAME), Toast.LENGTH_LONG).show(); } } }
From source file:io.github.vomitcuddle.SearchViewAllowEmpty.SearchView.java
/** * Create and return an Intent that can launch the voice search activity, perform a specific * voice transcription, and forward the results to the searchable activity. * * @param baseIntent The voice app search intent to start from * @return A completely-configured intent ready to send to the voice search activity *//*from w ww . ja v a2s . c om*/ private Intent createVoiceAppSearchIntent(Intent baseIntent, SearchableInfo searchable) { ComponentName searchActivity = searchable.getSearchActivity(); // create the necessary intent to set up a search-and-forward operation // in the voice search system. We have to keep the bundle separate, // because it becomes immutable once it enters the PendingIntent Intent queryIntent = new Intent(Intent.ACTION_SEARCH); queryIntent.setComponent(searchActivity); PendingIntent pending = PendingIntent.getActivity(getContext(), 0, queryIntent, PendingIntent.FLAG_ONE_SHOT); // Now set up the bundle that will be inserted into the pending intent // when it's time to do the search. We always build it here (even if empty) // because the voice search activity will always need to insert "QUERY" into // it anyway. Bundle queryExtras = new Bundle(); if (mAppSearchData != null) { queryExtras.putParcelable(SearchManager.APP_DATA, mAppSearchData); } // Now build the intent to launch the voice search. Add all necessary // extras to launch the voice recognizer, and then all the necessary extras // to forward the results to the searchable activity Intent voiceIntent = new Intent(baseIntent); // Add all of the configuration options supplied by the searchable's metadata String languageModel = RecognizerIntent.LANGUAGE_MODEL_FREE_FORM; String prompt = null; String language = null; int maxResults = 1; Resources resources = getResources(); if (searchable.getVoiceLanguageModeId() != 0) { languageModel = resources.getString(searchable.getVoiceLanguageModeId()); } if (searchable.getVoicePromptTextId() != 0) { prompt = resources.getString(searchable.getVoicePromptTextId()); } if (searchable.getVoiceLanguageId() != 0) { language = resources.getString(searchable.getVoiceLanguageId()); } if (searchable.getVoiceMaxResults() != 0) { maxResults = searchable.getVoiceMaxResults(); } voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel); voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt); voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); voiceIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResults); voiceIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, searchActivity == null ? null : searchActivity.flattenToShortString()); // Add the values that configure forwarding the results voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, pending); voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE, queryExtras); return voiceIntent; }