Code example for Intent

Methods: getAction, getLongExtra

0
		final ConfirmNotifications request = new ConfirmNotifications(packageName, startId, notifyIds);
		runRequestOrQueue(request);
	} 
 
	private Action getActionFromIntent(Intent intent) {
		final String actionString = intent.getAction();
		if (actionString == null) {
			return null; 
		} 
		final String[] split = actionString.split("\\.");
		if (split.length <= 0) {
			return null; 
		} 
		return Action.valueOf(split[split.length - 1]);
	} 
 
	private void getPurchaseInformation(Intent intent, int startId) {
		final String packageName = getPackageName();
		final long nonce = intent.getLongExtra(EXTRA_NONCE, 0);
		final String[] notifyIds = intent.getStringArrayExtra(EXTRA_NOTIFY_IDS);
		final GetPurchaseInformation request = new GetPurchaseInformation(packageName, startId, notifyIds);
		request.setNonce(nonce);
		runRequestOrQueue(request);
	} 
 
	@Override 
	public IBinder onBind(Intent intent) {
		return null; 
	} 
 
	public void onServiceConnected(ComponentName name, IBinder service) {
		mService = IMarketBillingService.Stub.asInterface(service);
		runPendingRequests(); 
	} 
 
	public void onServiceDisconnected(ComponentName name) {
		mService = null;
	} 
 
	// This is the old onStart method that will be called on the pre-2.0 
	// platform.  On 2.0 or later we override onStartCommand() so this 
	// method will not be called. 
	@Override 
	public void onStart(Intent intent, int startId) {
	    handleCommand(intent, startId);
	} 
 
	// @Override // Avoid compile errors on pre-2.0 
	public int onStartCommand(Intent intent, int flags, int startId) {
	    handleCommand(intent, startId);
	    return Compatibility.START_NOT_STICKY; 
	} 
	 
	private void handleCommand(Intent intent, int startId) {
		final Action action = getActionFromIntent(intent);
		if (action == null) {
			return; 
		} 
		switch (action) {			
		case CHECK_BILLING_SUPPORTED:
			checkBillingSupported(startId);
			break; 
		case CHECK_SUBSCRIPTION_SUPPORTED:
			checkSubscriptionSupported(startId);
			break; 
		case REQUEST_PURCHASE:
			requestPurchase(intent, startId);
			break; 
		case REQUEST_SUBSCRIPTION:
			requestSubscription(intent, startId);
			break; 
		case GET_PURCHASE_INFORMATION:
			getPurchaseInformation(intent, startId);
			break; 
		case CONFIRM_NOTIFICATIONS:
			confirmNotifications(intent, startId);
			break; 
		case RESTORE_TRANSACTIONS:
			restoreTransactions(intent, startId);
		} 
	} 
 
	private void requestPurchase(Intent intent, int startId) {
		final String packageName = getPackageName();
		final String itemId = intent.getStringExtra(EXTRA_ITEM_ID);
		final String developerPayload = intent.getStringExtra(EXTRA_DEVELOPER_PAYLOAD);
		final RequestPurchase request = new RequestPurchase(packageName, startId, itemId, developerPayload);
		runRequestOrQueue(request);
	} 
	 
	private void requestSubscription(Intent intent, int startId) {
		final String packageName = getPackageName();
		final String itemId = intent.getStringExtra(EXTRA_ITEM_ID);
		final String developerPayload = intent.getStringExtra(EXTRA_DEVELOPER_PAYLOAD);
		final RequestPurchase request = new RequestSubscription(packageName, startId, itemId, developerPayload);
		runRequestOrQueue(request);
	} 
 
	private void restoreTransactions(Intent intent, int startId) {
		final String packageName = getPackageName();
		final long nonce = intent.getLongExtra(EXTRA_NONCE, 0);
		final RestoreTransactions request = new RestoreTransactions(packageName, startId);
		request.setNonce(nonce);
		runRequestOrQueue(request);
	}