List of usage examples for android.os Bundle getInt
public int getInt(String key)
From source file:Main.java
/** * Get resource ID from extra or from metadata. * //from ww w .j a va 2 s. c o m * @param context * @param packagename * @param intent * @param extra * @param metadata * @return */ public static int getResourceIdExtraOrMetadata(final Context context, final String packagename, final Intent intent, final String extra, final String metadata) { if (intent.hasExtra(extra) && intent.getStringExtra(extra) != null) { int id = 0; try { String resourcename = intent.getStringExtra(extra); Resources resources = context.getPackageManager().getResourcesForApplication(packagename); Log.i(TAG, "Looking up resource Id for " + resourcename); id = resources.getIdentifier(resourcename, "", packagename); } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } return id; } else { //Try meta data of package Bundle md = null; try { md = context.getPackageManager().getApplicationInfo(packagename, PackageManager.GET_META_DATA).metaData; } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } if (md != null) { // Obtain resource ID and convert to resource name: int id = md.getInt(metadata); return id; } else { return 0; } } }
From source file:Main.java
/** * Get String array from Extra or from Meta-data through resources. * /*w w w . j a v a 2 s . c o m*/ * @param packagename * @param intent * @param extra * @param metadata */ public static String[] getStringArrayExtraOrMetadata(final Context context, final String packagename, final Intent intent, final String extra, final String metadata) { if (intent.hasExtra(extra) && intent.getStringArrayExtra(extra) != null) { return intent.getStringArrayExtra(extra); } else { //Try meta data of package Bundle md = null; try { md = context.getPackageManager().getApplicationInfo(packagename, PackageManager.GET_META_DATA).metaData; } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } if (md != null) { String[] array = null; try { int id = md.getInt(metadata); Resources resources = context.getPackageManager().getResourcesForApplication(packagename); array = resources.getStringArray(id); } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found ", e); } catch (NumberFormatException e) { Log.e(TAG, "Metadata not valid id.", e); } catch (Resources.NotFoundException e) { Log.e(TAG, "Resource not found.", e); } if (array != null) { return array; } else { return null; } } else { return null; } } }
From source file:jp.sonymusicstudio.cast.castcompanionlibrary.utils.Utils.java
/** * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by * <code>mediaInfoToBundle</code>. It is assumed that the type of the {@link MediaInfo} is * {@code MediaMetaData.MEDIA_TYPE_MOVIE} * * @see <code>mediaInfoToBundle()</code> *///from www . j av a 2 s .c om public static MediaInfo bundleToMediaInfo(Bundle wrapper) { if (wrapper == null) { return null; } MediaMetadata metaData = new MediaMetadata(wrapper.getInt(KEY_MEDIA_TYPE)); metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE)); metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE)); metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO)); metaData.putString(MediaMetadata.KEY_ALBUM_ARTIST, wrapper.getString(MediaMetadata.KEY_ALBUM_ARTIST)); metaData.putString(MediaMetadata.KEY_ALBUM_TITLE, wrapper.getString(MediaMetadata.KEY_ALBUM_TITLE)); metaData.putString(MediaMetadata.KEY_COMPOSER, wrapper.getString(MediaMetadata.KEY_COMPOSER)); metaData.putString(MediaMetadata.KEY_SERIES_TITLE, wrapper.getString(MediaMetadata.KEY_SERIES_TITLE)); metaData.putInt(MediaMetadata.KEY_SEASON_NUMBER, wrapper.getInt(MediaMetadata.KEY_SEASON_NUMBER)); metaData.putInt(MediaMetadata.KEY_EPISODE_NUMBER, wrapper.getInt(MediaMetadata.KEY_EPISODE_NUMBER)); long releaseDateMillis = wrapper.getLong(MediaMetadata.KEY_RELEASE_DATE, 0); if (releaseDateMillis > 0) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(releaseDateMillis); metaData.putDate(MediaMetadata.KEY_RELEASE_DATE, calendar); } ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES); if (images != null && !images.isEmpty()) { for (String url : images) { Uri uri = Uri.parse(url); metaData.addImage(new WebImage(uri)); } } String customDataStr = wrapper.getString(KEY_CUSTOM_DATA); JSONObject customData = null; if (!TextUtils.isEmpty(customDataStr)) { try { customData = new JSONObject(customDataStr); } catch (JSONException e) { LOGE(TAG, "Failed to deserialize the custom data string: custom data= " + customDataStr); } } List<MediaTrack> mediaTracks = null; if (wrapper.getString(KEY_TRACKS_DATA) != null) { try { JSONArray jsonArray = new JSONArray(wrapper.getString(KEY_TRACKS_DATA)); mediaTracks = new ArrayList<MediaTrack>(); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObj = (JSONObject) jsonArray.get(i); MediaTrack.Builder builder = new MediaTrack.Builder(jsonObj.getLong(KEY_TRACK_ID), jsonObj.getInt(KEY_TRACK_TYPE)); if (jsonObj.has(KEY_TRACK_NAME)) { builder.setName(jsonObj.getString(KEY_TRACK_NAME)); } if (jsonObj.has(KEY_TRACK_SUBTYPE)) { builder.setSubtype(jsonObj.getInt(KEY_TRACK_SUBTYPE)); } if (jsonObj.has(KEY_TRACK_CONTENT_ID)) { builder.setContentType(jsonObj.getString(KEY_TRACK_CONTENT_ID)); } if (jsonObj.has(KEY_TRACK_LANGUAGE)) { builder.setLanguage(jsonObj.getString(KEY_TRACK_LANGUAGE)); } if (jsonObj.has(KEY_TRACKS_DATA)) { builder.setCustomData(new JSONObject(jsonObj.getString(KEY_TRACKS_DATA))); } mediaTracks.add(builder.build()); } } } catch (JSONException e) { LOGE(TAG, "Failed to build media tracks from the wrapper bundle", e); } } MediaInfo.Builder mediaBuilder = new MediaInfo.Builder(wrapper.getString(KEY_URL)) .setStreamType(wrapper.getInt(KEY_STREAM_TYPE)).setContentType(wrapper.getString(KEY_CONTENT_TYPE)) .setMetadata(metaData).setCustomData(customData).setMediaTracks(mediaTracks); if (wrapper.containsKey(KEY_STREAM_DURATION) && wrapper.getLong(KEY_STREAM_DURATION) >= 0) { mediaBuilder.setStreamDuration(wrapper.getLong(KEY_STREAM_DURATION)); } return mediaBuilder.build(); }
From source file:org.wheelmap.android.net.AbstractExecutor.java
public static IExecutor create(Context context, Bundle bundle, IAppProperties appProperties, ICredentials credentials, IHttpUserAgent httpUserAgent) { if (bundle == null || !bundle.containsKey(Extra.WHAT)) { return null; }/*from w w w . j a va2 s . c o m*/ int what = bundle.getInt(Extra.WHAT); IExecutor executor; switch (what) { case What.RETRIEVE_NODE: executor = new NodeExecutor(context, bundle); break; case What.RETRIEVE_MARKER_ICONS: executor = new MarkerIconExecutor(context, bundle); break; case What.RETRIEVE_NODES: case What.SEARCH_NODES: case What.SEARCH_NODES_IN_BOX: executor = new NodesExecutor(context, bundle); break; case What.RETRIEVE_TOTAL_NODE_COUNT: executor = new TotalNodeCountExecutor(context, bundle); break; case What.RETRIEVE_LOCALES: executor = new LocalesExecutor(context, bundle); break; case What.RETRIEVE_CATEGORIES: executor = new CategoriesExecutor(context, bundle); break; case What.RETRIEVE_NODETYPES: executor = new NodeTypesExecutor(context, bundle); break; case What.UPDATE_SERVER: executor = new NodeUpdateOrNewExecutor(context); break; case What.RETRIEVE_APIKEY: executor = new ApiKeyExecutor(context, bundle); break; case What.RETRIEVE_PHOTO: executor = new PhotosExecutor(context, bundle); break; case What.UPDATE_PHOTO: executor = new PhotoExecutor(context, bundle); break; default: return null; // noop no instruction, no operation; } executor.setAppProperties(appProperties); executor.setCredentials(credentials); executor.setUserAgent(httpUserAgent.getAppUserAgent()); return executor; }
From source file:com.google.android.gms.common.GooglePlayServicesUtil.java
private static void m118t(Context context) { ApplicationInfo applicationInfo = null; try {/*from w ww. j a v a 2 s . co m*/ applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), TransportMediator.FLAG_KEY_MEDIA_NEXT); } catch (Throwable e) { Log.wtf("GooglePlayServicesUtil", "This should never happen.", e); } Bundle bundle = applicationInfo.metaData; if (bundle != null) { int i = bundle.getInt("com.google.android.gms.version"); if (i != GOOGLE_PLAY_SERVICES_VERSION_CODE) { throw new IllegalStateException( "The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4452000 but found " + i + ". You must have the" + " following declaration within the <application> element: " + " <meta-data android:name=\"" + "com.google.android.gms.version" + "\" android:value=\"@integer/google_play_services_version\" />"); } return; } throw new IllegalStateException( "A required meta-data tag in your app's AndroidManifest.xml does not exist. You must have the following declaration within the <application> element: <meta-data android:name=\"com.google.android.gms.version\" android:value=\"@integer/google_play_services_version\" />"); }
From source file:com.ademsha.appnotifico.NotificationDataHelper.java
@TargetApi(Build.VERSION_CODES.KITKAT) private static JSONObject getNotificationExtras(JSONObject notification, StatusBarNotification statusBarNotification) { try {/* w w w. j a v a 2 s . c o m*/ Bundle extras = statusBarNotification.getNotification().extras; if (extras != null) { notification.put("text", extras.getString(Notification.EXTRA_TEXT)); notification.put("sub_text", extras.getString(Notification.EXTRA_SUB_TEXT)); notification.put("summary_text", extras.getString(Notification.EXTRA_SUMMARY_TEXT)); notification.put("text_lines", Arrays .toString(extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES)).replace("null", "")); notification.put("icon", String.valueOf(extras.getInt(Notification.EXTRA_SMALL_ICON))); if (extras.getParcelable(Notification.EXTRA_LARGE_ICON) != null) { notification.put("large_icon", String.valueOf(extras.getParcelable(Notification.EXTRA_LARGE_ICON).toString()) .replace("null", "")); } notification.put("title", extras.getString(Notification.EXTRA_TITLE)); notification.put("title_big", extras.getString(Notification.EXTRA_TITLE_BIG)); notification.put("progress", extras.getInt(Notification.EXTRA_PROGRESS)); notification.put("progress_indeterminate", String.valueOf(extras.getBoolean(Notification.EXTRA_PROGRESS_INDETERMINATE))); notification.put("progress_max", String.valueOf(extras.getInt(Notification.EXTRA_PROGRESS_MAX))); notification.put("people", extras.getStringArray(Notification.EXTRA_PEOPLE)); } } catch (JSONException e) { e.printStackTrace(); } return notification; }
From source file:com.chess.genesis.data.GameParser.java
public static Bundle parse(final JSONObject data) { final Bundle game = new Bundle(); try {//from w w w. jav a 2 s . c om game.putInt("gametype", Enums.GameType(data.optString("gametype", "genesis"))); } catch (final RuntimeException e) { game.putInt("gametype", Enums.GENESIS_CHESS); } try { game.putInt("opponent", Enums.OpponentType(data.optString("opponent", "human"))); } catch (final RuntimeException e) { game.putInt("opponent", Enums.HUMAN_OPPONENT); } game.putString("name", data.optString("name", "untitled")); game.putLong("ctime", data.optLong("ctime", System.currentTimeMillis())); game.putLong("stime", data.optLong("stime", System.currentTimeMillis())); final GamePosition pos = parsePosition(data.optString("history", " "), game.getInt("gametype")); game.putString("history", pos.history); game.putString("zfen", pos.zfen); return game; }
From source file:com.example.kyle.weatherforecast.WeatherFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_layout, container, false); Bundle args = getArguments(); int i = args.getInt("day"); TextView textOutlook = ((TextView) rootView.findViewById(R.id.text_outlook)); ImageView symbolView = ((ImageView) rootView.findViewById(R.id.image_symbol)); TextView tempsView = ((TextView) rootView.findViewById(R.id.text_temp)); TextView windView = ((TextView) rootView.findViewById(R.id.text_min)); TextView realFeelView = ((TextView) rootView.findViewById(R.id.text_real_feel)); textOutlook.setText(WeatherData.outlookArray[i]); symbolView.setImageResource(WeatherData.symbolArray[i]); tempsView.setText(WeatherData.tempsArray[i] + "c"); windView.setText(("Min " + WeatherData.minArray[i] + "c")); realFeelView.setText("Real feel " + WeatherData.realFeelArray[i] + "c"); return rootView; }
From source file:android.example.com.tabcompat.lib.TabHelperHoneycomb.java
@Override protected void onRestoreInstanceState(Bundle savedInstanceState) { int position = savedInstanceState.getInt("tab_position"); mActionBar.setSelectedNavigationItem(position); }
From source file:com.amazon.aws.demo.anonymous.sqs.SqsMessageBody.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.item_view);//from w w w . j av a 2 s. c o m Bundle extras = this.getIntent().getExtras(); messageIndex = extras.getInt(SimpleQueue.MESSAGE_INDEX); messageId = extras.getString(SimpleQueue.MESSAGE_ID); loadingText = (TextView) findViewById(R.id.item_view_loading_text); bodyText = (TextView) findViewById(R.id.item_view_body_text); updateUi(); }