Java Code Examples for android.content.Intent.getIntExtra()

The following are Jave code examples for showing how to use getIntExtra() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: FloatingWidget   File: MainActivity.java   View Source Code Vote up 11 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = getIntent();
    int button = intent.getIntExtra(BUTTON_KEY, 0);
    if(button > 0) {
        ((TextView)findViewById(R.id.textview)).setText("Button " + button + " is pressed!");
    }

    //Ask permission
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {

        Intent permissionIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + getPackageName()));
        startActivityForResult(permissionIntent, CODE_DRAW_OVER_OTHER_APP_PERMISSION);
    }
}
 
Example 2
Project: boohee_v5.6   File: h.java   View Source Code Vote up 8 votes
private void d(Intent intent) {
    if (intent != null) {
        String stringExtra = intent.getStringExtra("error");
        Throwable th = new Throwable(stringExtra + " (" + intent.getIntExtra("error_code", -1) + SocializeConstants.OP_CLOSE_PAREN);
        if (this.c != null) {
            this.c.onFailed(th);
        }
    } else if (this.c != null) {
        this.c.onCancel();
    }
}
 
Example 3
Project: wzyx-android-user   File: MainActivity.java   View Source Code Vote up 8 votes
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    int requestCode = intent.getIntExtra("pay_success",0);
    if(requestCode == REQUEST_CODE_PAY_SUCCESS){
        selectOrderFragment();
    }
}
 
Example 4
Project: Exoplayer2Radio   File: InfosheetActivity.java   View Source Code Vote up 8 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // get activity title from intent
    Intent intent = this.getIntent();

    // set activity title
    if (intent.hasExtra(EXTRA_INFOSHEET_TITLE)) {
        this.setTitle(intent.getStringExtra(EXTRA_INFOSHEET_TITLE));
    }

    // set activity view
    if (intent.hasExtra(EXTRA_INFOSHEET_CONTENT) && intent.getIntExtra(EXTRA_INFOSHEET_CONTENT, -1) == INFOSHEET_CONTENT_ABOUT) {
        setContentView(R.layout.fragment_infosheet_about);
    } else if (intent.hasExtra(EXTRA_INFOSHEET_CONTENT) && intent.getIntExtra(EXTRA_INFOSHEET_CONTENT, -1) == INFOSHEET_CONTENT_HOWTO) {
        setContentView(R.layout.fragment_infosheet_howto);
    }

}
 
Example 5
Project: ServiceDownLoadApp-master   File: UpdateService.java   View Source Code Vote up 8 votes
@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (!startDownload && intent != null){
            startDownload = true;
            downloadUrl = intent.getStringExtra(URL);
            icoResId = intent.getIntExtra(ICO_RES_ID, DEFAULT_RES_ID);
            icoSmallResId = intent.getIntExtra(ICO_SMALL_RES_ID, DEFAULT_RES_ID);
            storeDir = intent.getStringExtra(STORE_DIR);
            updateProgress = intent.getIntExtra(UPDATE_PROGRESS, UPDATE_NUMBER_SIZE);
            downloadNotificationFlag = intent.getIntExtra(DOWNLOAD_NOTIFICATION_FLAG, 0);
            downloadErrorNotificationFlag = intent.getIntExtra(DOWNLOAD_ERROR_NOTIFICATION_FLAG, 0);
            downloadSuccessNotificationFlag = intent.getIntExtra(DOWNLOAD_SUCCESS_NOTIFICATION_FLAG, 0);
            isSendBroadcast = intent.getBooleanExtra(IS_SEND_BROADCAST, false);


//            if (DEBUG){
               LogUtil.e(TAG, "downloadUrl: " + downloadUrl);
               LogUtil.e(TAG, "icoResId: " + icoResId);
               LogUtil.e(TAG, "icoSmallResId: " + icoSmallResId);
               LogUtil.e(TAG, "storeDir: " + storeDir);
               LogUtil.e(TAG, "updateProgress: " + updateProgress);
               LogUtil.e(TAG, "downloadNotificationFlag: " + downloadNotificationFlag);
               LogUtil.e(TAG, "downloadErrorNotificationFlag: " + downloadErrorNotificationFlag);
               LogUtil.e(TAG, "downloadSuccessNotificationFlag: " + downloadSuccessNotificationFlag);
               LogUtil.e(TAG, "isSendBroadcast: " + isSendBroadcast);
//            }

            notifyId = startId;
            buildNotification();
            buildBroadcast();
            downloadApkTask = new DownloadApk(this);
            downloadApkTask.execute(downloadUrl);
        }
        return super.onStartCommand(intent, flags, startId);
    }
 
Example 6
Project: MobileAppForPatient   File: BluetoothHandler.java   View Source Code Vote up 8 votes
private void performBondStateChangeAction(Intent intent) {
    final int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
    final int prevState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, BluetoothDevice.ERROR);
    if (state == BluetoothDevice.BOND_BONDED && prevState == BluetoothDevice.BOND_BONDING) {
        showToast(mContext.getString(R.string.device_paired));
        connectToZephyrDevice();
    } else if (state == BluetoothDevice.BOND_NONE) {
        showToast(mContext.getString(R.string.device_pairing_failure));
    }
}
 
Example 7
Project: q-mail   File: CoreReceiver.java   View Source Code Vote up 8 votes
@Override
public void onReceive(Context context, Intent intent) {
    Integer tmpWakeLockId = CoreReceiver.getWakeLock(context);
    try {
        Timber.i("CoreReceiver.onReceive %s", intent);

        if (CoreReceiver.WAKE_LOCK_RELEASE.equals(intent.getAction())) {
            Integer wakeLockId = intent.getIntExtra(WAKE_LOCK_ID, -1);
            if (wakeLockId != -1) {
                Timber.v("CoreReceiver Release wakeLock %d", wakeLockId);
                CoreReceiver.releaseWakeLock(wakeLockId);
            }
        } else {
            tmpWakeLockId = receive(context, intent, tmpWakeLockId);
        }
    } finally {
        CoreReceiver.releaseWakeLock(tmpWakeLockId);
    }
}
 
Example 8
Project: PaoMovie   File: Setting.java   View Source Code Vote up 8 votes
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	// TODO Auto-generated method stub
	super.onActivityResult(requestCode, resultCode, data);
	switch (resultCode) {
	case 1:
		int netState = data.getIntExtra("netState", 0);
		switch (netState) {
		case 0:
			autoPlayVideoSettingsText.setText("仅wifi");
			break;
		case 1:
			autoPlayVideoSettingsText.setText("移动蜂窝和wifi");
			break;
		case 2:
			autoPlayVideoSettingsText.setText("从不");
			break;
		default:
			break;
		}
		break;

	default:
		break;
	}
}
 
Example 9
Project: AssistantBySDK   File: RemindEditActivity.java   View Source Code Vote up 8 votes
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (data != null) {
        switch (resultCode) {
            case TimePickerActivity.FOR_TIME_RESULT:
                int v = data.getIntExtra(TimePickerActivity.TIME, -1);
                if (v > -1) {
                    dt = new SimpleDate(v);
                    mAreTime.setText(dt.toString());
                }
                break;
            case DatePickerActivity.FOR_DATE_RESULT:
                dd.setTimeInMillis(data.getLongExtra(DatePickerActivity.DATE, System.currentTimeMillis()));
                mAreDate.setText(sdf.format(new Date(dd.getTimeInMillis())));
                break;
            case RemindFrSettingActivity.FOR_FR:
                fr = data.getIntExtra(RemindFrSettingActivity.TYPE, 0);
                mAreFr.setText(AssistUtils.translateRemindFrequency(fr, dd));
                break;
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example 10
Project: stynico   File: BatteryWrapper.java   View Source Code Vote up 8 votes
@Override 
public void onReceive(Context arg0, Intent intent)
{  
 String action=intent.getAction();
 if(action.equals(Intent.ACTION_BATTERY_CHANGED))
 {
  //Toast.makeText(arg0, "test", 5).show();
 currentBatteryLevel = intent.getIntExtra("level" , 0);  
  scale = intent.getIntExtra("scale", 100);
    health = intent.getIntExtra("health" , 0);
  plug = intent.getIntExtra("plugged", 0);
    status = intent.getIntExtra("status", 0);
    temperature = intent.getIntExtra("temperature", 0);
    voltage = intent.getIntExtra("voltage", 0);
    technology = intent.getIntExtra("technology", 0);
 }  
}
 
Example 11
Project: android-instant-apps   File: MainActivity.java   View Source Code Vote up 7 votes
@Override
public void onActivityReenter(int resultCode, Intent data) {
    postponeEnterTransition();
    // Start the postponed transition when the recycler view is ready to be drawn.
    grid.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            grid.getViewTreeObserver().removeOnPreDrawListener(this);
            startPostponedEnterTransition();
            return true;
        }
    });

    if (data == null) {
        return;
    }

    final int selectedItem = data.getIntExtra(IntentUtil.SELECTED_ITEM_POSITION, 0);
    grid.scrollToPosition(selectedItem);

    PhotoViewHolder holder = (PhotoViewHolder) grid.
            findViewHolderForAdapterPosition(selectedItem);
    if (holder == null) {
        Log.w(TAG, "onActivityReenter: Holder is null, remapping cancelled.");
        return;
    }

    DetailSharedElementEnterCallback callback =
            new DetailSharedElementEnterCallback(getIntent());
    callback.setView(holder.itemView);
    setExitSharedElementCallback(callback);

}
 
Example 12
Project: LuaViewPlayground   File: InactivityTimer.java   View Source Code Vote up 7 votes
@Override
public void onReceive(Context context, Intent intent) {
    if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
        // 0 indicates that we're on battery
        boolean onBatteryNow = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) <= 0;
        if (onBatteryNow) {
            InactivityTimer.this.onActivity();
        } else {
            InactivityTimer.this.cancel();
        }
    }
}
 
Example 13
Project: OpenLive-Android   File: LiveRoomActivity.java   View Source Code Vote up 7 votes
@Override
protected void initUIandEvent() {
    event().addEventHandler(this);

    Intent i = getIntent();
    int cRole = i.getIntExtra(ConstantApp.ACTION_KEY_CROLE, 0);

    if (cRole == 0) {
        throw new RuntimeException("Should not reach here");
    }

    String roomName = i.getStringExtra(ConstantApp.ACTION_KEY_ROOM_NAME);

    doConfigEngine(cRole);

    mGridVideoViewContainer = (GridVideoViewContainer) findViewById(R.id.grid_video_view_container);
    mGridVideoViewContainer.setItemEventHandler(new VideoViewEventListener() {
        @Override
        public void onItemDoubleClick(View v, Object item) {
            log.debug("onItemDoubleClick " + v + " " + item);

            if (mUidsList.size() < 2) {
                return;
            }

            if (mViewType == VIEW_TYPE_DEFAULT)
                switchToSmallVideoView(((VideoStatusData) item).mUid);
            else
                switchToDefaultVideoView();
        }
    });

    ImageView button1 = (ImageView) findViewById(R.id.btn_1);
    ImageView button2 = (ImageView) findViewById(R.id.btn_2);
    ImageView button3 = (ImageView) findViewById(R.id.btn_3);

    if (isBroadcaster(cRole)) {
        SurfaceView surfaceV = RtcEngine.CreateRendererView(getApplicationContext());
        rtcEngine().setupLocalVideo(new VideoCanvas(surfaceV, VideoCanvas.RENDER_MODE_HIDDEN, 0));
        surfaceV.setZOrderOnTop(true);
        surfaceV.setZOrderMediaOverlay(true);

        mUidsList.put(0, surfaceV); // get first surface view

        mGridVideoViewContainer.initViewContainer(getApplicationContext(), 0, mUidsList); // first is now full view
        worker().preview(true, surfaceV, 0);
        broadcasterUI(button1, button2, button3);
    } else {
        audienceUI(button1, button2, button3);
    }

    worker().joinChannel(roomName, config().mUid);

    TextView textRoomName = (TextView) findViewById(R.id.room_name);
    textRoomName.setText(roomName);
}
 
Example 14
Project: Andela-ALC-Challenge   File: HttpService.java   View Source Code Vote up 7 votes
@Override
protected void onHandleIntent(Intent intent) {

    userDataSource = new UserDataSource(getApplicationContext());
    userItems = new ArrayList<>();

    profileDataSource = new ProfileDataSource(this);
    profileItem = new ProfileItem();

    if (intent != null) {
        int intentType = intent.getIntExtra("intent_type", 0);
        switch (intentType) {

            case httpIntentLoadUsers: {
                loadGithubUsers();
            }
            break;

            case httpIntentLoadProfile: {
                profileUrl = intent.getStringExtra("profile_url");
                loadGithubProfile();
            }
            break;

        }
    }
}
 
Example 15
Project: iSPY   File: TrackerService.java   View Source Code Vote up 7 votes
private float getBatteryLevel() {
    Intent batteryStatus = registerReceiver(null,
            new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    int batteryLevel = -1;
    int batteryScale = 1;
    if (batteryStatus != null) {
        batteryLevel = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, batteryLevel);
        batteryScale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, batteryScale);
    }
    return batteryLevel / (float) batteryScale * 100;
}
 
Example 16
Project: MyFlightbookAndroid   File: ActNewAircraft.java   View Source Code Vote up 7 votes
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == SELECT_IMAGE_ACTIVITY_REQUEST_CODE)
            AddGalleryImage(data);
        else if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
            AddCameraImage(m_TempFilePath, false);
        else if (requestCode == SELECT_MAKE_ACTIVITY_REQUEST_CODE) {
            int selectedMakeIndex = data.getIntExtra(MODELFORAIRCRAFT, 0);
            if (AvailableMakesAndModels != null && AvailableMakesAndModels.length > selectedMakeIndex)
                setCurrentMakeModel(AvailableMakesAndModels[selectedMakeIndex]);
        }
    }
    if (requestCode == BEGIN_NEW_AIRCRAFT_REQUEST_CODE)
        newAircraft();
}
 
Example 17
Project: Xndroid   File: XndroidReceiver.java   View Source Code Vote up 7 votes
private void handleBattery(Intent intent){
    int level=intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);
    int scale=intent.getIntExtra(BatteryManager.EXTRA_SCALE,0);
    int levelPercent = (int)(((float)level / scale) * 100);
    boolean charging = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
            BatteryManager.BATTERY_STATUS_UNKNOWN) == BatteryManager.BATTERY_STATUS_CHARGING;
    if(levelPercent < BATTERY_LOW_LIMIT && !charging)
        AppModel.sDevBatteryLow = true;
    else
        AppModel.sDevBatteryLow = false;
    LogUtils.i("battery:" + level +"%, BatteryLow=" + AppModel.sDevBatteryLow);
}
 
Example 18
Project: q-mail   File: SleepService.java   View Source Code Vote up 7 votes
@Override
public int startService(Intent intent, int startId) {
    startForeground(FOREGROUND_SERVICE_NOTIFICATION_ID,
            new NotificationCompat.Builder(this).setContentTitle("Sleeping").build());
    try {
      if (intent.getAction().startsWith(ALARM_FIRED)) {
          Integer id = intent.getIntExtra(LATCH_ID, -1);
          endSleep(id);
      }
      return START_NOT_STICKY;
    }
    finally {
      stopSelf(startId);
    }
}
 
Example 19
Project: MyFire   File: InactivityTimer.java   View Source Code Vote up 7 votes
@Override
public void onReceive(Context context, Intent intent) {
	if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
		// 0 indicates that we're on battery
		boolean onBatteryNow = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) <= 0;
		if (onBatteryNow) {
			InactivityTimer.this.onActivity();
		} else {
			InactivityTimer.this.cancel();
		}
	}
}
 
Example 20
Project: decoy   File: CrashSnapshot.java   View Source Code Vote up 7 votes
/**
 * 获取手机剩余电量
 * 
 * @return
 */
private static String battery() {
	IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
	Intent intent = NimUIKit.getContext().registerReceiver(null, filter);
	int level = intent.getIntExtra("level", -1);
	int scale = intent.getIntExtra("scale", -1);
	if(scale == -1) {
		return "--";
	} else {
		return String.format(Locale.US, "%d %%", (level*100) / scale);
	}
}