List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:com.ubikod.capptain.android.sdk.track.CapptainTrackReceiver.java
@Override public void onReceive(Context context, Intent intent) { /* Once the application identifier is known */ if ("com.ubikod.capptain.intent.action.APPID_GOT".equals(intent.getAction())) { /* Init the tracking agent */ String appId = intent.getStringExtra("appId"); CapptainTrackAgent.getInstance(context).onAppIdGot(appId); }/* w w w . j a v a2 s . com*/ /* During installation, an install referrer may be triggered */ else if ("com.android.vending.INSTALL_REFERRER".equals(intent.getAction())) { /* Forward this action to configured receivers */ String forwardList = CapptainUtils.getMetaData(context) .getString("capptain:track:installReferrerForwardList"); if (forwardList != null) for (String component : forwardList.split(",")) if (!component.equals(getClass().getName())) { Intent clonedIntent = new Intent(intent); clonedIntent.setComponent(new ComponentName(context, component)); context.sendBroadcast(clonedIntent); } /* Guess store from referrer */ String referrer = Uri.decode(intent.getStringExtra("referrer")); String store; /* GetJar uses an opaque string always starting with z= */ if (referrer.startsWith("z=")) store = "GetJar"; /* Assume Android Market otherwise */ else store = "Android Market"; /* Look for a source parameter */ Uri uri = Uri.parse("a://a?" + referrer); String source = uri.getQueryParameter("utm_source"); /* * Skip "androidmarket" source, this is the default one when not set or installed via web * Android Market. */ if ("androidmarket".equals(source)) source = null; /* Send app info to register store/source */ Bundle appInfo = new Bundle(); appInfo.putString("store", store); if (source != null) { /* Parse source, if coming from capptain, it may be a JSON complex object */ try { /* Convert JSON to bundle (just flat strings) */ JSONObject jsonInfo = new JSONObject(source); Iterator<?> keyIt = jsonInfo.keys(); while (keyIt.hasNext()) { String key = keyIt.next().toString(); appInfo.putString(key, jsonInfo.getString(key)); } } catch (JSONException jsone) { /* Not an object, process as a string */ appInfo.putString("source", source); } } /* Send app info */ CapptainAgent.getInstance(context).sendAppInfo(appInfo); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToSharedAppFeedObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject obj) { try {/* w w w . j a v a 2s. c om*/ String packageName = obj.getString(PACKAGE_NAME); String feedName = obj.getString("sharedFeedName"); JSONArray ids = obj.getJSONArray(PARTICIPANTS); Intent launch = new Intent(); launch.setAction(Intent.ACTION_MAIN); launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.putExtra("type", "invite_app_feed"); launch.putExtra("creator", false); launch.putExtra("sender", from.id); launch.putExtra("sharedFeedName", feedName); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); long[] idArray = new long[ids.length()]; for (int i = 0; i < ids.length(); i++) { idArray[i] = ids.getLong(i); } launch.putExtra("participants", idArray); launch.setPackage(packageName); final PackageManager mgr = context.getPackageManager(); List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0); if (resolved.size() == 0) { Toast.makeText(context, "Could not find application to handle invite.", Toast.LENGTH_SHORT).show(); return; } ActivityInfo info = resolved.get(0).activityInfo; launch.setComponent(new ComponentName(info.packageName, info.name)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch, PendingIntent.FLAG_CANCEL_CURRENT); (new PresenceAwareNotify(context)).notify("New Invitation from " + from.name, "Invitation received from " + from.name, "Click to launch application: " + packageName, contentIntent); } catch (JSONException e) { Log.e(TAG, e.getMessage()); } }
From source file:com.example.android.notepad.NotesList.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); // This is our one standard application action -- inserting a // new note into the list. menu.add(0, MENU_ITEM_INSERT, 0, R.string.menu_insert).setShortcut('3', 'a') .setIcon(android.R.drawable.ic_menu_add); // ilya: add refresh menu.add(0, MENU_ITEM_REFRESH, 0, "Refresh").setShortcut('4', 'r').setIcon(android.R.drawable.ic_menu_view); // Generate any additional actions that can be performed on the // overall list. In a normal install, there are no additional // actions found here, but this allows other applications to extend // our menu with their own actions. Intent intent = new Intent(null, getIntent().getData()); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, NotesList.class), null, intent, 0, null);//from w w w.j av a 2s. c o m return true; }
From source file:com.pspdfkit.cordova.PSPDFCordovaPlugin.java
@SuppressWarnings("ConstantConditions") @NonNull/* w ww . j ava 2s . c om*/ private PSPDFActivityConfiguration parseOptionsToConfiguration(@NonNull final JSONObject options) throws JSONException { final Activity activity = cordova.getActivity(); int theme; try { ActivityInfo info = activity.getPackageManager() .getActivityInfo(new ComponentName(activity, PSPDFActivity.class), 0); theme = info.theme; } catch (PackageManager.NameNotFoundException e) { theme = R.style.Theme_AppCompat_NoActionBar; } final ContextThemeWrapper themedContext = new ContextThemeWrapper(activity, theme); final PSPDFActivityConfiguration.Builder builder = new PSPDFActivityConfiguration.Builder(themedContext, licenseKey); final Iterator<String> optionIterator = options.keys(); while (optionIterator.hasNext()) { final String option = optionIterator.next(); final Object value = options.get(option); try { if ("backgroundColor".equals(option)) { builder.backgroundColor(Color.parseColor((String) value)); } else if ("disableOutline".equals(option) && ((Boolean) value)) { builder.disableOutline(); } else if ("disableSearch".equals(option) && ((Boolean) value)) { builder.disableSearch(); } else if ("hidePageLabels".equals(option) && ((Boolean) value)) { builder.hidePageLabels(); } else if ("hidePageNumberOverlay".equals(option) && ((Boolean) value)) { builder.hidePageNumberOverlay(); } else if ("hideThumbnailBar".equals(option) && ((Boolean) value)) { builder.hideThumbnailBar(); } else if ("hideThumbnailGrid".equals(option) && ((Boolean) value)) { builder.hideThumbnailGrid(); } else if ("diskCacheSize".equals(option)) { builder.diskCacheSize((Integer) value); } else if ("memoryCacheSize".equals(option)) { builder.memoryCacheSize((Integer) value); } else if ("pageFitMode".equals(option)) { builder.fitMode(PageFitMode.valueOf((String) value)); } else if ("scrollDirection".equals(option)) { builder.scrollDirection(PageScrollDirection.valueOf((String) value)); } else if ("scrollMode".equals(option)) { builder.scrollMode(PageScrollMode.valueOf((String) value)); } else if ("invertColors".equals(option)) { builder.invertColors((Boolean) value); } else if ("toGrayscale".equals(option)) { builder.toGrayscale((Boolean) value); } else if ("loggingEnabled".equals(option)) { builder.loggingEnabled((Boolean) value); } else if ("title".equals(option)) { builder.title(fromJsonString(options.getString("title"))); } else if ("startZoomScale".equals(option)) { builder.startZoomScale((float) options.getDouble("startZoomScale")); } else if ("maxZoomScale".equals(option)) { builder.maxZoomScale((float) options.getDouble("maxZoomScale")); } else if ("zoomOutBounce".equals(option)) { builder.zoomOutBounce(options.getBoolean("zoomOutBounce")); } else if ("page".equals(option)) { builder.page(options.getInt("page")); } else if ("useImmersiveMode".equals(option)) { builder.useImmersiveMode(options.getBoolean("useImmersiveMode")); } else if ("searchType".equals(option)) { final String searchType = options.getString("searchType"); if ("SEARCH_INLINE".equals(searchType)) builder.setSearchType(PSPDFActivityConfiguration.SEARCH_INLINE); else if ("SEARCH_MODULAR".equals(searchType)) builder.setSearchType(PSPDFActivityConfiguration.SEARCH_MODULAR); else throw new IllegalArgumentException(String.format("Invalid search type: %s", value)); } else if ("autosaveEnabled".equals(option)) { builder.autosaveEnabled(options.getBoolean("autosaveEnabled")); } else if ("annotationEditing".equals(option)) { final AnnotationEditingConfiguration.Builder annotationBuilder = new AnnotationEditingConfiguration.Builder( themedContext); final JSONObject annotationEditing = options.getJSONObject("annotationEditing"); final Iterator<String> annotationOptionIterator = annotationEditing.keys(); while (annotationOptionIterator.hasNext()) { final String annotationEditingOption = annotationOptionIterator.next(); final Object annotationEditingValue = annotationEditing.get(annotationEditingOption); if ("enabled".equals(annotationEditingOption)) { if ((Boolean) annotationEditingValue) annotationBuilder.enableAnnotationEditing(); else annotationBuilder.disableAnnotationEditing(); } else if ("creatorName".equals(annotationEditingOption)) { annotationBuilder.defaultAnnotationCreator( fromJsonString(annotationEditing.getString("creatorName"))); } else { throw new IllegalArgumentException(String .format("Invalid annotation editing option '%s'", annotationEditingOption)); } } builder.annotationEditingConfiguration(annotationBuilder.build()); } else { throw new IllegalArgumentException(String.format("Invalid plugin option '%s'", option)); } } catch (Exception ex) { throw new PSPDFCordovaPluginException(String.format("Error while parsing option '%s'", option), ex); } } return builder.build(); }
From source file:edu.umich.flowfence.testapp.TestActivity.java
public void runTest(View ignored) { try {/*from w w w . ja v a 2s . c om*/ setButtonsEnabled(false); FlowfenceConnection conn = connection; // start resolving init0 = conn.resolveConstructor(TestQM.class); init1 = conn.resolveConstructor(TestQM.class, String.class); concat = conn.resolveStatic(String.class, TestQM.class, "concat", String.class, String.class); getState = conn.resolveInstance(String.class, TestQM.class, "getconnecState"); swapState = conn.resolveInstance(String.class, TestQM.class, "swapState", String.class); log = conn.resolveInstance(void.class, TestQM.class, "log", String.class); logStatic = conn.resolveStatic(void.class, TestQM.class, "log", String.class, String.class); throwStatic = conn.resolveStatic(String.class, TestQM.class, "throwStatic", String.class); throwInstance = conn.resolveInstance(void.class, TestQM.class, "throwInstance", String.class); sleep = conn.resolveStatic(String.class, TestQM.class, "sleep", long.class); Log.i(TAG, "Done resolving"); ComponentName cn = new ComponentName(getPackageName(), "testChannel"); QMDescriptor sd = logStatic.getDescriptor(); conn.getRawInterface().subscribeEventChannel(cn, sd); Log.i(TAG, "Constructing with init0"); Sealed<TestQM> obj1 = init0.call(); obj1.buildCall(log).arg("obj1").call(); Log.i(TAG, "Constructing with init1"); Sealed<TestQM> obj2 = init1.arg("<foobar>").call(); Sealed<String> obj2State = getState.arg(obj2).call(); logStatic.arg("obj2State").arg(obj2State).call(); Log.i(TAG, "Calling static method"); Sealed<String> newState = concat.arg("state").arg(obj2State).call(); logStatic.arg("newState").arg(newState).call(); Log.i(TAG, "Calling instance with inout"); Sealed<String> oldState1 = swapState.inOut(obj1).arg(newState).call(); logStatic.arg("oldState1").arg(oldState1).call(); obj1.buildCall(log).arg("obj1'").call(); Log.i(TAG, "Calling instance without inout"); Sealed<String> oldState2 = swapState.in(obj2).arg(newState).call(); logStatic.arg("oldState2").arg(oldState2).call(); obj2.buildCall(log).arg("obj2'").call(); Log.i(TAG, "Testing exception propagation - static"); Sealed<String> excStatic = throwStatic.in("static test #1").call(); Sealed<String> excStatic2 = throwStatic.in("static test #2").call(); logStatic.arg(excStatic).arg(excStatic2).call(); Log.i(TAG, "Testing exception propagation - instance"); obj1.buildCall(throwInstance).arg("instance test - obj1").call(); obj1.buildCall(log).argNull().call(); throwInstance.in(obj2).arg("instance test - obj2").call(); obj2.buildCall(log).argNull().call(); Log.i(TAG, "Testing async method calls"); Sealed<String> sleepResult = sleep.arg(15 * 1000L).asAsync().call(); logStatic.arg("Sleep result").arg(sleepResult).asAsync().call(); Log.i(TAG, "All done!"); } catch (Exception e) { Log.wtf(TAG, "Exception in post-connect handler", e); } finally { Log.i(TAG, "Finishing"); setButtonsEnabled(true); } }
From source file:com.chale22.ico01.fragments.FragmentExtras.java
private void actIcons() { String pkg = getResources().getString(R.string.pkg); Intent iconfrag = new Intent(Intent.ACTION_MAIN); iconfrag.setComponent(new ComponentName(pkg, pkg + ".IconActivity")); try {/* w w w. ja v a 2s .com*/ startActivity(iconfrag); } catch (RuntimeException icons) { icons.printStackTrace(); } }
From source file:com.android.messaging.receiver.SmsReceiver.java
/** * Enable or disable the SmsReceiver as appropriate. Pre-KLP we use this receiver for * receiving incoming SMS messages. For KLP+ this receiver is not used when running as the * primary user and the SmsDeliverReceiver is used for receiving incoming SMS messages. * When running as a secondary user, this receiver is still used to trigger the incoming * notification./*w w w .j a v a 2 s.co m*/ */ public static void updateSmsReceiveHandler(final Context context) { boolean smsReceiverEnabled; boolean mmsWapPushReceiverEnabled; boolean respondViaMessageEnabled; boolean broadcastAbortEnabled; if (OsUtil.isAtLeastKLP()) { // When we're running as the secondary user, we don't get the new SMS_DELIVER intent, // only the primary user receives that. As secondary, we need to go old-school and // listen for the SMS_RECEIVED intent. For the secondary user, use this SmsReceiver // for both sms and mms notification. For the primary user on KLP (and above), we don't // use the SmsReceiver. smsReceiverEnabled = OsUtil.isSecondaryUser(); // On KLP use the new deliver event for mms mmsWapPushReceiverEnabled = false; // On KLP we need to always enable this handler to show in the list of sms apps respondViaMessageEnabled = true; // On KLP we don't need to abort the broadcast broadcastAbortEnabled = false; } else { // On JB we use the sms receiver for both sms/mms delivery final boolean carrierSmsEnabled = PhoneUtils.getDefault().isSmsEnabled(); smsReceiverEnabled = carrierSmsEnabled; // On JB we use the mms receiver when sms/mms is enabled mmsWapPushReceiverEnabled = carrierSmsEnabled; // On JB this is dynamic to make sure we don't show in dialer if sms is disabled respondViaMessageEnabled = carrierSmsEnabled; // On JB we need to abort broadcasts if SMS is enabled broadcastAbortEnabled = carrierSmsEnabled; } final PackageManager packageManager = context.getPackageManager(); final boolean logv = LogUtil.isLoggable(TAG, LogUtil.VERBOSE); if (smsReceiverEnabled) { if (logv) { LogUtil.v(TAG, "Enabling SMS message receiving"); } packageManager.setComponentEnabledSetting(new ComponentName(context, SmsReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else { if (logv) { LogUtil.v(TAG, "Disabling SMS message receiving"); } packageManager.setComponentEnabledSetting(new ComponentName(context, SmsReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } if (mmsWapPushReceiverEnabled) { if (logv) { LogUtil.v(TAG, "Enabling MMS message receiving"); } packageManager.setComponentEnabledSetting(new ComponentName(context, MmsWapPushReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else { if (logv) { LogUtil.v(TAG, "Disabling MMS message receiving"); } packageManager.setComponentEnabledSetting(new ComponentName(context, MmsWapPushReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } if (broadcastAbortEnabled) { if (logv) { LogUtil.v(TAG, "Enabling SMS/MMS broadcast abort"); } packageManager.setComponentEnabledSetting(new ComponentName(context, AbortSmsReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); packageManager.setComponentEnabledSetting(new ComponentName(context, AbortMmsWapPushReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else { if (logv) { LogUtil.v(TAG, "Disabling SMS/MMS broadcast abort"); } packageManager.setComponentEnabledSetting(new ComponentName(context, AbortSmsReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); packageManager.setComponentEnabledSetting(new ComponentName(context, AbortMmsWapPushReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } if (respondViaMessageEnabled) { if (logv) { LogUtil.v(TAG, "Enabling respond via message intent"); } packageManager.setComponentEnabledSetting( new ComponentName(context, NoConfirmationSmsSendService.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else { if (logv) { LogUtil.v(TAG, "Disabling respond via message intent"); } packageManager.setComponentEnabledSetting( new ComponentName(context, NoConfirmationSmsSendService.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } }
From source file:co.carlosjimenez.android.currencyalerts.app.widget.DetailWidgetProvider.java
@Override public void onReceive(@NonNull Context context, @NonNull Intent intent) { super.onReceive(context, intent); if (ForexSyncAdapter.ACTION_DATA_UPDATED.equals(intent.getAction())) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, getClass())); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_list); }/*w ww. ja va2s . com*/ }
From source file:com.dpcsoftware.mn.App.java
public void setFlag(int tableId) { switch (tableId) { case 1://from w w w. j a v a 2 s . c o m mnUpdateList = true; //Update widgets if anyone is being used AppWidgetManager wManager = AppWidgetManager.getInstance(this); ComponentName cWidgetProvider = new ComponentName(this, Widget1.class); int wIds[] = wManager.getAppWidgetIds(cWidgetProvider); if (wIds.length != 0) { Intent updateIntent = new Intent(this, Widget1.class); updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, wIds); try { PendingIntent.getBroadcast(this, 0, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT).send(); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } } break; case 2: mnUpdateList = true; break; case 3: mnUpdateMenu = true; break; } }