List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:org.catrobat.catroid.ui.fragment.LookFragment.java
public void addLookDrawNewImage() { Intent intent = new Intent("android.intent.action.MAIN"); intent.setComponent(new ComponentName(Constants.POCKET_PAINT_PACKAGE_NAME, Constants.POCKET_PAINT_INTENT_ACTIVITY_NAME)); if (!LookController.getInstance().checkIfPocketPaintIsInstalled(intent, getActivity())) { return;/* w w w. j av a2 s.co m*/ } Bundle bundleForPocketPaint = new Bundle(); bundleForPocketPaint.putString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT, ""); bundleForPocketPaint.putString(Constants.EXTRA_PICTURE_NAME_POCKET_PAINT, getString(R.string.default_look_name)); intent.putExtras(bundleForPocketPaint); intent.addCategory("android.intent.category.LAUNCHER"); startActivityForResult(intent, LookController.REQUEST_SELECT_OR_DRAW_IMAGE); }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_client.ui.activity.ItemListActivity.java
private void doCrop() { Intent intent = new Intent(ConstantKeys.CROP_INTENT); intent.setType(ConstantKeys.IMAGE_CROP); List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, 0); int size = list.size(); if (size == 0) { Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show(); return;//from ww w . j a v a 2 s . c om } intent.setData(mFileCaptureUri); intent.putExtra("outputX", 100); intent.putExtra("outputY", 100); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("scale", true); intent.putExtra("noFaceDetection", true); mFileCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), ConstantKeys.CROP + String.valueOf(System.currentTimeMillis()) + ConstantKeys.EXTENSION_JPG)); intent.putExtra("output", mFileCaptureUri); Intent i = new Intent(intent); ResolveInfo res = list.get(0); i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); startActivityForResult(i, CROP_CAMERA_IMAGE); }
From source file:ch.fixme.status.Main.java
@Override public void startActivity(Intent intent) { // http://stackoverflow.com/questions/13691241/autolink-not-working-on-htc-htclinkifydispatcher try {// w w w.j av a 2s . co m /* First attempt at fixing an HTC broken by evil Apple patents. */ if (intent.getComponent() != null && ".HtcLinkifyDispatcherActivity".equals(intent.getComponent().getShortClassName())) intent.setComponent(null); super.startActivity(intent); } catch (ActivityNotFoundException e) { /* * Probably an HTC broken by evil Apple patents. This is not * perfect, but better than crashing the whole application. */ super.startActivity(Intent.createChooser(intent, null)); } }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
private void updateClock(Context context, AppWidgetManager appWidgetManager, int appWidgetId, float ratio) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); // Launch setinngs when clicking on the time in the widget only if not a lock screen widget Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId); if (newOptions != null && newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1) != AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) { Intent mIntent = new Intent(Intent.ACTION_MAIN); mIntent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName component = new ComponentName("com.android.settings", "com.android.settings.Settings"); mIntent.setComponent(component); widget.setOnClickPendingIntent(R.id.digital_appwidget, PendingIntent.getActivity(context, 0, mIntent, 0)); }// www . j a va2s. com //cg sai.pan begin refreshWifiStatus(context, widget); refreshBtStatus(context, widget); refreshAirplaneStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0); mLocationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE); refreshGpsStatus(context, widget, mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)); //refreshDataStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.MOBILE_DATA, 0) != 0); requestLocation(context); //cg sai.pan end // SPRD for bug421127 add am/pm for widget WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size), R.id.the_clock); WidgetUtils.setClockSize(context, widget, ratio); // Set today's date format CharSequence dateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(), context.getString(R.string.abbrev_wday_month_day_no_year)); widget.setCharSequence(R.id.date, "setFormat12Hour", dateFormat); widget.setCharSequence(R.id.date, "setFormat24Hour", dateFormat); appWidgetManager.updateAppWidget(appWidgetId, widget); }
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(//from w ww .j a v a2s . c om 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:com.opentaxi.android.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent != null && intent.getExtras() != null) { String regId = intent.getExtras().getString("registration_id"); if (regId != null && !regId.equals("") && !regId.equals(TaxiApplication.gcmId)) { TaxiApplication.gcmId = regId; /* Do what ever you want with the regId eg. send it to your server */ Log.i("GcmBroadcastReceiver", "onReceive:" + regId); //RestClient.getInstance().gcmRegister(regId); Intent i = new Intent(context, GCMRegisterService.class); i.putExtra("regId", regId); context.startService(i);/*from www .j a va 2s . c o m*/ } } // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. if (intent != null) startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); }
From source file:com.androzic.location.LocationService.java
private Notification getNotification() { int msgId = R.string.notif_loc_started; int ntfId = R.drawable.ic_stat_locating; if (trackingEnabled) { msgId = R.string.notif_trk_started; ntfId = R.drawable.ic_stat_tracking; }/* ww w. ja v a2 s . com*/ if (gpsStatus != LocationService.GPS_OK) { msgId = R.string.notif_loc_waiting; ntfId = R.drawable.ic_stat_waiting; } if (gpsStatus == LocationService.GPS_OFF) { ntfId = R.drawable.ic_stat_off; } if (errorTime > 0) { msgId = R.string.notif_trk_failure; ntfId = R.drawable.ic_stat_failure; } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setWhen(errorTime); builder.setSmallIcon(ntfId); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(new ComponentName(getApplicationContext(), Splash.class)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, intent, 0); builder.setContentIntent(contentIntent); builder.setContentTitle(getText(R.string.notif_loc_short)); if (errorTime > 0 && DEBUG_ERRORS) builder.setContentText(errorMsg); else builder.setContentText(getText(msgId)); builder.setOngoing(true); Notification notification = builder.getNotification(); return notification; }
From source file:com.google.appinventor.components.runtime.ProbeBase.java
@SimpleFunction(description = "Create a notication with message to wake up " + "another activity when tap on the notification") public void CreateNotification(String title, String text, boolean enabledSound, boolean enabledVibrate, String packageName, String className, String extraKey, String extraVal) throws ClassNotFoundException { Intent activityToLaunch = new Intent(Intent.ACTION_MAIN); Log.i(TAG, "packageName: " + packageName); Log.i(TAG, "className: " + className); // for local AI instance, all classes are under the package // "appinventor.ai_test" // but for those runs on Google AppSpot(AppEngine), the package name will be // "appinventor.ai_GoogleAccountUserName" // e.g. pakageName = appinventor.ai_HomerSimpson.HelloPurr // && className = appinventor.ai_HomerSimpson.HelloPurr.Screen1 ComponentName component = new ComponentName(packageName, className); activityToLaunch.setComponent(component); activityToLaunch.putExtra(extraKey, extraVal); Log.i(TAG, "we found the class for intent to send into notificaiton"); activityToLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); mContentIntent = PendingIntent.getActivity(mainUIThreadActivity, 0, activityToLaunch, 0); Long currentTimeMillis = System.currentTimeMillis(); notification = new Notification(R.drawable.stat_notify_chat, "Activate Notification!", currentTimeMillis); Log.i(TAG, "After creating notification"); notification.contentIntent = mContentIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; // reset the notification notification.defaults = 0;//from w w w.ja v a 2 s . c o m if (enabledSound) notification.defaults |= Notification.DEFAULT_SOUND; if (enabledVibrate) notification.defaults |= Notification.DEFAULT_VIBRATE; notification.setLatestEventInfo(mainUIThreadActivity, (CharSequence) title, (CharSequence) text, mContentIntent); Log.i(TAG, "after updated notification contents"); mNM.notify(PROBE_NOTIFICATION_ID, notification); Log.i(TAG, "notified"); }
From source file:fr.rolandl.smartshareactionprovider.SmartActivityChooserModel.java
/** * Chooses a activity to handle the current intent. This will result in * adding a historical record for that action and construct intent with * its component name set such that it can be immediately started by the * client./*from ww w . j a v a 2s . c om*/ * <p> * <strong>Note:</strong> By calling this method the client guarantees * that the returned intent will be started. This intent is returned to * the client solely to let additional customization before the start. * </p> * * @return An {@link Intent} for launching the activity or null if the * policy has consumed the intent or there is not current intent * set via {@link #setIntent(Intent)}. * @see HistoricalRecord * @see OnChooseActivityListener */ public Intent chooseActivity(int index) { synchronized (mInstanceLock) { if (mIntent == null) { return null; } ensureConsistentState(); ActivityResolveInfo chosenActivity = mActivities.get(index); ComponentName chosenName = new ComponentName(chosenActivity.resolveInfo.activityInfo.packageName, chosenActivity.resolveInfo.activityInfo.name); Intent choiceIntent = new Intent(mIntent); choiceIntent.setComponent(chosenName); if (mActivityChoserModelPolicy != null) { // Do not allow the policy to change the intent. // Intent choiceIntentCopy = new Intent(choiceIntent); final boolean handled = mActivityChoserModelPolicy.onChooseActivity(this, choiceIntent); if (handled) { return null; } } HistoricalRecord historicalRecord = new HistoricalRecord(chosenName, System.currentTimeMillis(), DEFAULT_HISTORICAL_RECORD_WEIGHT); addHisoricalRecord(historicalRecord); return choiceIntent; } }
From source file:org.libreoffice.ui.LibreOfficeUIActivity.java
public void open(final IFile document) { new AsyncTask<IFile, Void, File>() { @Override// ww w.ja v a 2 s .c o m protected File doInBackground(IFile... document) { // this operation may imply network access and must be run in // a different thread try { return document[0].getDocument(); } catch (final RuntimeException e) { final Activity activity = LibreOfficeUIActivity.this; activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show(); } }); Log.e(LOGTAG, e.getMessage(), e.getCause()); return null; } } @Override protected void onPostExecute(File file) { if (file != null) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file)); String packageName = getApplicationContext().getPackageName(); ComponentName componentName = new ComponentName(packageName, LibreOfficeMainActivity.class.getName()); i.setComponent(componentName); // these extras allow to rebuild the IFile object in LOMainActivity i.putExtra("org.libreoffice.document_provider_id", documentProvider.getId()); i.putExtra("org.libreoffice.document_uri", document.getUri()); startActivity(i); } } }.execute(document); }