List of usage examples for android.content Intent addCategory
public @NonNull Intent addCategory(String category)
From source file:com.polyvi.xface.extension.camera.XCameraExt.java
public void getImage() { Intent intent = new Intent(); String title = GET_PICTURE;//from ww w . j a v a2s . co m if (mMediaType == PICTURE) { intent.setType("image/*"); } else if (mMediaType == VIDEO) { intent.setType("video/*"); title = GET_VIDEO; } else if (mMediaType == ALLMEDIA) { intent.setType("*/*"); title = GET_All; } intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); // ?? mExtensionContext.getSystemContext().startActivityForResult(this, Intent.createChooser(intent, new String(title)), PHOTO_REQUEST_CODE); }
From source file:com.snappy.CameraCropActivity.java
private void getImageIntents() { /*/*from w w w . j a va 2s . c om*/ * if (getIntent().hasExtra("trio")) { _trio = true; _groupId = * getIntent().getStringExtra("groupId"); _planner = * getIntent().getBooleanExtra("planner", false); } else { _trio = * false; _planner = false; _groupId = ""; } */ if (getIntent().getStringExtra("type").equals("gallery")) { //this is used to solve the selected path for android 19, kitkat o superior if (Build.VERSION.SDK_INT < 19) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); this.startActivityForResult(intent, GALLERY); } else { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); this.startActivityForResult(intent, GALLERY); } mIsCamera = false; } else { try { startCamera(); mIsCamera = true; } catch (UnsupportedOperationException ex) { ex.printStackTrace(); Toast.makeText(getBaseContext(), "UnsupportedOperationException", Toast.LENGTH_SHORT).show(); } } if (getIntent().getBooleanExtra("profile", false) == true) { mForProfile = true; } else { mForProfile = false; } if (getIntent().getBooleanExtra("createGroup", false) == true) { mForGroup = true; } else { mForGroup = false; } if (getIntent().getBooleanExtra("groupUpdate", false) == true) { mForGroupUpdate = true; } else { mForGroupUpdate = false; } }
From source file:com.facebook.react.views.webview.ReactWebViewManager.java
@Override protected WebView createViewInstance(final ThemedReactContext reactContext) { final ReactWebView webView = new ReactWebView(reactContext); /**/*from ww w.j ava 2 s . c om*/ * cookie? * 5.0???cookie,5.0?false * */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true); } webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); reactContext.getCurrentActivity().startActivity(intent); // DownloadManager.Request request = new DownloadManager.Request( // Uri.parse(url)); // // request.setMimeType(mimetype); // String cookies = CookieManager.getInstance().getCookie(url); // request.addRequestHeader("cookie", cookies); // request.addRequestHeader("User-Agent", userAgent); // request.allowScanningByMediaScanner(); //// request.setTitle() // request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! // request.setDestinationInExternalPublicDir( // Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName( // url, contentDisposition, mimetype)); // DownloadManager dm = (DownloadManager) reactContext.getCurrentActivity().getSystemService(DOWNLOAD_SERVICE); // dm.enqueue(request); // Toast.makeText(reactContext, "...", //To notify the Client that the file is being downloaded // Toast.LENGTH_LONG).show(); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage message) { if (ReactBuildConfig.DEBUG) { return super.onConsoleMessage(message); } // Ignore console logs in non debug builds. return true; } @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); } private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File imageFile = new File(storageDir, /* directory */ imageFileName + ".jpg" /* filename */ ); return imageFile; } public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { if (mFilePathCallback != null) { mFilePathCallback.onReceiveValue(null); } mFilePathCallback = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent .resolveActivity(reactContext.getCurrentActivity().getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File FLog.e(ReactConstants.TAG, "Unable to create Image File", ex); } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("*/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "?"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); reactContext.getCurrentActivity().startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); // final Intent galleryIntent = new Intent(Intent.ACTION_PICK); // galleryIntent.setType("image/*"); // final Intent chooserIntent = Intent.createChooser(galleryIntent, "Choose File"); // reactContext.getCurrentActivity().startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } @Override public void onShowCustomView(View view, CustomViewCallback callback) { if (mVideoView != null) { callback.onCustomViewHidden(); return; } // Store the view and it's callback for later, so we can dispose of them correctly mVideoView = view; mCustomViewCallback = callback; view.setBackgroundColor(Color.BLACK); getRootView().addView(view, FULLSCREEN_LAYOUT_PARAMS); webView.setVisibility(View.GONE); UiThreadUtil.runOnUiThread(new Runnable() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void run() { // If the status bar is translucent hook into the window insets calculations // and consume all the top insets so no padding will be added under the status bar. View decorView = reactContext.getCurrentActivity().getWindow().getDecorView(); decorView.setOnApplyWindowInsetsListener(null); ViewCompat.requestApplyInsets(decorView); } }); reactContext.getCurrentActivity() .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } @Override public void onHideCustomView() { if (mVideoView == null) { return; } mVideoView.setVisibility(View.GONE); getRootView().removeView(mVideoView); mVideoView = null; mCustomViewCallback.onCustomViewHidden(); webView.setVisibility(View.VISIBLE); // View decorView = reactContext.getCurrentActivity().getWindow().getDecorView(); // // Show Status Bar. // int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE; // decorView.setSystemUiVisibility(uiOptions); UiThreadUtil.runOnUiThread(new Runnable() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void run() { // If the status bar is translucent hook into the window insets calculations // and consume all the top insets so no padding will be added under the status bar. View decorView = reactContext.getCurrentActivity().getWindow().getDecorView(); // decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { // @Override // public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { // WindowInsets defaultInsets = v.onApplyWindowInsets(insets); // return defaultInsets.replaceSystemWindowInsets( // defaultInsets.getSystemWindowInsetLeft(), // 0, // defaultInsets.getSystemWindowInsetRight(), // defaultInsets.getSystemWindowInsetBottom()); // } // }); decorView.setOnApplyWindowInsetsListener(null); ViewCompat.requestApplyInsets(decorView); } }); reactContext.getCurrentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } private ViewGroup getRootView() { return ((ViewGroup) reactContext.getCurrentActivity().findViewById(android.R.id.content)); } }); reactContext.addLifecycleEventListener(webView); reactContext.addActivityEventListener(new ActivityEventListener() { @Override public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) { return; } Uri[] results = null; // Check that the response is a good one if (resultCode == Activity.RESULT_OK) { if (data == null) { // If there is not data, then we may have taken a photo if (mCameraPhotoPath != null) { results = new Uri[] { Uri.parse(mCameraPhotoPath) }; } } else { String dataString = data.getDataString(); if (dataString != null) { results = new Uri[] { Uri.parse(dataString) }; } } } if (results == null) { mFilePathCallback.onReceiveValue(new Uri[] {}); } else { mFilePathCallback.onReceiveValue(results); } mFilePathCallback = null; return; } @Override public void onNewIntent(Intent intent) { } }); mWebViewConfig.configWebView(webView); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setDisplayZoomControls(false); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setDefaultFontSize(16); webView.getSettings().setTextZoom(100); // Fixes broken full-screen modals/galleries due to body height being 0. webView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } return webView; }
From source file:android.support.v7.media.RemotePlaybackClient.java
private void performSessionAction(final Intent intent, final String sessionId, Bundle extras, final SessionActionCallback callback) { intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK); if (sessionId != null) { intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId); }// w w w. j av a 2 s . c o m if (extras != null) { intent.putExtras(extras); } logRequest(intent); mRoute.sendControlRequest(intent, new MediaRouter.ControlRequestCallback() { @Override public void onResult(Bundle data) { if (data != null) { String sessionIdResult = inferMissingResult(sessionId, data.getString(MediaControlIntent.EXTRA_SESSION_ID)); MediaSessionStatus sessionStatus = MediaSessionStatus .fromBundle(data.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS)); adoptSession(sessionIdResult); if (sessionIdResult != null) { if (DEBUG) { Log.d(TAG, "Received result from " + intent.getAction() + ": data=" + bundleToString(data) + ", sessionId=" + sessionIdResult + ", sessionStatus=" + sessionStatus); } try { callback.onResult(data, sessionIdResult, sessionStatus); } finally { if (intent.getAction().equals(MediaControlIntent.ACTION_END_SESSION) && sessionIdResult.equals(mSessionId)) { setSessionId(null); } } return; } } handleInvalidResult(intent, callback, data); } @Override public void onError(String error, Bundle data) { handleError(intent, callback, error, data); } }); }
From source file:com.givon.anhao.activity.AnhaoMainActivity.java
private void loadPhotos() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); // intent.putExtra("crop", "true"); // intent.putExtra("aspectX", 1); // intent.putExtra("aspectY", 1); // intent.putExtra("outputX", 80); // intent.putExtra("outputY", 80); intent.putExtra("return-data", true); startActivityForResult(intent, ChatActivity.REQUEST_CODE_SELECT_FILE); }
From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java
private void displayArtistInfo_bk(JSONObject j) throws JSONException { if (imageLoader == null) imageLoader = ImageLoader.getInstance(); if (!imageLoader.isInited()) imageLoader.init(config);/*from ww w . j ava 2 s .c o m*/ Log.i("musicInfo", "LinkPopUp. displayArtistInfo " + j.toString()); JSONObject j_artist_info = j.getJSONObject("artist"); tArtistName.setText(j_artist_info.getString("name")); final JSONObject urls = j_artist_info.optJSONObject("urls"); final JSONArray videos = j_artist_info.optJSONArray("video"); final JSONArray images = j_artist_info.optJSONArray("images"); final String fm_image = j.optString("fm_image"); final JSONArray available_images = new JSONArray(); ArrayList<String> image_urls = new ArrayList<String>(); if (fm_image != null) { image_urls.add(fm_image); } Log.i("musicInfo", images.toString()); if (images != null) { for (int i = 0; i < images.length(); i++) { JSONObject image = images.getJSONObject(i); int width = image.optInt("width", 0); int height = image.optInt("height", 0); String url = image.optString("url", ""); Log.i("musicInfo", i + ": " + url); if ((width * height > 10000) && (width * height < 100000) && (!url.contains("userserve-ak"))) { //if ((width>300&&width<100)&&(height>300&&height<1000)&&(!url.contains("userserve-ak"))) { image_urls.add(url); Log.i("musicInfo", "Selected: " + url); //available_images.put(image); } } int random = (int) (Math.random() * image_urls.size()); final String f_url = image_urls.get(random); //int random = (int) (Math.random() * available_images.length()); //final JSONObject fImage = available_images.length()>0?available_images.getJSONObject(random > images.length() ? 0 : random):images.getJSONObject(0); Log.i("musicInfo", "Total image#=" + available_images.length() + " Selected image#=" + random + " " + f_url); imageLoader.displayImage(f_url, ArtistImage, new ImageLoadingListener() { @Override public void onLoadingStarted(String imageUri, View view) { } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { lLinkList.removeAllViews(); //String attr = fImage.optJSONObject("license").optString("attribution"); //tAttribution.setText("Credit. " + ((attr == null) || (attr.contains("n/a")) ? "Unknown" : attr)); if (urls != null) { String[] jsonName = { "wikipedia_url", "mb_url", "lastfm_url", "official_url", "twitter_url" }; for (int i = 0; i < jsonName.length; i++) { if ((urls.optString(jsonName[i]) != null) && (urls.optString(jsonName[i]) != "")) { Log.d("musicinfo", "Link URL: " + urls.optString(jsonName[i])); TextView tv = new TextView(getApplicationContext()); tv.setTextSize(11); tv.setPadding(16, 16, 16, 16); tv.setTextColor(Color.LTGRAY); tv.setTypeface(Typeface.SANS_SERIF); tv.setGravity(Gravity.CENTER_VERTICAL); tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); switch (jsonName[i]) { case "official_url": tv.setText("HOME."); break; case "wikipedia_url": tv.setText("WIKI."); break; case "mb_url": tv.setText("Music Brainz."); break; case "lastfm_url": tv.setText("Last FM."); break; case "twitter_url": tv.setText("Twitter."); break; } try { tv.setTag(urls.getString(jsonName[i])); } catch (JSONException e) { e.printStackTrace(); } tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setData(Uri.parse((String) v.getTag())); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); Toast.makeText(getApplicationContext(), "Open the Link...", Toast.LENGTH_SHORT).show(); //finish(); } }); lLinkList.addView(tv); } } } else { TextView tv = new TextView(getApplicationContext()); tv.setTextSize(11); tv.setPadding(16, 16, 16, 16); tv.setTextColor(Color.LTGRAY); tv.setTypeface(Typeface.SANS_SERIF); tv.setGravity(Gravity.CENTER_VERTICAL); tv.setText("Sorry, No Link Here..."); lLinkList.addView(tv); } if (videos != null) { jVideoArray = videos; mAdapter = new StaggeredViewAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, generateImageData(videos)); //if (mData == null) { mData = generateImageData(videos); //} //mAdapter.clear(); for (JSONObject data : mData) { mAdapter.add(data); } mGridView.setAdapter(mAdapter); } else { } adjBottomColor(((ImageView) view).getDrawable()); } @Override public void onLoadingCancelled(String imageUri, View view) { } }); } }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
private Intent buildIntent(String action, String uri, String type, JSONObject extras, String packagename, String classname, JSONArray categories) throws JSONException { Intent intent = new Intent(action); intent.setDataAndType(uri != null ? Uri.parse(uri) : null, type); if (packagename != null && classname != null) { intent.setComponent(new ComponentName(packagename, classname)); }/*from w w w . java 2 s . c o m*/ if (extras != null) { putExtrasFromJsonObject(extras, intent); } if (categories != null) { for (int i = 0; i < categories.length(); i++) { intent.addCategory(categories.getString(i)); } } return intent; }
From source file:android.support.v7.media.RemotePlaybackClient.java
private void performItemAction(final Intent intent, final String sessionId, final String itemId, Bundle extras, final ItemActionCallback callback) { intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK); if (sessionId != null) { intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId); }// www . j a v a 2s . co m if (itemId != null) { intent.putExtra(MediaControlIntent.EXTRA_ITEM_ID, itemId); } if (extras != null) { intent.putExtras(extras); } logRequest(intent); mRoute.sendControlRequest(intent, new MediaRouter.ControlRequestCallback() { @Override public void onResult(Bundle data) { if (data != null) { String sessionIdResult = inferMissingResult(sessionId, data.getString(MediaControlIntent.EXTRA_SESSION_ID)); MediaSessionStatus sessionStatus = MediaSessionStatus .fromBundle(data.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS)); String itemIdResult = inferMissingResult(itemId, data.getString(MediaControlIntent.EXTRA_ITEM_ID)); MediaItemStatus itemStatus = MediaItemStatus .fromBundle(data.getBundle(MediaControlIntent.EXTRA_ITEM_STATUS)); adoptSession(sessionIdResult); if (sessionIdResult != null && itemIdResult != null && itemStatus != null) { if (DEBUG) { Log.d(TAG, "Received result from " + intent.getAction() + ": data=" + bundleToString(data) + ", sessionId=" + sessionIdResult + ", sessionStatus=" + sessionStatus + ", itemId=" + itemIdResult + ", itemStatus=" + itemStatus); } callback.onResult(data, sessionIdResult, sessionStatus, itemIdResult, itemStatus); return; } } handleInvalidResult(intent, callback, data); } @Override public void onError(String error, Bundle data) { handleError(intent, callback, error, data); } }); }
From source file:com.rainmakerlabs.bleepsample.BleepService.java
private void localNotification(String title, String message, Intent notificationIntent, String failMsg, int notifyId) { if (!testIntent(notificationIntent)) { //if (!BleepActivity.isTesting) // return; notificationIntent = null;/* ww w .ja v a 2 s.co m*/ if (!failMsg.equalsIgnoreCase("")) message = failMsg; } if (notificationIntent == null) { notificationIntent = new Intent(this, BleepActivity.rootClass); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (message == null || message.equalsIgnoreCase("")) return; if (title == null || title.equalsIgnoreCase("")) title = getString(R.string.app_name); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setTicker(message).setWhen(System.currentTimeMillis()) .setAutoCancel(true).setContentTitle(title).setContentText(message).setContentIntent(contentIntent) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(notifyId, builder.build()); }
From source file:com.givon.anhao.activity.AnhaoMainActivity.java
/** * //from w ww. jav a 2 s . c o m */ private void selectFileFromLocal() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent, ChatActivity.REQUEST_CODE_SELECT_FILE); }