List of usage examples for android.content Intent getScheme
public @Nullable String getScheme()
From source file:com.jecelyin.editor.v2.ui.MainActivity.java
private boolean processIntentImpl() throws Throwable { Intent intent = getIntent(); L.d("intent=" + intent); if (intent == null) return true; //pass hint String action = intent.getAction(); // action == null if change theme if (action == null || Intent.ACTION_MAIN.equals(action)) { return true; }//from w w w .j a va 2s .com if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)) { if (intent.getScheme().equals("content")) { InputStream attachment = getContentResolver().openInputStream(intent.getData()); String text = IOUtils.toString(attachment); openText(text); return true; } else if (intent.getScheme().equals("file")) { Uri mUri = intent.getData(); String file = mUri != null ? mUri.getPath() : null; if (!TextUtils.isEmpty(file)) { openFile(file); return true; } } } else if (Intent.ACTION_SEND.equals(action) && intent.getExtras() != null) { Bundle extras = intent.getExtras(); CharSequence text = extras.getCharSequence(Intent.EXTRA_TEXT); if (text != null) { openText(text); return true; } else { Object stream = extras.get(Intent.EXTRA_STREAM); if (stream != null && stream instanceof Uri) { openFile(((Uri) stream).getPath()); return true; } } } return false; }
From source file:info.guardianproject.otr.app.im.app.WelcomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mApp = (ImApp) getApplication();// www . j a va 2s .c o m mHandler = new MyHandler(this); mSignInHelper = new SignInHelper(this); Intent intent = getIntent(); mDoSignIn = intent.getBooleanExtra("doSignIn", true); mDoLock = intent.getBooleanExtra("doLock", false); if (!mDoLock) { mApp.maybeInit(this); } if (ImApp.mUsingCacheword) connectToCacheWord(); else { if (openEncryptedStores(null, false)) { IocVfs.init(this, ""); } else { connectToCacheWord(); //first time setup } } // if we have an incoming contact, send it to the right place String scheme = intent.getScheme(); if (TextUtils.equals(scheme, "xmpp")) { intent.setClass(this, AddContactActivity.class); startActivity(intent); finish(); return; } }
From source file:com.handpoint.headstart.client.ui.MainActivity.java
Properties loadIniProperties(Intent iniIntent) throws IOException { InputStream attachment = null; Uri returnedUri = iniIntent.getData(); try {//from w w w. ja va 2s .c o m if (iniIntent.getScheme().equals("file")) { attachment = new FileInputStream(returnedUri.getPath()); } else if (iniIntent.getScheme().equals("content")) { attachment = getContentResolver().openInputStream(returnedUri); } Properties p = new Properties(); p.load(attachment); return p; } finally { if (null != attachment) { try { attachment.close(); } catch (IOException ignore) { } } } }
From source file:net.momodalo.app.vimtouch.VimTouch.java
private String getIntentUrl(Intent intent) { if (intent == null || intent.getScheme() == null) return null; String url = null;//from ww w. j av a2 s . c o m if (intent.getScheme().equals("file")) { url = intent.getData().getPath(); } else if (intent.getScheme().equals("content")) { String tmpPath = "tmp"; try { InputStream attachment = getContentResolver().openInputStream(intent.getData()); if (attachment.available() > 50000) { tmpPath = ""; new AlertDialog.Builder(this).setTitle(R.string.dialog_title_content_error) .setMessage(R.string.message_content_too_big).show(); throw new IOException("file too big"); } String attachmentFileName = "NoFile"; if (intent != null && intent.getData() != null) { Cursor c = getContentResolver().query(intent.getData(), null, null, null, null); c.moveToFirst(); final int fileNameColumnId = c.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME); if (fileNameColumnId >= 0) attachmentFileName = c.getString(fileNameColumnId); } String str[] = attachmentFileName.split("\\."); File outFile; if (str.length >= 2) outFile = File.createTempFile(str[0], "." + str[1], getDir(tmpPath, MODE_PRIVATE)); else outFile = File.createTempFile(attachmentFileName, "", getDir(tmpPath, MODE_PRIVATE)); tmpPath = outFile.getAbsolutePath(); FileOutputStream f = new FileOutputStream(outFile); byte[] buffer = new byte[1024]; while (attachment.read(buffer) > 0) { f.write(buffer); } f.close(); } catch (Exception e) { tmpPath = null; Log.e(VimTouch.LOG_TAG, e.toString()); } url = tmpPath; } return url; }
From source file:org.deviceconnect.android.manager.DConnectMessageService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { super.onStartCommand(intent, flags, startId); if (intent == null) { mLogger.warning("intent is null."); return START_STICKY; }//from w w w. jav a 2 s .c o m if (!mRunningFlag) { return START_STICKY; } String action = intent.getAction(); if (action == null) { mLogger.warning("action is null."); return START_STICKY; } String scheme = intent.getScheme(); if (SCHEME_LAUNCH.equals(scheme)) { String key = intent.getStringExtra(IntentDConnectMessage.EXTRA_KEY); String origin = intent.getStringExtra(IntentDConnectMessage.EXTRA_ORIGIN); if (key != null && !TextUtils.isEmpty(origin)) { mHmacManager.updateKey(origin, key); } return START_STICKY; } if (checkAction(action)) { onRequestReceive(intent); } else if (IntentDConnectMessage.ACTION_RESPONSE.equals(action)) { onResponseReceive(intent); } else if (IntentDConnectMessage.ACTION_EVENT.equals(action)) { onEventReceive(intent); } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) { mPluginMgr.checkAndAddDevicePlugin(intent); } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) { mPluginMgr.checkAndRemoveDevicePlugin(intent); } return START_STICKY; }
From source file:pt.aptoide.backupapps.Aptoide.java
private void handleIncomingIntent(Intent incomingIntent) { if (incomingIntent.getData() != null) { AptoideLog.d(this, "received intent: " + incomingIntent.getDataString()); if (incomingIntent.getType() != null && incomingIntent.getType().equals(Constants.MIMETYPE_MYAPP)) { AptoideLog.d(this, "received myapp: " + incomingIntent.getDataString()); try { serviceDataCaller.callReceiveMyapp(incomingIntent.getDataString()); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace();//from w w w . j a va 2 s . c om } } else if (incomingIntent.getScheme().equals(Constants.SCHEME_MARKET) || (incomingIntent.getScheme().equals(Constants.SCHEME_HTTPS) && incomingIntent.getData().getHost().equals(Constants.HOST_MARKET))) { String query = incomingIntent.getData().getQuery().split("&")[0].split("=")[1]; if (query.contains(":")) { query = query.split(":")[1]; } AptoideLog.d(this, "received market query: " + query); if (!synchronizingInstalledApps.get()) { startSearch(query, false, null, false); } else { blockedSearchQuery = query; } } cleanAptoideIntent(); } }
From source file:com.plusot.senselib.SenseMain.java
public void init(Intent intent, boolean start) { if (intent != null) { String scheme = intent.getScheme(); LLog.d(Globals.TAG, CLASSTAG + ".onActivityCreated: Scheme = " + scheme); if (scheme != null && scheme.equals("file")) { try { InputStream is = getContentResolver().openInputStream(intent.getData()); LLog.d(Globals.TAG, CLASSTAG + ".onActivityCreated: Reading CSV"); if (start) init(false);/* w ww . j av a 2 s .com*/ DataLog dataLog = DataLog.getInstance(); SenseGlobals.loadSplash = false; if (dataLog != null) dataLog.readCsv(is, this); return; } catch (FileNotFoundException e) { LLog.e(Globals.TAG, CLASSTAG + ".onActivityCreated: Could not getContentResolver()", e); } } } if (start) init(true); }
From source file:edu.mit.viral.shen.DroidFish.java
private final Pair<String, String> getPgnOrFenIntent() { String pgnOrFen = null;/*from ww w . j a va 2 s.c o m*/ String filename = null; try { Intent intent = getIntent(); Uri data = intent.getData(); if (data == null) { if ((Intent.ACTION_SEND.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction())) && ("application/x-chess-pgn".equals(intent.getType()) || "application/x-chess-fen".equals(intent.getType()))) pgnOrFen = intent.getStringExtra(Intent.EXTRA_TEXT); } else { String scheme = intent.getScheme(); if ("file".equals(scheme)) { filename = data.getEncodedPath(); if (filename != null) filename = Uri.decode(filename); } if ((filename == null) && ("content".equals(scheme) || "file".equals(scheme))) { ContentResolver resolver = getContentResolver(); InputStream in = resolver.openInputStream(intent.getData()); StringBuilder sb = new StringBuilder(); while (true) { byte[] buffer = new byte[16384]; int len = in.read(buffer); if (len <= 0) break; sb.append(new String(buffer, 0, len)); } pgnOrFen = sb.toString(); } } } catch (IOException e) { Toast.makeText(getApplicationContext(), R.string.failed_to_read_pgn_data, Toast.LENGTH_SHORT).show(); } return new Pair<String, String>(pgnOrFen, filename); }
From source file:org.mdc.chess.MDChess.java
/** * Return PGN/FEN data or filename from the Intent. Both can not be non-null. * * @return Pair of PGN/FEN data and filename. *//* ww w . ja v a 2 s . co m*/ private Pair<String, String> getPgnOrFenIntent() { String pgnOrFen = null; String filename = null; try { Intent intent = getIntent(); Uri data = intent.getData(); if (data == null) { Bundle b = intent.getExtras(); if (b != null) { Object strm = b.get(Intent.EXTRA_STREAM); if (strm instanceof Uri) { data = (Uri) strm; if ("file".equals(data.getScheme())) { filename = data.getEncodedPath(); if (filename != null) { filename = Uri.decode(filename); } } } } } if (data == null) { if ((Intent.ACTION_SEND.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction())) && ("application/x-chess-pgn".equals(intent.getType()) || "application/x-chess-fen".equals(intent.getType()))) { pgnOrFen = intent.getStringExtra(Intent.EXTRA_TEXT); } } else { String scheme = intent.getScheme(); if ("file".equals(scheme)) { filename = data.getEncodedPath(); if (filename != null) { filename = Uri.decode(filename); } } if ((filename == null) && ("content".equals(scheme) || "file".equals(scheme))) { ContentResolver resolver = getContentResolver(); InputStream in = resolver.openInputStream(intent.getData()); StringBuilder sb = new StringBuilder(); while (true) { byte[] buffer = new byte[16384]; int len = in != null ? in.read(buffer) : 0; if (len <= 0) { break; } sb.append(new String(buffer, 0, len)); } pgnOrFen = sb.toString(); } } } catch (IOException e) { Toast.makeText(getApplicationContext(), R.string.failed_to_read_pgn_data, Toast.LENGTH_SHORT).show(); } return new Pair<>(pgnOrFen, filename); }