List of usage examples for android.content Intent getIntExtra
public int getIntExtra(String name, int defaultValue)
From source file:com.adam.aslfms.util.Util.java
/** * Returns whether the phone is running on battery or if it is connected to * a charger.//from w ww . j a v a 2s . c o m * * @param ctx context to get access to battery-checking methods * @return an enum indicating what the power source is * @see PowerOptions */ public static PowerOptions checkPower(Context ctx) { IntentFilter battFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent intent = ctx.registerReceiver(null, battFilter); if (intent != null) { int plugged = intent.getIntExtra("plugged", -1); if (plugged == 0) { // == 0 means on battery return PowerOptions.BATTERY; } else { return PowerOptions.PLUGGED_IN; } } Log.d(TAG, "Failed to get intent, assuming battery"); return PowerOptions.BATTERY; }
From source file:ly.count.android.sdk.CrashDetails.java
/** * Returns the current device battery level. *//*w w w . j ava 2 s . co m*/ static String getBatteryLevel(Context context) { try { Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (batteryIntent != null) { int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); // Error checking that probably isn't needed but I added just in case. if (level > -1 && scale > 0) { return Float.toString(((float) level / (float) scale) * 100.0f); } } } catch (Exception e) { if (Countly.sharedInstance().isLoggingEnabled()) { Log.i(Countly.TAG, "Can't get batter level"); } } return null; }
From source file:gxu.software_engineering.market.android.util.ServiceHelper.java
public static void doing(ContentResolver contentResolver, Intent intent) throws JSONException { String httpUri = intent.getStringExtra(C.HTTP_URI); Log.i("http uri", httpUri); JSONObject data = null;/* w w w . j a v a 2s .co m*/ try { data = RESTMethod.get(httpUri); } catch (IOException e) { e.printStackTrace(); } Log.i("json result", data.toString()); JSONArray array = null; ContentValues[] items = null; switch (intent.getIntExtra(C.TARGET_ENTITY, -1)) { case CATEGORIES: array = data.getJSONArray(C.CATEGORIES); ContentValues[] categories = Processor.toCategories(array); contentResolver.bulkInsert(intent.getData(), categories); break; case LASTEST_USERS: array = data.getJSONArray(C.USERS); ContentValues[] users = Processor.toUsers(array); contentResolver.bulkInsert(intent.getData(), users); break; case LASTEST_ITEMS: array = data.getJSONArray(C.ITEMS); items = Processor.toItems(array); contentResolver.bulkInsert(intent.getData(), items); break; case HOTTEST_ITEMS: array = data.getJSONArray(C.ITEMS); items = Processor.toItems(array); contentResolver.bulkInsert(intent.getData(), items); break; case USER_ITEMS: array = data.getJSONArray(C.ITEMS); items = Processor.toItems(array); contentResolver.bulkInsert(intent.getData(), items); break; case CATEGORY_ITEMS: array = data.getJSONArray(C.ITEMS); items = Processor.toItems(array); contentResolver.bulkInsert(intent.getData(), items); break; case USER_CLOSED_ITEMS: array = data.getJSONArray(C.ITEMS); items = Processor.toItems(array); contentResolver.bulkInsert(intent.getData(), items); break; case USER_DEAL_ITEMS: array = data.getJSONArray(C.ITEMS); items = Processor.toItems(array); contentResolver.bulkInsert(intent.getData(), items); break; default: throw new IllegalArgumentException("sorry, 404 for the target!"); } }
From source file:com.android.messaging.receiver.SmsReceiver.java
public static void deliverSmsIntent(final Context context, final Intent intent) { final android.telephony.SmsMessage[] messages = getMessagesFromIntent(intent); // Check messages for validity if (messages == null || messages.length < 1) { LogUtil.e(TAG, "processReceivedSms: null or zero or ignored message"); return;//from ww w .ja v a 2 s . c o m } final int errorCode = intent.getIntExtra(EXTRA_ERROR_CODE, 0); // Always convert negative subIds into -1 int subId = PhoneUtils.getDefault().getEffectiveIncomingSubIdFromSystem(intent, EXTRA_SUB_ID); deliverSmsMessages(context, subId, errorCode, messages); if (MmsUtils.isDumpSmsEnabled()) { final String format = null; DebugUtils.dumpSms(messages[0].getTimestampMillis(), messages, format); } }
From source file:cis350.blanket.IntentIntegrator.java
/** * <p>Call this from your {@link Activity}'s * {@link Activity#onActivityResult(int, int, Intent)} method.</p> * * @param requestCode request code from {@code onActivityResult()} * @param resultCode result code from {@code onActivityResult()} * @param intent {@link Intent} from {@code onActivityResult()} * @return null if the event handled here was not related to this class, or * else an {@link IntentResult} containing the result of the scan. If the user cancelled scanning, * the fields will be null./*from w w w. ja v a2s. c o m*/ */ public static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT"); byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES"); int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE); Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation; String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL"); return new IntentResult(contents, formatName, rawBytes, orientation, errorCorrectionLevel); } return new IntentResult(); } return null; }
From source file:csic.ceab.movelab.beepath.Util.java
public static int getBatteryLevel(Context context) { Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int level = batteryIntent.getIntExtra("level", -1); int scale = batteryIntent.getIntExtra("scale", -1); // Error checking that probably isn't needed but I added just in case. if (level == -1 || scale == -1) { return -1; }/*from w ww .j a va 2 s . co m*/ int powerLevel = (int) Math.round(level * 100.0 / scale); return powerLevel; }
From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java
/** * Given an Intent, returns the drawable id of the image to show on the default error activity. * * @param intent The Intent. Must not be null. * @return The id of the drawable to use. *//* ww w .j a v a 2 s . c om*/ public static int getDefaultErrorActivityDrawableIdFromIntent(Intent intent) { return intent.getIntExtra(CustomActivityOnCrash.EXTRA_IMAGE_DRAWABLE_ID, R.drawable.customactivityoncrash_error_image); }
From source file:org.metawatch.manager.Monitors.java
private static void createBatteryLevelReciever(Context context) { if (batteryLevelReceiver != null) return;/*from ww w . j a v a 2 s. c om*/ batteryLevelReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); int level = -1; if (rawlevel >= 0 && scale > 0) { level = (rawlevel * 100) / scale; } boolean charging = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) > 0; if (BatteryData.level != level || BatteryData.charging != charging) { //if (Preferences.logging) Log.d(MetaWatch.TAG, "Battery level changed: "+rawlevel+"/"+scale+" - "+level+"%"); BatteryData.level = level; BatteryData.charging = charging; Idle.updateIdle(context, true); } } }; context.registerReceiver(batteryLevelReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); }
From source file:com.alex.vmandroid.display.spread.store.StoreRecordDbListActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_store_record_db_list); Intent intent = getIntent(); int storeId = intent.getIntExtra("StoreId", -1); String storeTitle = intent.getStringExtra("StoreTitle"); StoreRecordDbListFragment fragment = StoreRecordDbListFragment.newInstance(); new StoreRecordDbListPresenter(fragment, storeId, storeTitle, getApplicationContext()); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(R.id.store_record_list_frame_layout, fragment); transaction.commit();//from ww w .ja va 2s. co m }
From source file:net.eledge.android.europeana.gui.notification.receiver.UrlButtonReceiver.java
@Override public void onReceive(Context context, Intent intent) { int notificationId = intent.getIntExtra(PARAM_NOTIFICATIONID, Config.NOTIFICATION_NEWBLOG); String url = intent.getStringExtra(PARAM_URL); if (StringUtils.isNoneBlank(url)) { try {/*from ww w . ja v a 2 s .c om*/ PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse(url)), PendingIntent.FLAG_UPDATE_CURRENT).send(); } catch (PendingIntent.CanceledException e) { Log.e(UrlButtonReceiver.class.getSimpleName(), e.getMessage(), e); } } final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(notificationId); }