List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:com.hichinaschool.flashcards.libanki.Utils.java
public static boolean isIntentAvailable(Context context, String action, ComponentName componentName) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); intent.setComponent(componentName); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
From source file:org.croudtrip.gcm.GcmBroadcastReceiver.java
@Override public void onReceive(final Context context, Intent intent) { ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);/* w w w. ja v a 2 s .c om*/ }
From source file:com.dm.material.dashboard.candybar.adapters.IntentAdapter.java
private void sendRequest(ComponentName name) { try {/*from w w w . j a v a 2s. co m*/ Intent intent = new Intent(Intent.ACTION_SEND); intent = addIntentExtra(intent); intent.setComponent(name); intent.addCategory(Intent.CATEGORY_LAUNCHER); mContext.startActivity(intent); } catch (IllegalArgumentException e) { try { Intent intent = new Intent(Intent.ACTION_SEND); intent = addIntentExtra(intent); mContext.startActivity( Intent.createChooser(intent, mContext.getResources().getString(R.string.email_client))); } catch (ActivityNotFoundException e1) { LogUtil.e(Log.getStackTraceString(e1)); } } }
From source file:org.apache.cordova.CordovaUriHelper.java
/** * Give the host application a chance to take over the control when a new url * is about to be loaded in the current WebView. * * @param view The WebView that is initiating the callback. * @param url The url to be loaded. * @return true to override, false for default behavior *//*from ww w . j ava 2 s . c om*/ public boolean shouldOverrideUrlLoading(WebView view, String url) { // The WebView should support http and https when going on the Internet if (url.startsWith("http:") || url.startsWith("https:")) { // Check if it's an exec() bridge command message. if (NativeToJsMessageQueue.ENABLE_LOCATION_CHANGE_EXEC_MODE && url.startsWith(CORDOVA_EXEC_URL_PREFIX)) { handleExecUrl(url); } // We only need to whitelist sites on the Internet! else if (Config.isUrlWhiteListed(url)) { return false; } } // Give plugins the chance to handle the url else if (this.appView.pluginManager.onOverrideUrlLoading(url)) { } else if (url.startsWith("file://") | url.startsWith("data:")) { //This directory on WebKit/Blink based webviews contains SQLite databases! //DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING! return url.contains("app_webview"); } else { try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setComponent(null); intent.setSelector(null); this.cordova.getActivity().startActivity(intent); } catch (android.content.ActivityNotFoundException e) { LOG.e(TAG, "Error loading url " + url, e); } } //Default behaviour should be to load the default intent, let's see what happens! return true; }
From source file:com.farmerbb.taskbar.receiver.ReceiveSettingsReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Ignore this broadcast if this is the free version if (BuildConfig.APPLICATION_ID.equals(BuildConfig.PAID_APPLICATION_ID)) { // Get pinned and blocked apps PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context); pba.clear(context);//from w w w. j a va 2 s .c om String[] pinnedAppsPackageNames = intent.getStringArrayExtra("pinned_apps_package_names"); String[] pinnedAppsComponentNames = intent.getStringArrayExtra("pinned_apps_component_names"); String[] pinnedAppsLabels = intent.getStringArrayExtra("pinned_apps_labels"); long[] pinnedAppsUserIds = intent.getLongArrayExtra("pinned_apps_user_ids"); UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE); LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); if (pinnedAppsPackageNames != null && pinnedAppsComponentNames != null && pinnedAppsLabels != null) for (int i = 0; i < pinnedAppsPackageNames.length; i++) { Intent throwaway = new Intent(); throwaway.setComponent(ComponentName.unflattenFromString(pinnedAppsComponentNames[i])); long userId; if (pinnedAppsUserIds != null) userId = pinnedAppsUserIds[i]; else userId = userManager.getSerialNumberForUser(Process.myUserHandle()); AppEntry newEntry = new AppEntry(pinnedAppsPackageNames[i], pinnedAppsComponentNames[i], pinnedAppsLabels[i], IconCache.getInstance(context).getIcon(context, context.getPackageManager(), launcherApps.resolveActivity(throwaway, userManager.getUserForSerialNumber(userId))), true); newEntry.setUserId(userId); pba.addPinnedApp(context, newEntry); } String[] blockedAppsPackageNames = intent.getStringArrayExtra("blocked_apps_package_names"); String[] blockedAppsComponentNames = intent.getStringArrayExtra("blocked_apps_component_names"); String[] blockedAppsLabels = intent.getStringArrayExtra("blocked_apps_labels"); if (blockedAppsPackageNames != null && blockedAppsComponentNames != null && blockedAppsLabels != null) for (int i = 0; i < blockedAppsPackageNames.length; i++) { pba.addBlockedApp(context, new AppEntry(blockedAppsPackageNames[i], blockedAppsComponentNames[i], blockedAppsLabels[i], null, false)); } // Get blacklist Blacklist blacklist = Blacklist.getInstance(context); blacklist.clear(context); String[] blacklistPackageNames = intent.getStringArrayExtra("blacklist_package_names"); String[] blacklistLabels = intent.getStringArrayExtra("blacklist_labels"); if (blacklistPackageNames != null && blacklistLabels != null) for (int i = 0; i < blacklistPackageNames.length; i++) { blacklist.addBlockedApp(context, new BlacklistEntry(blacklistPackageNames[i], blacklistLabels[i])); } // Get top apps TopApps topApps = TopApps.getInstance(context); topApps.clear(context); String[] topAppsPackageNames = intent.getStringArrayExtra("top_apps_package_names"); String[] topAppsLabels = intent.getStringArrayExtra("top_apps_labels"); if (topAppsPackageNames != null && topAppsLabels != null) for (int i = 0; i < topAppsPackageNames.length; i++) { topApps.addTopApp(context, new BlacklistEntry(topAppsPackageNames[i], topAppsLabels[i])); } // Get saved window sizes if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { SavedWindowSizes savedWindowSizes = SavedWindowSizes.getInstance(context); savedWindowSizes.clear(context); String[] savedWindowSizesComponentNames = intent .getStringArrayExtra("saved_window_sizes_component_names"); String[] savedWindowSizesWindowSizes = intent .getStringArrayExtra("saved_window_sizes_window_sizes"); if (savedWindowSizesComponentNames != null && savedWindowSizesWindowSizes != null) for (int i = 0; i < savedWindowSizesComponentNames.length; i++) { savedWindowSizes.setWindowSize(context, savedWindowSizesComponentNames[i], savedWindowSizesWindowSizes[i]); } } // Get shared preferences String contents = intent.getStringExtra("preferences"); if (contents.length() > 0) try { File file = new File(context.getFilesDir().getParent() + "/shared_prefs/" + BuildConfig.APPLICATION_ID + "_preferences.xml"); FileOutputStream output = new FileOutputStream(file); output.write(contents.getBytes()); output.close(); } catch (IOException e) { /* Gracefully fail */ } try { File file = new File(context.getFilesDir() + File.separator + "imported_successfully"); if (file.createNewFile()) LocalBroadcastManager.getInstance(context) .sendBroadcast(new Intent("com.farmerbb.taskbar.IMPORT_FINISHED")); } catch (IOException e) { /* Gracefully fail */ } } }
From source file:com.miuidev.themebrowser.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.MenuThemeManager: final Intent intentThemeManager = new Intent("android.intent.action.MAIN"); intentThemeManager.setComponent(new ComponentName("com.android.thememanager", "com.android.thememanager.ThemeSettingsActivity")); try {//from w w w . ja v a 2 s . c o m startActivity(intentThemeManager); } catch (ActivityNotFoundException e) { Context context = getApplicationContext(); CharSequence text = getString(R.string.theme_manager_not_found); int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } return true; case R.id.MenuAbout: displayAbout(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:org.deviceconnect.message.intent.impl.io.IntentHttpMessageWriter.java
@Override public void write(final HttpMessage message) throws IOException, HttpException { mLogger.entering(getClass().getName(), "write"); DConnectMessage dmessage = HttpMessageFactory.getMessageFactory().newDConnectMessage(message); Intent intent = IntentMessageFactory.getMessageFactory().newPackagedMessage(dmessage); // put intent optional extras Header host = message.getFirstHeader(HttpHeaders.HOST); if (host != null) { intent.setComponent(ComponentName.unflattenFromString(host.getValue())); }// ww w.j a v a2 s . c o m intent.putExtra(DConnectMessage.EXTRA_RECEIVER, new ComponentName(mContext, IntentResponseReceiver.class)); // send broadcast mLogger.fine("send request broadcast: " + intent); mLogger.fine("send request extra: " + intent.getExtras()); mContext.sendBroadcast(intent); mLogger.exiting(getClass().getName(), "write"); }
From source file:com.devbrackets.android.exomedia.EMLockScreen.java
private PendingIntent getMediaButtonReceiverPendingIntent(ComponentName componentName) { Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(componentName); mediaButtonIntent.putExtra(RECEIVER_EXTRA_CLASS, mediaServiceClass.getName()); return PendingIntent.getBroadcast(context, 0, mediaButtonIntent, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.bluros.music.widgets.SleepModeDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { context = getActivity().getBaseContext(); Intent action = new Intent(MusicService.SLEEP_MODE_STOP_ACTION); ComponentName serviceName = new ComponentName(context, MusicService.class); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(context, 4, action, 0); alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.sleep_mode_time_selector, null); int minutes = Integer.valueOf(getString(R.string.default_interval)); final TextView tvPopUpTime = (TextView) view.findViewById(R.id.pop_up_time); tvPopUpTime.setText(String.valueOf(minutes)); final SeekBar sBar = (SeekBar) view.findViewById(R.id.seekbar); sBar.setProgress(minutes - 1);// w w w. j ava 2 s. co m sBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { tvPopUpTime.setText(String.valueOf(arg1 + 1)); } @Override public void onStartTrackingTouch(SeekBar arg0) { } @Override public void onStopTrackingTouch(SeekBar arg0) { } }); builder.setTitle(R.string.select_quit_time); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { long timeLeft = (sBar.getProgress() + 1) * mMill; alarmManager.set(AlarmManager.RTC_WAKEUP, timeLeft + System.currentTimeMillis(), pendingIntent); MusicPlayer.setSleepMode(true); Toast.makeText(context, String.format(getString(R.string.quit_warining), sBar.getProgress() + 1), Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); builder.setView(view); return builder.create(); }
From source file:com.perm.DoomPlay.DownloadNotifBuilder.java
private Notification createStartingOld() { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setOngoing(true);//from w w w. ja v a 2 s . c o m builder.setContentTitle(context.getResources().getString(R.string.Downloading)); builder.setContentText(track.getArtist() + "-" + track.getTitle()); builder.setSmallIcon(R.drawable.download_icon); Intent intentClose = new Intent(PlayingService.actionClose); intentClose.putExtra("aid", track.getAid()); intentClose.setComponent(new ComponentName(context, DownloadingService.class)); builder.setContentIntent( PendingIntent.getService(context, notificationId, intentClose, PendingIntent.FLAG_UPDATE_CURRENT)); return builder.build(); }