Java Code Examples for android.os.bundle#isEmpty()

The following examples show how to use android.os.bundle#isEmpty() . 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
Source File: ShareWeiboWebViewClient.java    From letv with Apache License 2.0 6 votes vote down vote up
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (this.mCallBack != null) {
        this.mCallBack.shouldOverrideUrlLoadingCallBack(view, url);
    }
    if (!url.startsWith(WeiboSdkBrowser.BROWSER_CLOSE_SCHEME)) {
        return super.shouldOverrideUrlLoading(view, url);
    }
    Bundle bundle = Utility.parseUri(url);
    if (!(bundle.isEmpty() || this.mListener == null)) {
        this.mListener.onComplete(bundle);
    }
    String errCode = bundle.getString("code");
    String errMsg = bundle.getString("msg");
    if (TextUtils.isEmpty(errCode)) {
        this.mShareRequestParam.sendSdkCancleResponse(this.mAct);
    } else if ("0".equals(errCode)) {
        this.mShareRequestParam.sendSdkOkResponse(this.mAct);
    } else {
        this.mShareRequestParam.sendSdkErrorResponse(this.mAct, errMsg);
    }
    WeiboSdkBrowser.closeBrowser(this.mAct, this.mShareRequestParam.getAuthListenerKey(), null);
    return true;
}
 
Example 2
Source File: SaiyInteractionService.java    From Saiy-PS with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "onStartCommand: " + startId);
    }

    final Bundle bundle = intent.getExtras();
    if (bundle != null && !bundle.isEmpty()) {

        hotword = bundle.getString(EXTRA_VOICE_KEYPHRASE_HINT_TEXT);
        locale = UtilsLocale.stringToLocale(bundle.getString(EXTRA_VOICE_KEYPHRASE_LOCALE,
                SupportedLanguage.ENGLISH.getLanguageCountry()));

        if (DEBUG) {
            MyLog.i(CLS_NAME, "hotword: " + hotword);
            MyLog.i(CLS_NAME, "locale: " + locale.toString());
        }
    }

    return super.onStartCommand(intent, flags, startId);
}
 
Example 3
Source File: ContactListFragment.java    From PermissionsSample with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null && !savedInstanceState.isEmpty()) {
        contactList = savedInstanceState.getParcelableArrayList(MainActivity.CURRENT_CONTACT_KEY);
    }

    //Here we could use a ServiceLocator or a dependency injector to inject the depenencies.
    // I've decided not to use them since I want that this sample app is really to understand even for
    // beginners.
    ThreadExecutor threadExecutor = JobExecutor.getInstance();
    PostExecutionThread postExecutionThread = UIThread.getInstance();
    ListContactsAction listContactsAction = new ListListContactsActionImpl(this.getContext());
    ListContactsUseCase listContactsUseCase = new ListContactsUseCaseImpl(listContactsAction, threadExecutor,
            postExecutionThread);
    contactListPresenter = new ContactListPresenter(this, listContactsUseCase);
}
 
Example 4
Source File: GCMIntentService.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
	Bundle extras = intent.getExtras();
	GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

	String messageType = gcm.getMessageType(intent);

	if (!extras.isEmpty()) {
		if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
			sendNotification("Send error: " + extras.toString());
		} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
			sendNotification("Deleted messages on server: "
					+ extras.toString());
		} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

			sendNotification("Message Received from Google GCM Server: "  + extras.get(CommonUtilities.EXTRA_MESSAGE));
			Log.i(TAG, "Received: " + extras.toString());
		}
	}
	GCMBroadcastReceiver.completeWakefulIntent(intent);
}
 
Example 5
Source File: GcmIntentService.java    From Mobilyzer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
  Bundle extras = intent.getExtras();
  GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
  // The getMessageType() intent parameter must be the intent you received
  // in your BroadcastReceiver.
  String messageType = gcm.getMessageType(intent);

  if (!extras.isEmpty()) { // has effect of unparcelling Bundle
    /*
     * Filter messages based on message type. Since it is likely that GCM will be extended in the
     * future with new message types, just ignore any message types you're not interested in, or
     * that you don't recognize.
     */
    if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
      Logger.d("GCMManager -> GcmIntentService -> MESSAGE_TYPE_SEND_ERROR");
    } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
      Logger.d("GCMManager -> GcmIntentService -> MESSAGE_TYPE_DELETED");
    } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
      Logger.d("GCMManager -> MESSAGE_TYPE_MESSAGE -> " + extras.toString());
      if (extras.containsKey("task")) {
        Logger.d("GCMManager -> " + extras.getString("task"));
        
        Intent newintent = new Intent();
        newintent.setAction(UpdateIntent.GCM_MEASUREMENT_ACTION);
        newintent.putExtra(UpdateIntent.MEASUREMENT_TASK_PAYLOAD, extras.getString("task"));
        sendBroadcast(newintent);

      }
    }
  }
  // Release the wake lock provided by the WakefulBroadcastReceiver.
  GcmBroadcastReceiver.completeWakefulIntent(intent);
}
 
Example 6
Source File: BaseActivity.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (layout() != 0) {
        setContentView(layout());
        ButterKnife.bind(this);
    }
    Icepick.setDebug(BuildConfig.DEBUG);
    if (savedInstanceState != null && !savedInstanceState.isEmpty()) {
        Icepick.restoreInstanceState(this, savedInstanceState);
    }
    setupToolbarAndStatusBar();
}
 
Example 7
Source File: DecodeHintManager.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
static Map<DecodeHintType, Object> parseDecodeHints(Intent intent) {
  Bundle extras = intent.getExtras();
  if (extras == null || extras.isEmpty()) {
    return null;
  }
  Map<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);

  for (DecodeHintType hintType: DecodeHintType.values()) {

    if (hintType == DecodeHintType.CHARACTER_SET ||
        hintType == DecodeHintType.NEED_RESULT_POINT_CALLBACK ||
        hintType == DecodeHintType.POSSIBLE_FORMATS) {
      continue; // This hint is specified in another way
    }

    String hintName = hintType.name();
    if (extras.containsKey(hintName)) {
      if (hintType.getValueType().equals(Void.class)) {
        // Void hints are just flags: use the constant specified by the DecodeHintType
        hints.put(hintType, Boolean.TRUE);
      } else {
        Object hintData = extras.get(hintName);
        if (hintType.getValueType().isInstance(hintData)) {
          hints.put(hintType, hintData);
        } else {
          Log.w(TAG, "Ignoring hint " + hintType + " because it is not assignable from " + hintData);
        }
      }
    }
  }

  Log.i(TAG, "Hints from the Intent: " + hints);
  return hints;
}
 
Example 8
Source File: DecodeHintManager.java    From CodeScaner with MIT License 5 votes vote down vote up
static Map<DecodeHintType, Object> parseDecodeHints(Intent intent) {
  Bundle extras = intent.getExtras();
  if (extras == null || extras.isEmpty()) {
    return null;
  }
  Map<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);

  for (DecodeHintType hintType: DecodeHintType.values()) {

    if (hintType == DecodeHintType.CHARACTER_SET ||
        hintType == DecodeHintType.NEED_RESULT_POINT_CALLBACK ||
        hintType == DecodeHintType.POSSIBLE_FORMATS) {
      continue; // This hint is specified in another way
    }

    String hintName = hintType.name();
    if (extras.containsKey(hintName)) {
      if (hintType.getValueType().equals(Void.class)) {
        // Void hints are just flags: use the constant specified by the DecodeHintType
        hints.put(hintType, Boolean.TRUE);
      } else {
        Object hintData = extras.get(hintName);
        if (hintType.getValueType().isInstance(hintData)) {
          hints.put(hintType, hintData);
        } else {
          Log.w(TAG, "Ignoring hint " + hintType + " because it is not assignable from " + hintData);
        }
      }
    }
  }

  Log.i(TAG, "Hints from the Intent: " + hints);
  return hints;
}
 
Example 9
Source File: BaiduDialog.java    From dcs-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    LogUtil.d(LOG_TAG, "Redirect URL: " + url);
    /*
     * 如果url的地址为bdconnect://success,即使用User-Agent方式获取用户授权的redirct
     * url,则截取url中返回的各种token参数,
     * 如果出错,则通过listener的相应处理方式回调
     */
    if (url.startsWith(BaiduOauthImplicitGrant.SUCCESS_URI)) {
        Bundle values = OauthNetUtil.parseUrl(url);
        if (values != null && !values.isEmpty()) {
            String error = values.getString("error");
            // 用户取消授权返回error=access_denied
            if ("access_denied".equals(error)) {
                mListener.onCancel();
                BaiduDialog.this.dismiss();
                return true;
            }
            // 请求出错时返回error=1100&errorDesp=error_desp
            String errorDesp = values.getString("error_description");
            if (error != null && errorDesp != null) {
                mListener.onBaiduException(new BaiduException(error, errorDesp));
                BaiduDialog.this.dismiss();
                return true;
            }
            mListener.onComplete(values);
            BaiduDialog.this.dismiss();
            return true;
        }
    } else if (url.startsWith(BaiduOauthImplicitGrant.CANCEL_URI)) {
        mListener.onCancel();
        BaiduDialog.this.dismiss();
        return true;
    }
    return false;
}
 
Example 10
Source File: DecodeHintManager.java    From zxingfragmentlib with Apache License 2.0 5 votes vote down vote up
public static Map<DecodeHintType, Object> parseDecodeHints(Intent intent) {
  Bundle extras = intent.getExtras();
  if (extras == null || extras.isEmpty()) {
    return null;
  }
  Map<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);

  for (DecodeHintType hintType: DecodeHintType.values()) {

    if (hintType == DecodeHintType.CHARACTER_SET ||
        hintType == DecodeHintType.NEED_RESULT_POINT_CALLBACK ||
        hintType == DecodeHintType.POSSIBLE_FORMATS) {
      continue; // This hint is specified in another way
    }

    String hintName = hintType.name();
    if (extras.containsKey(hintName)) {
      if (hintType.getValueType().equals(Void.class)) {
        // Void hints are just flags: use the constant specified by the DecodeHintType
        hints.put(hintType, Boolean.TRUE);
      } else {
        Object hintData = extras.get(hintName);
        if (hintType.getValueType().isInstance(hintData)) {
          hints.put(hintType, hintData);
        } else {
          Log.w(TAG, "Ignoring hint " + hintType + " because it is not assignable from " + hintData);
        }
      }
    }
  }

  Log.i(TAG, "Hints from the Intent: " + hints);
  return hints;
}
 
Example 11
Source File: UserProfile.java    From kakao-android-sdk-standalone with Apache License 2.0 5 votes vote down vote up
/**
 * 캐시로 부터 사용자정보를 읽어온다.
 * @return 캐시에서 읽은 사용자정보
 */
public static UserProfile loadFromCache() {
    SharedPreferencesCache cache = Session.getAppCache();
    if(cache == null)
        return null;

    Bundle bundle = cache.load();

    final long userId = bundle.getLong(CACHE_USER_ID);
    bundle.remove(CACHE_USER_ID);
    final String nickname = bundle.getString(CACHE_NICKNAME);
    bundle.remove(CACHE_NICKNAME);
    final String thumbnailPath = bundle.getString(CACHE_THUMBNAIL_PATH);
    bundle.remove(CACHE_THUMBNAIL_PATH);
    final String profilePath = bundle.getString(CACHE_PROFILE_PATH);
    bundle.remove(CACHE_PROFILE_PATH);

    Map<String, String> properties = new HashMap<String, String>();
    if(!bundle.isEmpty()){
        for(String key : bundle.keySet()){
            if(key.startsWith(CACHE_USER_PREFIX))
                properties.put(key, bundle.getString(key));
        }
    }

    return new UserProfile(userId, nickname, thumbnailPath, profilePath, properties);
}
 
Example 12
Source File: PushReceiver.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 13
Source File: ServiceBasedSpeechRecognizer.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void onResults(Bundle bundle) {
  if (bundle.isEmpty()) {
    result = "";
  } else {
    ArrayList<String> results = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    result = results.get(0);
  }
  speechListener.onResult(result);
}
 
Example 14
Source File: GcmIntentService.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty() && GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
        try {
            JSONObject AzMsg = new JSONObject(extras.getString("message"));
            JSONObject AzServ = AzMsg.getJSONObject("service");
            PushjetService srv = new PushjetService(
                    AzServ.getString("public"),
                    AzServ.getString("name"),
                    new Date((long) AzServ.getInt("created") * 1000)
            );
            srv.setIcon(AzServ.getString("icon"));

            PushjetMessage msg = new PushjetMessage(
                    srv,
                    AzMsg.getString("message"),
                    AzMsg.getString("title"),
                    AzMsg.getInt("timestamp")
            );
            msg.setLevel(AzMsg.getInt("level"));
            msg.setLink(AzMsg.getString("link"));
            DatabaseHandler db = new DatabaseHandler(this);
            db.addMessage(msg);
            sendNotification(msg);
        } catch (JSONException ignore) {
            Log.e("PushjetJson", ignore.getMessage());
        }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
    sendBroadcast(new Intent("PushjetMessageRefresh"));
}
 
Example 15
Source File: DecodeHintManager.java    From weex with Apache License 2.0 5 votes vote down vote up
static Map<DecodeHintType, Object> parseDecodeHints(Intent intent) {
  Bundle extras = intent.getExtras();
  if (extras == null || extras.isEmpty()) {
    return null;
  }
  Map<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);

  for (DecodeHintType hintType: DecodeHintType.values()) {

    if (hintType == DecodeHintType.CHARACTER_SET ||
        hintType == DecodeHintType.NEED_RESULT_POINT_CALLBACK ||
        hintType == DecodeHintType.POSSIBLE_FORMATS) {
      continue; // This hint is specified in another way
    }

    String hintName = hintType.name();
    if (extras.containsKey(hintName)) {
      if (hintType.getValueType().equals(Void.class)) {
        // Void hints are just flags: use the constant specified by the DecodeHintType
        hints.put(hintType, Boolean.TRUE);
      } else {
        Object hintData = extras.get(hintName);
        if (hintType.getValueType().isInstance(hintData)) {
          hints.put(hintType, hintData);
        } else {
          Log.w(TAG, "Ignoring hint " + hintType + " because it is not assignable from " + hintData);
        }
      }
    }
  }

  Log.i(TAG, "Hints from the Intent: " + hints);
  return hints;
}
 
Example 16
Source File: UtilsBundle.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean notNaked(@Nullable final Bundle bundle) {
    return bundle != null && !bundle.isEmpty();
}
 
Example 17
Source File: BaseBottomSheetDialog.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Override public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null && !savedInstanceState.isEmpty()) {
        StateSaver.restoreInstanceState(this, savedInstanceState);
    }
}
 
Example 18
Source File: GcmBroadcastReceiver.java    From zulip-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    // handle cancel notification action on uploads
    final String action = intent.getAction();
    if (Constants.CANCEL.equals(action)) {
        int notifId = intent.getIntExtra("id", 0);
        try {
            ZulipApp.get().getZulipActivity().cancelRequest(notifId);
        } catch (NullPointerException e) {
            ZLog.log("onReceive: app destroyed but notification visible");
            return;
        }
    }

    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that
         * GCM will be extended in the future with new message types, just
         * ignore any message types you're not interested in, or that you
         * don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
                .equals(messageType)) {
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
                .equals(messageType)) {
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
                .equals(messageType)) {

            Log.i(TAG, "Received: " + extras.toString());
            if (extras.getString("event").equals("message")) {
                Intent broadcast = new Intent(getGCMReceiverAction(context.getApplicationContext()));
                broadcast.putExtras(extras);
                context.sendOrderedBroadcast(broadcast, null);
            }
        }
    }

    setResultCode(Activity.RESULT_OK);
}
 
Example 19
Source File: BundleUtil.java    From ZhihuDailyFluxRRD with Apache License 2.0 4 votes vote down vote up
public static Throwable getThrowable(Bundle bundle) {
    if (bundle == null || bundle.isEmpty()) {
        throw new IllegalArgumentException("the bundle is null or empty");
    }
    return (Throwable) bundle.getSerializable(BundleKey.THROWABLE);
}
 
Example 20
Source File: JobRequest.java    From android-job with Apache License 2.0 2 votes vote down vote up
/**
 * Set optional transient extras. <b>WARNING:</b> It's not guaranteed that a transient job will
 * run at all, e.g. rebooting the device or force closing the app will cancel the job. This is
 * only helpful for jobs which should start soon and can be cancelled automatically.
 *
 * <br>
 * <br>
 *
 * If the passed in bundle is {@code null} or empty, then the previous extras are reset to the default
 * and the job won't be transient.
 *
 * @param extras  Bundle containing extras you want the scheduler to hold on to for you.
 */
public Builder setTransientExtras(@Nullable Bundle extras) {
    mTransient = extras != null && !extras.isEmpty();
    mTransientExtras = mTransient ? new Bundle(extras) : Bundle.EMPTY;
    return this;
}