List of usage examples for android.content Intent getFlags
public @Flags int getFlags()
From source file:Main.java
private static boolean isContainFlag(Intent intent, int flag) { return (intent.getFlags() & flag) != 0; }
From source file:Main.java
private static void removeFlag(Intent intent, int flag) { intent.setFlags(intent.getFlags() & ~flag); }
From source file:com.frostwire.android.StoragePicker.java
public static String handle(Context context, int requestCode, int resultCode, Intent data) { String result = null;/*from ww w .j ava2 s. c o m*/ try { if (resultCode == Activity.RESULT_OK && requestCode == SELECT_FOLDER_REQUEST_CODE) { Uri treeUri = data.getData(); ContentResolver cr = context.getContentResolver(); final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cr.takePersistableUriPermission(treeUri, takeFlags); if (treeUri == null) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_null); result = null; } else { DocumentFile file = DocumentFile.fromTreeUri(context, treeUri); if (!file.isDirectory()) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_not_directory); result = null; } else if (!file.canWrite()) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_cant_write); result = null; } else { LollipopFileSystem fs = (LollipopFileSystem) Platforms.fileSystem(); result = fs.getTreePath(treeUri); if (result != null && !result.endsWith("/FrostWire")) { DocumentFile f = file.findFile("FrostWire"); if (f == null) { file.createDirectory("FrostWire"); } } } } } } catch (Throwable e) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_error); LOG.error("Error handling folder selection", e); result = null; } if (result != null) { ConfigurationManager.instance().setStoragePath(result); BTEngine.ctx.dataDir = Platforms.data(); BTEngine.ctx.torrentsDir = Platforms.torrents(); } return result; }
From source file:org.dkf.jmule.StoragePicker.java
public static String handle(Context context, int requestCode, int resultCode, Intent data) { String result = null;/*from w ww . ja v a 2s . com*/ try { if (resultCode == Activity.RESULT_OK && requestCode == SELECT_FOLDER_REQUEST_CODE) { Uri treeUri = data.getData(); ContentResolver cr = context.getContentResolver(); Method takePersistableUriPermissionM = cr.getClass().getMethod("takePersistableUriPermission", Uri.class, int.class); final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takePersistableUriPermissionM.invoke(cr, treeUri, takeFlags); if (treeUri == null) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_null); result = null; } else { DocumentFile file = DocumentFile.fromTreeUri(context, treeUri); if (!file.isDirectory()) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_not_directory); result = null; } else if (!file.canWrite()) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_cant_write); result = null; } else { if (Platforms.get().saf()) { LollipopFileSystem fs = (LollipopFileSystem) Platforms.fileSystem(); result = fs.getTreePath(treeUri); // TODO - remove below code - only for testing SD card writing File testFile = new File(result, "test_file.txt"); LOG.info("test file {}", testFile); try { Pair<ParcelFileDescriptor, DocumentFile> fd = fs.openFD(testFile, "rw"); if (fd != null && fd.first != null && fd.second != null) { AndroidFileHandler ah = new AndroidFileHandler(testFile, fd.second, fd.first); ByteBuffer bb = ByteBuffer.allocate(48); bb.putInt(1).putInt(2).putInt(3).putInt(44).putInt(22); bb.flip(); ah.getWriteChannel().write(bb); ah.close(); } else { LOG.error("unable to create file {}", testFile); } } catch (Exception e) { LOG.error("unable to fill file {} error {}", testFile, e); } } } } } } catch (Exception e) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_error); LOG.error("Error handling folder selection {}", e); result = null; } return result; }
From source file:com.toan_itc.tn.CustomTabClient.CustomTabsIntent.java
/** * Whether a browser receiving the given intent should always use browser UI and avoid using any * custom tabs UI.// www.ja va 2s. c o m * * @param intent The intent to check for the required flags and extras. * @return Whether the browser UI should be used exclusively. */ public static boolean shouldAlwaysUseBrowserUI(Intent intent) { return intent.getBooleanExtra(EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS, false) && (intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0; }
From source file:com.frostwire.android.gui.StoragePicker.java
public static String handle(Context context, int requestCode, int resultCode, Intent data) { String result = null;/*from ww w .ja va2 s .com*/ try { if (resultCode == Activity.RESULT_OK && requestCode == SELECT_FOLDER_REQUEST_CODE) { Uri treeUri = data.getData(); ContentResolver cr = context.getContentResolver(); Method takePersistableUriPermissionM = cr.getClass().getMethod("takePersistableUriPermission", Uri.class, int.class); final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takePersistableUriPermissionM.invoke(cr, treeUri, takeFlags); if (treeUri == null) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_null); result = null; } else { DocumentFile file = DocumentFile.fromTreeUri(context, treeUri); if (!file.isDirectory()) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_not_directory); result = null; } else if (!file.canWrite()) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_cant_write); result = null; } else { result = getFullPathFromTreeUri(context, treeUri); } } } } catch (Throwable e) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_error); LOG.error("Error handling folder selection", e); result = null; } return result; }
From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java
private static JSONObject buildJsonIntent(Intent data) throws JSONException { JSONObject result = new JSONObject(); result.put("data", data.getDataString()); result.put("type", data.getType()); result.put("extras", build(data.getExtras())); result.put("categories", build(data.getCategories())); result.put("action", data.getAction()); ComponentName component = data.getComponent(); if (component != null) { result.put("packagename", component.getPackageName()); result.put("classname", component.getClassName()); }/*from w w w.ja v a 2 s.c om*/ result.put("flags", data.getFlags()); return result; }
From source file:de.ub0r.android.websms.WebSMSReceiver.java
/** * Displays notification if sending failed * * @param context context//from w ww .j a v a 2 s . com * @param specs {@link de.ub0r.android.websms.connector.common.ConnectorSpec} * @param command {@link de.ub0r.android.websms.connector.common.ConnectorCommand} */ private static void displaySendingFailedNotification(final Context context, final ConnectorSpec specs, final ConnectorCommand command) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); String to = Utils.joinRecipients(command.getRecipients(), ", "); final Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse(INTENT_SCHEME_SMSTO + ":" + Uri.encode(to)), context, WebSMS.class); // add pending intent i.putExtra(Intent.EXTRA_TEXT, command.getText()); i.putExtra(WebSMS.EXTRA_ERRORMESSAGE, specs.getErrorMessage()); i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); final PendingIntent cIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder b = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.stat_notify_sms_failed) .setContentTitle(context.getString(R.string.notify_failed) + " " + specs.getErrorMessage()) .setContentText(to + ": " + command.getText()).setTicker(context.getString(R.string.notify_failed_)) .setWhen(System.currentTimeMillis()).setContentIntent(cIntent).setAutoCancel(true) .setLights(NOTIFICATION_LED_COLOR, NOTIFICATION_LED_ON, NOTIFICATION_LED_OFF); final String s = p.getString(WebSMS.PREFS_FAIL_SOUND, null); if (!TextUtils.isEmpty(s)) { b.setSound(Uri.parse(s)); } if (p.getBoolean(WebSMS.PREFS_FAIL_VIBRATE, false)) { b.setVibrate(VIBRATE_ON_FAIL_PATTERN); } NotificationManager mNotificationMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationMgr.notify(getNotificationID(), b.build()); // show a toast as well final String em = specs.getErrorMessage(); if (em != null) { Toast.makeText(context, em, Toast.LENGTH_LONG).show(); } }
From source file:org.readium.sdk.android.launcher.BookmarksActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.book_marks); context = this; back = (Button) findViewById(R.id.backToBookView7); Intent intent = getIntent(); if (intent.getFlags() == Intent.FLAG_ACTIVITY_NEW_TASK) { Bundle extras = intent.getExtras(); if (extras != null) { String value = extras.getString(Constants.BOOK_NAME); containerId = extras.getLong(Constants.CONTAINER_ID); container = ContainerHolder.getInstance().get(containerId); back.setText(value);// w w w.j av a 2 s.c o m } } final ListView itmes = (ListView) findViewById(R.id.bookmarks); this.setListViewContent(itmes, BookmarkDatabase.getInstance().getBookmarks(container.getName())); initListener(); }
From source file:org.readium.sdk.android.launcher.SpineItemsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.spine_items); context = this; back = (Button) findViewById(R.id.backToBookView1); Intent intent = getIntent(); if (intent.getFlags() == Intent.FLAG_ACTIVITY_NEW_TASK) { Bundle extras = intent.getExtras(); if (extras != null) { String value = extras.getString(Constants.BOOK_NAME); back.setText(value);/*w w w . j a va 2 s.c o m*/ containerId = extras.getLong(Constants.CONTAINER_ID); Container container = ContainerHolder.getInstance().get(containerId); if (container == null) { finish(); return; } pckg = container.getDefaultPackage(); } } final ListView items = (ListView) findViewById(R.id.spineItems); List<SpineItem> spineItems = new ArrayList<SpineItem>(); if (pckg != null) { spineItems = pckg.getSpineItems(); } this.setListViewContent(items, spineItems); initListener(); }