List of usage examples for android.content Intent getIntExtra
public int getIntExtra(String name, int defaultValue)
From source file:com.ayaseya.nolnotification.GcmIntentService.java
@Override public void onCreate() { super.onCreate(); ringerMode = false;/*from w w w . j a va 2 s . co m*/ silentMode = false; vibrateMode = false; isPlugged = false; sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); checkbox_sound = sharedPreferences.getBoolean("checkbox_sound_key", true); checkbox_vibration = sharedPreferences.getBoolean("checkbox_vibration_key", false); Set<String> multiValues = sharedPreferences.getStringSet("list_preference", null); ArrayList<String> timeZone = new ArrayList<String>(); if (multiValues != null) { timeZone.addAll(multiValues); Collections.sort(timeZone); for (int i = 0; i < timeZone.size(); i++) { // Log.v(TAG, "TimeZone=" + timeZone.get(i)); } Calendar calendar = Calendar.getInstance(); int hour = calendar.get(Calendar.HOUR_OF_DAY); if (timeZone.indexOf(String.valueOf(hour)) == -1) { notificationPermission = false; // Log.v(TAG, "?????????"); } else { notificationPermission = true; // Log.v(TAG, "??????"); } } vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); ringerModeStateChangeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // ? if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_NORMAL) { // ringerMode = true; } else { ringerMode = false; } if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_VIBRATE) { // vibrateMode = true; } else { vibrateMode = false; } if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_SILENT) { // silentMode = true; } else { silentMode = false; } } } }; plugStateChangeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // ? if (intent.getIntExtra("state", 0) > 0) { isPlugged = true; // Log.v(TAG, "IN"); } else { isPlugged = false; // Log.v(TAG, "OUT"); } } }; // Broadcast Receiver??? registerReceiver(plugStateChangeReceiver, plugIntentFilter); registerReceiver(ringerModeStateChangeReceiver, ringerModeIntentFilter); }
From source file:com.winsuk.pebbletype.WatchCommunication.java
@Override public void onReceive(Context context, Intent intent) { if (ACTION_PEBBLE_RECEIVE.equals(intent.getAction())) { final UUID receivedUuid = (UUID) intent.getSerializableExtra("uuid"); // Pebble-enabled apps are expected to be good citizens and only inspect broadcasts containing their UUID if (!PEBBLE_APP_UUID.equals(receivedUuid)) { return; }/*ww w .j av a2s . c o m*/ final int transactionId = intent.getIntExtra("transaction_id", -1); final String jsonData = intent.getStringExtra("msg_data"); if (jsonData == null || jsonData.isEmpty()) { return; } try { final PebbleDictionary data = PebbleDictionary.fromJson(jsonData); receiveData(context, transactionId, data); } catch (JSONException e) { e.printStackTrace(); return; } } if (ACTION_SMS_REPLY.equals(intent.getAction())) { boolean sent = getResultCode() == Activity.RESULT_OK; if (!sent) Log.w("com.winsuk.pebbletype", "Message failed to send. Result code: " + getResultCode()); PebbleDictionary data = new PebbleDictionary(); data.addUint8(sent ? KEY_MESSAGE_SENT : KEY_MESSAGE_NOT_SENT, (byte) 1); PebbleKit.sendDataToPebble(context, PEBBLE_APP_UUID, data); } }
From source file:com.sip.pwc.sipphone.service.Downloader.java
@Override protected void onHandleIntent(Intent intent) { HttpGet getMethod = new HttpGet(intent.getData().toString()); int result = Activity.RESULT_CANCELED; String outPath = intent.getStringExtra(EXTRA_OUTPATH); boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false); int icon = intent.getIntExtra(EXTRA_ICON, 0); String title = intent.getStringExtra(EXTRA_TITLE); boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title)); // Build notification Builder nb = new Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);/* www . j a v a 2 s . c o m*/ nb.setSmallIcon(android.R.drawable.stat_sys_download); nb.setOngoing(true); Intent i = new Intent(this, SipHome.class); nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_notif); contentView.setImageViewResource(R.id.status_icon, icon); contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text)); contentView.setProgressBar(R.id.status_progress, 50, 0, false); contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE); nb.setContent(contentView); final Notification notification = showNotif ? nb.build() : null; notification.contentView = contentView; if (!TextUtils.isEmpty(outPath)) { try { File output = new File(outPath); if (output.exists()) { output.delete(); } if (notification != null) { notificationManager.notify(NOTIF_DOWNLOAD, notification); } ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() { private int oldState = 0; @Override public void run(long progress, long total) { //Log.d(THIS_FILE, "Progress is "+progress+" on "+total); int newState = (int) Math.round(progress * 50.0f / total); if (oldState != newState) { notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false); notificationManager.notify(NOTIF_DOWNLOAD, notification); oldState = newState; } } }); boolean hasReply = client.execute(getMethod, responseHandler); if (hasReply) { if (checkMd5) { URL url = new URL(intent.getData().toString().concat(".md5sum")); InputStream content = (InputStream) url.getContent(); if (content != null) { BufferedReader br = new BufferedReader(new InputStreamReader(content)); String downloadedMD5 = ""; try { downloadedMD5 = br.readLine().split(" ")[0]; } catch (NullPointerException e) { throw new IOException("md5_verification : no sum on server"); } if (!MD5.checkMD5(downloadedMD5, output)) { throw new IOException("md5_verification : incorrect"); } } } PendingIntent pendingIntent = (PendingIntent) intent .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT); try { Runtime.getRuntime().exec("chmod 644 " + outPath); } catch (IOException e) { Log.e(THIS_FILE, "Unable to make the apk file readable", e); } Log.d(THIS_FILE, "Download finished of : " + outPath); if (pendingIntent != null) { notification.contentIntent = pendingIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.icon = android.R.drawable.stat_sys_download_done; notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE); notification.contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.done) // TODO should be a parameter of this class + " - Click to install"); notificationManager.notify(NOTIF_DOWNLOAD, notification); /* try { pendingIntent.send(); notificationManager.cancel(NOTIF_DOWNLOAD); } catch (CanceledException e) { Log.e(THIS_FILE, "Impossible to start pending intent for download finish"); } */ } else { Log.w(THIS_FILE, "Invalid pending intent for finish !!!"); } result = Activity.RESULT_OK; } } catch (IOException e) { Log.e(THIS_FILE, "Exception in download", e); } } if (result == Activity.RESULT_CANCELED) { notificationManager.cancel(NOTIF_DOWNLOAD); } }
From source file:org.anhonesteffort.flock.SubscriptionGoogleFragment.java
protected void handlePurchaseIntentResult(int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (data.getIntExtra("RESPONSE_CODE", 0) == 0) handleItemPurchased(data);// w ww. j a va2 s . c om else handleItemPurchaseFailed(data); } else handleItemPurchaseCanceled(); subscriptionActivity.handleClearActivityResult(); }
From source file:com.csipsimple.service.Downloader.java
@Override protected void onHandleIntent(Intent intent) { HttpGet getMethod = new HttpGet(intent.getData().toString()); int result = Activity.RESULT_CANCELED; String outPath = intent.getStringExtra(EXTRA_OUTPATH); boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false); int icon = intent.getIntExtra(EXTRA_ICON, 0); String title = intent.getStringExtra(EXTRA_TITLE); boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title)); // Build notification Builder nb = new NotificationCompat.Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);//w w w .j a va 2 s . co m nb.setSmallIcon(android.R.drawable.stat_sys_download); nb.setOngoing(true); Intent i = new Intent(this, SipHome.class); nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_notif); contentView.setImageViewResource(R.id.status_icon, icon); contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text)); contentView.setProgressBar(R.id.status_progress, 50, 0, false); contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE); nb.setContent(contentView); final Notification notification = showNotif ? nb.build() : null; notification.contentView = contentView; if (!TextUtils.isEmpty(outPath)) { try { File output = new File(outPath); if (output.exists()) { output.delete(); } if (notification != null) { notificationManager.notify(NOTIF_DOWNLOAD, notification); } ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() { private int oldState = 0; @Override public void run(long progress, long total) { //Log.d(THIS_FILE, "Progress is "+progress+" on "+total); int newState = (int) Math.round(progress * 50.0f / total); if (oldState != newState) { notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false); notificationManager.notify(NOTIF_DOWNLOAD, notification); oldState = newState; } } }); boolean hasReply = client.execute(getMethod, responseHandler); if (hasReply) { if (checkMd5) { URL url = new URL(intent.getData().toString().concat(".md5sum")); InputStream content = (InputStream) url.getContent(); if (content != null) { BufferedReader br = new BufferedReader(new InputStreamReader(content)); String downloadedMD5 = ""; try { downloadedMD5 = br.readLine().split(" ")[0]; } catch (NullPointerException e) { throw new IOException("md5_verification : no sum on server"); } if (!MD5.checkMD5(downloadedMD5, output)) { throw new IOException("md5_verification : incorrect"); } } } PendingIntent pendingIntent = (PendingIntent) intent .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT); try { Runtime.getRuntime().exec("chmod 644 " + outPath); } catch (IOException e) { Log.e(THIS_FILE, "Unable to make the apk file readable", e); } Log.d(THIS_FILE, "Download finished of : " + outPath); if (pendingIntent != null) { notification.contentIntent = pendingIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.icon = android.R.drawable.stat_sys_download_done; notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE); notification.contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.done) // TODO should be a parameter of this class + " - Click to install"); notificationManager.notify(NOTIF_DOWNLOAD, notification); /* try { pendingIntent.send(); notificationManager.cancel(NOTIF_DOWNLOAD); } catch (CanceledException e) { Log.e(THIS_FILE, "Impossible to start pending intent for download finish"); } */ } else { Log.w(THIS_FILE, "Invalid pending intent for finish !!!"); } result = Activity.RESULT_OK; } } catch (IOException e) { Log.e(THIS_FILE, "Exception in download", e); } } if (result == Activity.RESULT_CANCELED) { notificationManager.cancel(NOTIF_DOWNLOAD); } }
From source file:com.sonetel.service.Downloader.java
@Override protected void onHandleIntent(Intent intent) { HttpGet getMethod = new HttpGet(intent.getData().toString()); int result = Activity.RESULT_CANCELED; String outPath = intent.getStringExtra(EXTRA_OUTPATH); boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false); int icon = intent.getIntExtra(EXTRA_ICON, 0); String title = intent.getStringExtra(EXTRA_TITLE); boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title)); // Build notification Builder nb = new NotificationCompat.Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);/*from ww w . j a v a 2s.com*/ nb.setSmallIcon(android.R.drawable.stat_sys_download); nb.setOngoing(true); Intent i = new Intent(this, SipHome.class); nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_notif); contentView.setImageViewResource(R.id.status_icon, icon); contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text)); contentView.setProgressBar(R.id.status_progress, 50, 0, false); contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE); nb.setContent(contentView); final Notification notification = showNotif ? nb.getNotification() : null; notification.contentView = contentView; if (!TextUtils.isEmpty(outPath)) { try { File output = new File(outPath); if (output.exists()) { output.delete(); } if (notification != null) { notificationManager.notify(NOTIF_DOWNLOAD, notification); } ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() { private int oldState = 0; @Override public void run(long progress, long total) { //Log.d(THIS_FILE, "Progress is "+progress+" on "+total); int newState = (int) Math.round(progress * 50.0f / total); if (oldState != newState) { notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false); notificationManager.notify(NOTIF_DOWNLOAD, notification); oldState = newState; } } }); boolean hasReply = client.execute(getMethod, responseHandler); if (hasReply) { if (checkMd5) { URL url = new URL(intent.getData().toString().concat(".md5sum")); InputStream content = (InputStream) url.getContent(); if (content != null) { BufferedReader br = new BufferedReader(new InputStreamReader(content)); String downloadedMD5 = ""; try { downloadedMD5 = br.readLine().split(" ")[0]; } catch (NullPointerException e) { throw new IOException("md5_verification : no sum on server"); } if (!MD5.checkMD5(downloadedMD5, output)) { throw new IOException("md5_verification : incorrect"); } } } PendingIntent pendingIntent = (PendingIntent) intent .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT); try { Runtime.getRuntime().exec("chmod 644 " + outPath); } catch (IOException e) { Log.e(THIS_FILE, "Unable to make the apk file readable", e); } Log.d(THIS_FILE, "Download finished of : " + outPath); if (pendingIntent != null) { notification.contentIntent = pendingIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.icon = android.R.drawable.stat_sys_download_done; notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE); notification.contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.done) // TODO should be a parameter of this class + " - Click to install"); notificationManager.notify(NOTIF_DOWNLOAD, notification); /* try { pendingIntent.send(); notificationManager.cancel(NOTIF_DOWNLOAD); } catch (CanceledException e) { Log.e(THIS_FILE, "Impossible to start pending intent for download finish"); } */ } else { Log.w(THIS_FILE, "Invalid pending intent for finish !!!"); } result = Activity.RESULT_OK; } } catch (IOException e) { Log.e(THIS_FILE, "Exception in download", e); } } if (result == Activity.RESULT_CANCELED) { notificationManager.cancel(NOTIF_DOWNLOAD); } }
From source file:com.android.deskclock.alarms.AlarmStateManager.java
public static void handleIntent(Context context, Intent intent) { final String action = intent.getAction(); LogUtils.v("AlarmStateManager received intent " + intent); if (CHANGE_STATE_ACTION.equals(action)) { Uri uri = intent.getData();/* w w w.jav a2 s . com*/ AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Can not change state for unknown instance: " + uri); return; } int globalId = getGlobalIntentId(context); int intentId = intent.getIntExtra(ALARM_GLOBAL_ID_EXTRA, -1); int alarmState = intent.getIntExtra(ALARM_STATE_EXTRA, -1); if (intentId != globalId) { LogUtils.i("IntentId: " + intentId + " GlobalId: " + globalId + " AlarmState: " + alarmState); // Allows dismiss/snooze requests to go through if (!intent.hasCategory(ALARM_DISMISS_TAG) && !intent.hasCategory(ALARM_SNOOZE_TAG)) { LogUtils.i("Ignoring old Intent"); return; } } if (intent.getBooleanExtra(FROM_NOTIFICATION_EXTRA, false)) { if (intent.hasCategory(ALARM_DISMISS_TAG)) { Events.sendAlarmEvent(R.string.action_dismiss, R.string.label_notification); } else if (intent.hasCategory(ALARM_SNOOZE_TAG)) { Events.sendAlarmEvent(R.string.action_snooze, R.string.label_notification); } } if (alarmState >= 0) { setAlarmState(context, instance, alarmState); } else { registerInstance(context, instance, true); } } else if (SHOW_AND_DISMISS_ALARM_ACTION.equals(action)) { Uri uri = intent.getData(); AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(), AlarmInstance.getId(uri)); if (instance == null) { LogUtils.e("Null alarminstance for SHOW_AND_DISMISS"); // dismiss the notification final int id = intent.getIntExtra(AlarmNotifications.EXTRA_NOTIFICATION_ID, -1); if (id != -1) { NotificationManagerCompat.from(context).cancel(id); } return; } long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId); viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX); viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId); viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(viewAlarmIntent); deleteInstanceAndUpdateParent(context, instance); } }
From source file:com.example.android.wearable.mjpegviewwear.MainActivity.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_SETTINGS: if (resultCode == Activity.RESULT_OK) { mWidth = data.getIntExtra("width", mWidth); mHeight = data.getIntExtra("height", mHeight); mIp_ad1 = data.getIntExtra("ip_ad1", mIp_ad1); mIp_ad2 = data.getIntExtra("ip_ad2", mIp_ad2); mIp_ad3 = data.getIntExtra("ip_ad3", mIp_ad3); mIp_ad4 = data.getIntExtra("ip_ad4", mIp_ad4); mIp_port = data.getIntExtra("ip_port", mIp_port); mIp_command = data.getStringExtra("ip_command"); mFrameSkip = data.getIntExtra("frameSkip", mFrameSkip); if (mMv != null) { mMv.setResolution(mWidth, mHeight); mMv.setFrameSkip(mFrameSkip); }/* w ww. ja v a 2s. c o m*/ SharedPreferences preferences = getSharedPreferences("SAVED_VALUES", MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("width", mWidth); editor.putInt("height", mHeight); editor.putInt("ip_ad1", mIp_ad1); editor.putInt("ip_ad2", mIp_ad2); editor.putInt("ip_ad3", mIp_ad3); editor.putInt("ip_ad4", mIp_ad4); editor.putInt("ip_port", mIp_port); editor.putString("ip_command", mIp_command); editor.putInt("frameSkip", mFrameSkip); editor.commit(); new RestartApp().execute(); } break; } }
From source file:com.ucai.test.control.DeviceControlActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gatt_services_characteristics); initView();/*from www. j av a 2 s . c o m*/ //EditActivity Intent intentCon = getIntent(); sex = intentCon.getIntExtra("sex", 1); final Intent intent = getIntent(); mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME); mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS); // Sets up UI references.UI //TODO //((TextView) findViewById(R.id.device_address)).setText(mDeviceAddress); //mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list); // mGattServicesList.setOnChildClickListener(servicesListClickListner); mConnectionState = (TextView) findViewById(R.id.connection_state);//? mDataField = (TextView) findViewById(R.id.data_value); mDeviceDataField = (TextView) findViewById(R.id.device_type_value);//? mDeviceDataName = (TextView) findViewById(R.id.device_type_name);//? // getActionBar().setTitle(mDeviceName); // getActionBar().setDisplayHomeAsUpEnabled(true); //TODO ?? Intent gattServiceIntent = new Intent(this, BluetoothLeService.class); bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); //??? tv_weight_center.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(DeviceControlActivity.this, DeviceScanActivity.class); new DeviceScanActivity(); // startActivity(intent); // finish(); } }); }
From source file:app.umitems.greenclock.DeskClock.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); mSelectedTab = CLOCK_TAB_INDEX;// www . j av a2s .co m if (icicle != null) { mSelectedTab = icicle.getInt(KEY_SELECTED_TAB, CLOCK_TAB_INDEX); } // Timer receiver may ask the app to go to the timer fragment if a timer expired Intent i = getIntent(); if (i != null) { int tab = i.getIntExtra(SELECT_TAB_INTENT_EXTRA, -1); if (tab != -1) { mSelectedTab = tab; } } initViews(); setHomeTimeZone(); // We need to update the system next alarm time on app startup because the // user might have clear our data. AlarmStateManager.updateNextAlarm(this); }