Java Code Examples for android.content.Intent#getExtras()

The following examples show how to use android.content.Intent#getExtras() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void onReceive(Context context, Intent intent) {
  Log.i(TAG, "SmsRetrieverReceiver received a broadcast...");

  if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
    Bundle extras = intent.getExtras();
    Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);

    switch (status.getStatusCode()) {
      case CommonStatusCodes.SUCCESS:
        Optional<String> code = VerificationCodeParser.parse(context, (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE));
        if (code.isPresent()) {
          Log.i(TAG, "Received verification code.");
          handleVerificationCodeReceived(code.get());
        } else {
          Log.w(TAG, "Could not parse verification code.");
        }
        break;
      case CommonStatusCodes.TIMEOUT:
        Log.w(TAG, "Hit a timeout waiting for the SMS to arrive.");
        break;
    }
  } else {
    Log.w(TAG, "SmsRetrieverReceiver received the wrong action?");
  }
}
 
Example 2
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.plan_management);

    Intent intent = getIntent();
    final Bundle bundle = intent.getExtras();
    Fragment planCreateFragment = new PlanCreateFragment();
    planCreateFragment.setArguments(bundle);

    getFragmentManager()
            .beginTransaction()
            .add(R.id.plan_container, planCreateFragment)
            .commit();

    planMenuFragment = new PlanMenuFragment();

    getFragmentManager()
            .beginTransaction()
            .add(R.id.plan_menu, planMenuFragment)
            .commit();

    getFragmentManager().addOnBackStackChangedListener(new OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {

            setDefaultPropertiesForAllButtons();
            if (getFragmentManager().getBackStackEntryCount() == 0) {
                planMenuFragment.getView().findViewById(R.id.id_navigation_plan_name).setEnabled(true);
            } else {
                Fragment fragment = getFragmentManager().findFragmentById(R.id.plan_container);
                Integer typeId = (Integer) fragment.getArguments()
                        .get(ActivityProperties.TYPE_ID);
                TaskType type = TaskType.getTaskType(typeId);
                planMenuFragment.getView().findViewById(type.getNavigationButtonId()).setEnabled(true);
            }
        }
    });
}
 
Example 3
protected void searchWebFor(String... keys) {
    StringBuilder stringBuilder = new StringBuilder();
    for (String key : keys) {
        stringBuilder.append(key);
        stringBuilder.append(" ");
    }
    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
    intent.putExtra(SearchManager.QUERY, stringBuilder.toString());
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Start search intent if possible: https://stackoverflow.com/questions/36592450/unexpected-intent-with-action-web-search
    if (Intent.ACTION_WEB_SEARCH.equals(intent.getAction()) && intent.getExtras() != null) {
        String query = intent.getExtras().getString(SearchManager.QUERY, null);
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/search?q="+query));
        boolean browserExists = intent.resolveActivityInfo(getPackageManager(), 0) != null;
        if (browserExists && query != null) {
            startActivity(browserIntent);
            return;
        }
    }

    Toast.makeText(this, R.string.error_no_app_for_intent, Toast.LENGTH_LONG).show();
}
 
Example 4
Source Project: Slide   File: OpenContent.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onNewIntent(Intent intent){
    super.onNewIntent(intent);
    Uri data = intent.getData();
    Bundle extras = intent.getExtras();
    String url;

    if (data != null) {
        url = data.toString();
    } else if (extras != null) {
        url = extras.getString(EXTRA_URL, "");
    } else {
        Toast.makeText(OpenContent.this, R.string.err_invalid_url, Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    url = url.toLowerCase(Locale.ENGLISH);

    Log.v(LogUtil.getTag(), url);


    new OpenRedditLink(this, url);
}
 
Example 5
Source Project: NotificationBox   File: DetailActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_applist);

    DetailFragment detailFragment = (DetailFragment) getSupportFragmentManager()
            .findFragmentById(R.id.fragment_applist);

    if (detailFragment == null) {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        detailFragment = DetailFragment.newInstance(bundle.getString("appName"), bundle.getString("packageName"));

        getSupportFragmentManager().beginTransaction()
                .add(R.id.content, detailFragment)
                .commit();
    }

    new DetailPresenter(detailFragment);
}
 
Example 6
Source Project: letv   File: AlbumPlayActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void initWithIntent(Intent intent) {
    if (intent != null && intent.getExtras() != null) {
        this.mPlayAdController.initState();
        this.mGestureController.setIsPanorama(this.mIsPanoramaVideo);
        this.mGestureController.setIsVr(this.mIsVR);
        this.mGestureController.setGestureUseful(!this.mIsVR);
        this.mVideoController.initFullState();
        this.mController.openSensor();
        if (isForceFull() && !this.mIsPlayingNonCopyright) {
            this.mController.fullLock();
        } else if (this.mIsPlayingNonCopyright && TextUtils.equals(this.mNonCopyrightUrl, "-1")) {
            this.mController.fullLock();
        }
        if (this.mIsDolbyVideo || this.mIsPanoramaVideo) {
            this.mTopController.setVisibilityForSwitchView(8);
        }
        initFloatBall();
    }
}
 
Example 7
Source Project: Abelana-Android   File: AccessToken.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new AccessToken using the information contained in an Intent populated by the Facebook
 * application in order to launch a native link. For more information on native linking, please see
 * https://developers.facebook.com/docs/mobile/android/deep_linking/.
 *
 * @param intent the Intent that was used to start an Activity; must not be null
 * @return a new AccessToken, or null if the Intent did not contain enough data to create one
 */
public static AccessToken createFromNativeLinkingIntent(Intent intent) {
    Validate.notNull(intent, "intent");

    if (intent.getExtras() == null) {
        return null;
    }

    return createFromBundle(null, intent.getExtras(), AccessTokenSource.FACEBOOK_APPLICATION_WEB, new Date());
}
 
Example 8
/**
 * Root and privileged methods create two identical intents upon installation on some devices
 * So to prevent double work on them and double event records, we need to filter them
 *
 */
static private long getIntentHash(Intent i) {
    StringBuilder sb = new StringBuilder();
    sb.append(i.getAction()).append("|").append(i.getDataString()).append("|");
    if (null != i.getExtras() && !i.getExtras().isEmpty()) {
        for (String key: i.getExtras().keySet()) {
            sb.append(key).append("=").append(i.getExtras().get(key)).append(";");
        }
    }
    byte[] bytes = sb.toString().getBytes();
    Checksum checksum = new CRC32();
    checksum.update(bytes, 0, bytes.length);
    return checksum.getValue();
}
 
Example 9
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    //setIntent(intent);
    if (!MobiComUserPreference.getInstance(this).isLoggedIn()) {
        //user is not logged in
        Utils.printLog(this, "AL", "user is not logged in yet.");
        return;
    }

    try {
        if (ApplozicClient.getInstance(this).isServiceDisconnected()) {
            serviceDisconnectionLayout.setVisibility(View.VISIBLE);
        } else {
            if (intent.getExtras() != null) {
                BroadcastService.setContextBasedChat(intent.getExtras().getBoolean(ConversationUIService.CONTEXT_BASED_CHAT));
                if (BroadcastService.isIndividual() && intent.getExtras().getBoolean(MobiComKitConstants.QUICK_LIST)) {
                    setSearchListFragment(quickConversationFragment);
                    addFragment(this, quickConversationFragment, ConversationUIService.QUICK_CONVERSATION_FRAGMENT);
                } else {
                    conversationUIService.checkForStartNewConversation(intent);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 10
@Override
public void onReceive(Context context, Intent intent) {
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    Bundle extras = intent.getExtras();
    String messageType = gcm.getMessageType(intent);
    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            ActorSDK.sharedActor().waitForReady();
            if (extras.containsKey("seq")) {
                int seq = Integer.parseInt(extras.getString("seq"));
                int authId = Integer.parseInt(extras.getString("authId", "0"));
                Log.d(TAG, "Push received #" + seq);
                ActorSDK.sharedActor().getMessenger().onPushReceived(seq, authId);
                setResultCode(Activity.RESULT_OK);
            } else if (extras.containsKey("callId")) {
                long callId = Long.parseLong(extras.getString("callId"));
                int attempt = 0;
                if (extras.containsKey("attemptIndex")) {
                    attempt = Integer.parseInt(extras.getString("attemptIndex"));
                }
                Log.d(TAG, "Received Call #" + callId + " (" + attempt + ")");
                ActorSDK.sharedActor().getMessenger().checkCall(callId, attempt);
                setResultCode(Activity.RESULT_OK);
            }
        }
    }
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
 
Example 11
@Override
public void initParam() {
    try {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        if (null != bundle) {
            type = bundle.getInt(IntentKeyGlobal.TRANSFER_TO_CONTACT);
        }
    } catch (Exception e) {
    }
}
 
Example 12
/**
 * 保存裁剪之后的图片数据,并更改二维码样式
 *
 * @param picdata intent
 */
private void setPicToView(Intent picdata) {
    Bundle extras = picdata.getExtras();
    Log.i(LOG_TAG, "extras.toString >> " + extras.toString());

    Bitmap qrLogoBitmap = extras.getParcelable("data");
    mQrLogoImv.setImageBitmap(qrLogoBitmap);

    if (isQRcodeGenerated) {
        generateQRcode();
    }
}
 
Example 13
@Test
public void shouldContainTheCorrectExtras()  throws Exception {
    Context context = mock(Context.class);
    Intent intent = Util.createQuery(context, "query2", "value");
    assertNotNull(intent);
    Bundle extras = intent.getExtras();
    assertNotNull(extras);

    assertEquals("query", extras.getString("QUERY"));
    assertEquals("value", extras.getString("VALUE"));
}
 
Example 14
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mobicom_multi_attachment_activity);
    String jsonString = FileUtils.loadSettingsJsonFile(getApplicationContext());
    if (!TextUtils.isEmpty(jsonString)) {
        alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
    } else {
        alCustomizationSettings = new AlCustomizationSettings();
    }
    restrictedWords = FileUtils.loadRestrictedWordsFile(this);
    choosenOption = getFilterOptions();
    fileClientService = new FileClientService(this);
    userPreferences = MobiComUserPreference.getInstance(this);
    Intent intent = getIntent();
    if (intent.getExtras() != null) {
        userID = intent.getExtras().getString(USER_ID);
        displayName = intent.getExtras().getString(DISPLAY_NAME);
        groupID = intent.getExtras().getInt(GROUP_ID, 0);
        groupName = intent.getExtras().getString(GROUP_NAME);
        imageUri = (Uri) intent.getParcelableExtra(URI_LIST);
        if (imageUri != null) {
            attachmentFileList.add(imageUri);
        }
    }
    initViews();
    setUpGridView();
    fileClientService = new FileClientService(this);
    if (imageUri == null) {
        Intent getContentIntent = FileUtils.createGetContentIntent(getFilterOptions(), getPackageManager());
        getContentIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
        startActivityForResult(getContentIntent, REQUEST_CODE_ATTACH_PHOTO);
    }
    connectivityReceiver = new ConnectivityReceiver();
    registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
 
Example 15
@Override
    public void onReceive(Context context, Intent intent) {
        Bundle data = intent.getExtras();
//        int message_id = Integer.parseInt(data.getString(OdooServerNotification.KEY_MESSAGE_ID));
//        ONotificationBuilder builder = new ONotificationBuilder(context,
//                message_id);
//        builder.setTitle(data.getString(OdooServerNotification.KEY_MESSAGE_AUTHOR_NAME));
//        builder.setBigText(data.getString(OdooServerNotification.KEY_MESSAGE_BODY));
//        builder.build().show();
    }
 
Example 16
Source Project: XERUNG   File: DetectSms.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    // Retrieves a map of extended data from the intent.
    final Bundle bundle = intent.getExtras();
    try {
        if (bundle != null) {
            final Object[] pdusObj = (Object[]) bundle.get("pdus");
            for (int i = 0; i < pdusObj.length; i++) {
                SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                String phoneNumber = currentMessage.getDisplayOriginatingAddress();
                String sendername = currentMessage.getOriginatingAddress();
                Log.d(TAG, "sendername is " + sendername);
                String servicecntradd = currentMessage.getServiceCenterAddress();
                Log.d(TAG, "servicecenteraddress is : " + servicecntradd);
                String senderNum = phoneNumber;
                Log.d(TAG, "Displayoriginationg address is : " + sendername);
                String message = currentMessage.getDisplayMessageBody();
                Log.d(TAG, "senderNum: " + senderNum + "; message: " + message);
                if (senderNum.equalsIgnoreCase("IM-MEDICO")||senderNum.equalsIgnoreCase("AD-MEDICO")||senderNum.equalsIgnoreCase("DM-MEDICO")||senderNum.equalsIgnoreCase("AM-MEDICO")) {
                    if (!message.isEmpty()) {
                        Pattern intsOnly = Pattern.compile("\\d{5}");
                        Matcher makeMatch = intsOnly.matcher(message);
                        makeMatch.find();
                        OTPcode = makeMatch.group();
                        Intent intentNew = new Intent();
                        intentNew.setAction("SMS_RECEIVED");
                        intentNew.putExtra("otp_code", OTPcode);
                        context.sendBroadcast(intentNew);
                        System.out.println(OTPcode);
                    }
                } else {
                    //Toast.makeText(context, "didn't identified the number", Toast.LENGTH_LONG).show();
                }
            }// end for loop
        } // bundle is null

    } catch (Exception e) {
        Log.e("SmsReceiver", "Exception smsReceiver" + e);
    }
}
 
Example 17
Source Project: cordova-social-vk   File: VKSdk.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Pass data of onActivityResult() function here
 *
 * @param resultCode result code of activity result
 * @param result     intent passed by activity
 * @param callback   activity result processing callback
 * @return If SDK parsed activity result properly, returns true. You can return from onActivityResult(). Otherwise, returns false.
 */
static boolean processActivityResult(@NonNull Context ctx, int resultCode, @Nullable Intent result,
                                     @Nullable VKCallback<VKAccessToken> callback) {
    if (resultCode != Activity.RESULT_OK || result == null) {
        //Result isn't ok, maybe user canceled
        if (callback != null) {
            callback.onError(new VKError(VKError.VK_CANCELED));
        }
        updateLoginState(ctx);
        return false;
    }

    CheckTokenResult tokenResult;
    Map<String, String> tokenParams = null;
    if (result.hasExtra(VKOpenAuthDialog.VK_EXTRA_TOKEN_DATA)) {
        //Token received via webview
        String tokenInfo = result.getStringExtra(VKOpenAuthDialog.VK_EXTRA_TOKEN_DATA);
        tokenParams = VKUtil.explodeQueryString(tokenInfo);
    } else if (result.getExtras() != null) {
        //Token received via VK app
        tokenParams = new HashMap<>();
        for (String key : result.getExtras().keySet()) {
            tokenParams.put(key, String.valueOf(result.getExtras().get(key)));
        }
    }

    tokenResult = checkAndSetToken(ctx, tokenParams);
    if (tokenResult.error != null && callback != null) {
        callback.onError(tokenResult.error);
    } else if (tokenResult.token != null) {
        if (tokenResult.oldToken != null) {
            VKRequest validationRequest = VKRequest.getRegisteredRequest(result.getLongExtra(VKOpenAuthDialog.VK_EXTRA_VALIDATION_REQUEST, 0));
            if (validationRequest != null) {
                validationRequest.unregisterObject();
                validationRequest.repeat();
            }
        } else {
            trackVisitor(null);
        }

        if (callback != null) {
            callback.onResult(tokenResult.token);
        }
    }
    requestedPermissions = null;
    updateLoginState(ctx);
    return true;
}
 
Example 18
@Override
public void onReceive(final Context context, final Intent intent) {
    if(!SMS_RECEIVED_ACTION.equals(intent.getAction())) return;

    Bundle pdusObj = intent.getExtras();
    final DatabaseAdapter db = new DatabaseAdapter(context);
    Set<String> smsNumbers = db.findAllSmsTemplateNumbers();
    Log.d(FTAG, "All sms numbers: " + smsNumbers);

    Object[] msgs;
    if (pdusObj != null && (msgs = (Object[]) pdusObj.get(PDUS_NAME)) != null && msgs.length > 0) {
        Log.d(FTAG, format("pdus: %s", msgs.length));

        SmsMessage msg = null;
        String addr = null;
        final StringBuilder body = new StringBuilder();

        for (final Object one : msgs) {
            msg = SmsMessage.createFromPdu((byte[]) one);
            addr = msg.getOriginatingAddress();
            if (smsNumbers.contains(addr)) {
                body.append(msg.getDisplayMessageBody());
            }
        }

        final String fullSmsBody = body.toString();
        if (!fullSmsBody.isEmpty()) {
            Log.d(FTAG, format("%s sms from %s: `%s`", msg.getTimestampMillis(), addr, fullSmsBody));

            Intent serviceIntent = new Intent(ACTION_NEW_TRANSACTION_SMS, null, context, FinancistoService.class);
            serviceIntent.putExtra(SMS_TRANSACTION_NUMBER, addr);
            serviceIntent.putExtra(SMS_TRANSACTION_BODY, fullSmsBody);
            FinancistoService.enqueueWork(context, serviceIntent);
        }
            // Display SMS message
            //                Toast.makeText(context, String.format("%s:%s", addr, body), Toast.LENGTH_SHORT).show();
    }

    // WARNING!!!
    // If you uncomment the next line then received SMS will not be put to incoming.
    // Be careful!
    // this.abortBroadcast();
}
 
Example 19
@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    context = this.getApplicationContext();
    utils = new ServerConfig();
    if (extras != null) {
        operationCode = extras.getString(INTENT_KEY_OPERATION_CODE);

        if (extras.containsKey(INTENT_KEY_APP_URI)) {
            appUri = extras.getString(INTENT_KEY_APP_URI);
        }

        if (extras.containsKey(INTENT_KEY_APP_NAME)) {
            appName = extras.getString(INTENT_KEY_APP_NAME);
        }

        if (extras.containsKey(INTENT_KEY_MESSAGE)) {
            message = extras.getString(INTENT_KEY_MESSAGE);
        }

        if (extras.containsKey(INTENT_KEY_ID)) {
            id = extras.getInt(INTENT_KEY_ID);
        }
    }

    Log.d(TAG, "App catalog has sent a command.");
    if ((operationCode != null)) {
        Log.d(TAG, "The operation code is: " + operationCode);

        Log.i(TAG, "Will now executing the command ..." + operationCode);
        boolean isRegistered = Preference.getBoolean(this.getApplicationContext(), Constants.PreferenceFlag.REGISTERED);
        if (isRegistered && Constants.CATALOG_APP_PACKAGE_NAME.equals(intent.getPackage())) {
            doTask(operationCode);
        } else if (isRegistered && Constants.SYSTEM_SERVICE_PACKAGE.equals(intent.getPackage())) {
            doTask(operationCode);
        } else if (operationCode.equals(Constants.Operation.GET_ENROLLMENT_STATUS)) {
            doTask(operationCode);
        } else {
            sendBroadcast(Constants.Status.AUTHENTICATION_FAILED, null);
        }
    }
}
 
Example 20
Source Project: quickmark   File: CustomActivity.java    License: MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	requestWindowFeature(Window.FEATURE_NO_TITLE);
	setContentView(R.layout.activity_custom);

	SysApplication.getInstance().addActivity(this); // �����ٶ��������this

	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		setTranslucentStatus(true);
		findViewById(R.id.fb_top).setVisibility(View.VISIBLE);
	}
	SystemBarTintManager mTintManager = new SystemBarTintManager(this);
	mTintManager.setStatusBarTintEnabled(true);
	mTintManager.setStatusBarTintResource(R.color.statusbar_bg);

	mContext = this;
	SharedPreferences sp = this.getSharedPreferences("preferences",
			MODE_WORLD_READABLE);
	Editor edit = sp.edit();

	initView();

	Intent intentr = getIntent();
	Bundle bundle = intentr.getExtras();// ��ȡ��������ݣ���ʹ��Bundle��¼
	if (bundle != null) {
		if (bundle.containsKey("cwp.md")) {
			String error = (String) bundle.getString("cwp.md");// ��ȡBundle�м�¼����Ϣ
			inputEdit.setText(error);
		}
	}
	mAgent = new FeedbackAgent(this);
	mComversation = new FeedbackAgent(this).getDefaultConversation();
	if (!firstfb.equals(sp.getString("firstfb", ""))) {
		mComversation.addUserReply("���ã���ӭʹ�ÿ��ټǣ��뷴��ʹ�ò�Ʒ�ĸ��ܺͽ���");
		edit.putString("firstfb", "true"); // һ��ֻ���һ��
		edit.commit();
	}
	adapter = new ReplyAdapter();
	mListView.setAdapter(adapter);
	sync();

}