當前位置: 首頁>>代碼示例>>Java>>正文


Java Intent.getCharSequenceArrayExtra方法代碼示例

本文整理匯總了Java中android.content.Intent.getCharSequenceArrayExtra方法的典型用法代碼示例。如果您正苦於以下問題:Java Intent.getCharSequenceArrayExtra方法的具體用法?Java Intent.getCharSequenceArrayExtra怎麽用?Java Intent.getCharSequenceArrayExtra使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.Intent的用法示例。


在下文中一共展示了Intent.getCharSequenceArrayExtra方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getValue

import android.content.Intent; //導入方法依賴的package包/類
/**
 * Get a value from an intent by a giving class and key.
 * @param intent
 *  the source intent
 * @param key
 *  the key of the value
 * @param clz
 *  the class of the value
 * @return
 *  the value from the source intent
 */
public static Object getValue(Intent intent, String key, Class<?> clz) {
    Object value = null;
    // Cause it is not an easy job to handle inheritance in apt, it is a lot easier to put the code in the Android environment.
    if(Bundle.class.isAssignableFrom(clz)) {
        // bundle implements parcelable, so it should place before parcelable.
        value = intent.getBundleExtra(key);
    } else if(Parcelable.class.isAssignableFrom(clz)) {
        value = intent.getParcelableExtra(key);
    } else if(Parcelable[].class.isAssignableFrom(clz)) {
        value = intent.getParcelableArrayExtra(key);
    } else if(boolean[].class.isAssignableFrom(clz)) {
        value = intent.getBooleanArrayExtra(key);
    } else if(byte[].class.isAssignableFrom(clz)) {
        value = intent.getByteArrayExtra(key);
    } else if(short[].class.isAssignableFrom(clz)) {
        value = intent.getShortArrayExtra(key);
    } else if(char[].class.isAssignableFrom(clz)) {
        value = intent.getCharArrayExtra(key);
    } else if(int[].class.isAssignableFrom(clz)) {
        value = intent.getIntArrayExtra(key);
    } else if(long[].class.isAssignableFrom(clz)) {
        value = intent.getLongArrayExtra(key);
    } else if(float[].class.isAssignableFrom(clz)) {
        value = intent.getFloatArrayExtra(key);
    } else if(double[].class.isAssignableFrom(clz)) {
        value = intent.getDoubleArrayExtra(key);
    } else if(String[].class.isAssignableFrom(clz)) {
        value = intent.getStringArrayExtra(key);
    } else if(CharSequence[].class.isAssignableFrom(clz)) {
        value = intent.getCharSequenceArrayExtra(key);
    } else if(Serializable.class.isAssignableFrom(clz)) {
        // some of the above are assignable for serializable, so serializable should be in the last place.
        value = intent.getSerializableExtra(key);
    } else {
        throw new RuntimeException(clz + " is not compatible with intent (key=" + key + ")");
    }

    return value;
}
 
開發者ID:foreveruseful,項目名稱:smartkey,代碼行數:51,代碼來源:IntentValueGetter.java

示例2: onReceive

import android.content.Intent; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (TextUtils.isEmpty(action)) {
        return;
    }

    if (!action.equals(LOCAL_ACTION_STATUS)) {
        return;
    }

    final String message = intent.getStringExtra(EXTRA_MESSAGE);
    int resultCode = intent.getIntExtra(EXTRA_STATUS_CODE, -1);
    int progress = intent.getIntExtra(EXTRA_PROGRESS, -1);

    String text;
    switch (resultCode) {
        case STATUS_INFO:
            notificationBuilder.setContentText(message)
                .setCategory(NotificationCompat.CATEGORY_SERVICE);
            if (progress != -1) {
                notificationBuilder.setProgress(100, progress, false);
            } else {
                notificationBuilder.setProgress(100, 0, true);
            }
            notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
            break;
        case STATUS_ERROR_GLOBAL:
            text = context.getString(R.string.global_error_updating_repos, message);
            notificationBuilder.setContentText(text)
                .setCategory(NotificationCompat.CATEGORY_ERROR)
                .setSmallIcon(android.R.drawable.ic_dialog_alert);
            notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
            Toast.makeText(context, text, Toast.LENGTH_LONG).show();
            break;
        case STATUS_ERROR_LOCAL:
        case STATUS_ERROR_LOCAL_SMALL:
            StringBuilder msgBuilder = new StringBuilder();
            CharSequence[] repoErrors = intent.getCharSequenceArrayExtra(EXTRA_REPO_ERRORS);
            for (CharSequence error : repoErrors) {
                if (msgBuilder.length() > 0) msgBuilder.append('\n');
                msgBuilder.append(error);
            }
            if (resultCode == STATUS_ERROR_LOCAL_SMALL) {
                msgBuilder.append('\n').append(context.getString(R.string.all_other_repos_fine));
            }
            text = msgBuilder.toString();
            notificationBuilder.setContentText(text)
                .setCategory(NotificationCompat.CATEGORY_ERROR)
                .setSmallIcon(android.R.drawable.ic_dialog_info);
            notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
            Toast.makeText(context, text, Toast.LENGTH_LONG).show();
            break;
        case STATUS_COMPLETE_WITH_CHANGES:
            break;
        case STATUS_COMPLETE_AND_SAME:
            text = context.getString(R.string.repos_unchanged);
            notificationBuilder.setContentText(text)
                .setCategory(NotificationCompat.CATEGORY_SERVICE);
            notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
            break;
    }
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:64,代碼來源:UpdateService.java


注:本文中的android.content.Intent.getCharSequenceArrayExtra方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。