Example usage for android.content Intent getType

List of usage examples for android.content Intent getType

Introduction

In this page you can find the example usage for android.content Intent getType.

Prototype

public @Nullable String getType() 

Source Link

Document

Retrieve any explicit MIME type included in the intent.

Usage

From source file:jamesmorrisstudios.com.randremind.activities.MainActivity.java

private void processIntents() {
    Intent intent = getIntent();
    if (intent == null) {
        return;/*from   w  ww .j  a  v  a 2 s . co m*/
    }
    String action = intent.getAction();
    String type = intent.getType();
    //If we are opening from a reminder notification click go straight to that reminder page
    if (intent.hasExtra("REMINDER") && intent.hasExtra("NAME")) {
        if (loadReminderListSync(intent)) {
            Log.v("Main Activity", "Intent received to go to reminder");
            ReminderList.getInstance().setCurrentReminder(intent.getStringExtra("NAME"));
            clearForOpen(intent);
            loadSummaryFragment();
        }
    } else if ((Intent.ACTION_SEND.equals(action) || Intent.ACTION_VIEW.equals(action)) && type != null) {
        Log.v("MainActivity", "Shared text " + type);
        Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (uri == null) {
            uri = intent.getData();
        }
        if (uri != null) {
            clearForOpen(intent);
            loadBackupRestoreFragment(uri);
        }
    }
}

From source file:org.mariotaku.gallery3d.app.ImageViewerGLActivity.java

private String getContentType(final Intent intent) {
    final String type = intent.getType();
    if (type != null)
        return type;

    final Uri uri = intent.getData();
    try {//from ww w  .  j a  v a  2 s. c om
        return getContentResolver().getType(uri);
    } catch (final Throwable t) {
        Log.w(TAG, "get type fail", t);
        return null;
    }
}

From source file:foundme.uniroma2.it.professore.HomeActivity.java

private void handleIntent(Intent intent) {
    String action = intent.getAction();

    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {

        String type = intent.getType();
        if (Variables_it.MIME_TEXT_PLAIN.equals(type)) {

            Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
            new NdefReaderTask().execute(tag);

        }//from  www .  j  av a2  s.  c o  m
    } else if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {

        // In questo caso usermo la Tech Discovered Intent
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        String[] techList = tag.getTechList();
        String searchedTech = Ndef.class.getName();

        for (String tech : techList) {
            if (searchedTech.equals(tech)) {
                new NdefReaderTask().execute(tag);
                break;
            }
        }
    }
}

From source file:org.imdea.panel.MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override//  w w  w . j a v  a 2 s  . c  o  m
        public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
            Log.e("Alert", "UNCAUGHT EXCEPTION", paramThrowable);
            System.exit(1);
        }
    });
    Thread.setDefaultUncaughtExceptionHandler(onRuntimeError);

    /*
    ParseObject testObject = new ParseObject("TestObject");
    testObject.put("foo", "bar");
    testObject.saveInBackground();*/

    SP = PreferenceManager.getDefaultSharedPreferences(this);

    //Abrimos la base de datos 'DBUsuarios' en modo escritura
    DBHelper msg_database = new DBHelper(this, "messages.db", null, 1);
    Global.db = msg_database.getWritableDatabase();

    enableBt();

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    setContentView(R.layout.activity_main);

    // Initilization
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionbar = getActionBar();

    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }
    checkUsername();

    TabsPagerAdapter mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    fm = getSupportFragmentManager();

    viewPager.setAdapter(mAdapter);
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionbar.addTab(actionbar.newTab().setText("General").setTabListener(this));
    actionbar.addTab(actionbar.newTab().setText("Tags").setTabListener(this));

    /**
     * on swiping the viewpager make respective tab selected
     * */
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        public void onPageSelected(int position) {
            // on changing the page
            // make respected tab selected
            actionbar.setSelectedNavigationItem(position);
        }

        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        public void onPageScrollStateChanged(int arg0) {
        }
    });

    /* EXPERIMENTAL SERVICES */

    //this.startService(new Intent(this, WifiService.class));
    //this.startService(new Intent(this, BtWizService.class));
    //this.startService(new Intent(this, MeshService.class));
    this.startService(new Intent(this, commService.class));
    //if (Global.mqtt) this.startService(new Intent(this, mqttService.class));
    //else this.startService(new Intent(this, BtService.class));
    //this.startService(new Intent(this, smoothService.class));

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            handleSendText(intent); // Handle text being sent
        } else if (type.startsWith("image/")) {
            handleSendImage(intent); // Handle single image being sent
        }

    }

}

From source file:org.opensilk.music.ui2.LauncherActivity.java

void handleIntent() {
    Intent intent = getIntent();
    final String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action)) {
        final Uri uri = intent.getData();
        final String mimeType = intent.getType();
        Timber.i("action=%s, mimeType=%s, uri=%s", action, uri != null ? uri : "null", mimeType);
        boolean handled = false;
        if (uri != null && uri.toString().length() > 0) {
            mMusicService.playFile(uri);
            handled = true;//from ww  w. j  a va  2  s .  c  om
        } else if (MediaStore.Audio.Playlists.CONTENT_TYPE.equals(mimeType)) {
            long id = intent.getLongExtra("playlistId", -1);
            if (id < 0) {
                String idString = intent.getStringExtra("playlist");
                if (idString != null) {
                    try {
                        id = Long.parseLong(idString);
                    } catch (NumberFormatException ignored) {
                    }
                }
            }
            if (id >= 0) {
                mMusicService.playPlaylist(getApplicationContext(), id, false);
                handled = true;
            }
        }
        if (!handled) {
            mBus.post(new MakeToast(R.string.err_generic));
        }
    }
    //        intent.setAction(null);
}

From source file:com.eng.arab.translator.androidtranslator.translate.TranslateViewActivity.java

private void initTranslatorPanel() {
    mainPanel = (LinearLayout) findViewById(R.id.activity_translator_translate);

    srcCard = (CardView) findViewById(R.id.src_card);
    srcToolbar = (Toolbar) findViewById(R.id.src_toolbar);
    srcToolbar.inflateMenu(R.menu.src_card);
    srcToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override//from ww w  . j  a  va 2  s .co  m
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.action_paste:
                srcText.setText(readFromClipboard());
                trgText.setTextColor(Color.BLACK);// Set Default Color
                showAToast("Pasted");
                break;
            /*case R.id.action_share:
                if (keyboard_flag == 0) {
                    hideSoftKeyboard();
                    keyboard_flag = 1;
                }
                else keyboard_flag = 0;
                Toast.makeText(TranslateViewActivity.this,"Share",Toast.LENGTH_SHORT).show();
                break;*/
            case R.id.action_clear:
                showAToast("Cleared");
                srcText.setText("");
                trgText.setTextColor(Color.BLACK);// Set Default Color
                //trgText.setText("");
                break;
            }
            return true;
        }
    });
    srcToolbar.setOnClickListener(this);
    srcToolbar.setTitle("ARABIC");/**UPPER Text to translate*/
    srcContent = (LinearLayout) findViewById(R.id.src_translate_content);

    translateButton = (Button) findViewById(R.id.main_translate_button);
    translateButton.setOnClickListener(this);

    trgCard = (CardView) findViewById(R.id.translate_trg_card);
    trgToolbar = (Toolbar) findViewById(R.id.translate_trg_toolbar);
    trgToolbar.inflateMenu(R.menu.trg_card);
    trgToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {

            case R.id.action_trg_audio:
                //Toast.makeText(TranslateViewActivity.this,"TRG AUDIO",Toast.LENGTH_SHORT).show();
                speakEnglishTranslation();
                break;
            case R.id.action_copy:
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                        Context.CLIPBOARD_SERVICE);
                clipboard.setText(trgText.getText());
                showAToast("English translation copied");
                trgText.setTextColor(Color.BLUE); // Set color as Higlight
                break;
            /*case R.id.action_share:
                Toast.makeText(TranslateViewActivity.this,"Share",Toast.LENGTH_SHORT).show();
                final Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_TEXT, trgText.getText().toString());
                startActivity(Intent.createChooser(intent, getResources().getText(R.string.share_with)));
                break;*/
            }
            return true;
        }
    });
    trgToolbar.setOnClickListener(this);
    trgToolbar.setTitle("ENGLISH");/**LOWER Translated*/
    trgContent = (LinearLayout) findViewById(R.id.trg_content);

    srcText = (EditText) findViewById(R.id.src_text);

    trgTextScroll = (ScrollView) findViewById(R.id.trg_text_scroll);
    trgText = (TextView) findViewById(R.id.trg_text);

    mainPanel.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        private int trgCardPreEditingVisibility;

        @Override
        public void onGlobalLayout() {
            final int heightDiffPx = mainPanel.getRootView().getHeight() - mainPanel.getHeight();
            final int heightDiffDp = (int) (heightDiffPx
                    / (getResources().getDisplayMetrics().densityDpi / 160f));
            if (heightDiffDp > 150 && !editing) { // if more than 150 dps, its probably a keyboard...
                editing = true;
                trgCardPreEditingVisibility = trgCard.getVisibility();
                trgCard.setVisibility(View.GONE);
                //                    updateSrcToolbar();
            } else if (heightDiffDp < 150 && editing) {
                editing = false;
                trgCard.setVisibility(trgCardPreEditingVisibility);
                srcText.clearFocus();
                //                    updateSrcToolbar();
            }
        }

    });

    final Intent intent = getIntent();
    if (Intent.ACTION_SEND.equals(intent.getAction()) && "text/plain".equals(intent.getType())) {
        srcText.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
    }
    //snackBar();
}

From source file:io.oceanos.shaderbox.ShaderEditorActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final LayoutInflater inflater = getLayoutInflater();
    final View customActionBarView = inflater.inflate(R.layout.actionbar_view_save, null);
    final View shaderActionView = customActionBarView.findViewById(R.id.actionbar_view);
    final View shaderActionSave = customActionBarView.findViewById(R.id.actionbar_save);
    shaderActionView.setOnClickListener(new View.OnClickListener() {
        @Override/* ww w.  j  a  va2s  .co m*/
        public void onClick(View v) {
            if (result.isSuccess())
                onView(shader);
            else {
                Toast errorMsg = Toast.makeText(getBaseContext(), result.getError(), Toast.LENGTH_LONG);
                errorMsg.getView().setBackgroundColor(getResources().getColor(R.color.editor_color_error));
                errorMsg.show();
            }
        }
    });
    shaderActionSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSave(shader);
        }
    });

    fps = (TextView) customActionBarView.findViewById(R.id.text_fps);
    viewError = (TextView) shaderActionView.findViewById(R.id.viewError);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    setContentView(R.layout.activity_editor);

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    ShaderDatabase database = new ShaderDatabase(getBaseContext());
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
            long id = database.newShader();
            Cursor cursor = database.findById(id);
            if (cursor.moveToFirst())
                shader = Shader.getValues(cursor);
            cursor.close();
            if (sharedText != null)
                shader.setText(sharedText);
            else
                shader.setText("");
        }
    } else {
        long id = intent.getLongExtra("ID", 0);
        Cursor cursor = database.findById(id);
        if (cursor.moveToFirst())
            shader = Shader.getValues(cursor);
        cursor.close();
    }
    database.close();

    setSymbolListener(R.id.action_tab, '\t');
    setSymbolListener(R.id.action_rpo, '(');
    setSymbolListener(R.id.action_rpc, ')');
    setSymbolListener(R.id.action_cpo, '{');
    setSymbolListener(R.id.action_cpc, '}');
    setSymbolListener(R.id.action_dotcoma, ';');
    setSymbolListener(R.id.action_coma, ',');
    setSymbolListener(R.id.action_dot, '.');
    setSymbolListener(R.id.action_plus, '+');
    setSymbolListener(R.id.action_minus, '-');
    setSymbolListener(R.id.action_times, '*');
    setSymbolListener(R.id.action_div, '/');
    setSymbolListener(R.id.action_equal, '=');
    setSymbolListener(R.id.action_spo, '[');
    setSymbolListener(R.id.action_spc, ']');
    setSymbolListener(R.id.action_and, '&');
    setSymbolListener(R.id.action_or, '|');
    setSymbolListener(R.id.action_greater, '>');
    setSymbolListener(R.id.action_lesser, '<');
    setSymbolListener(R.id.action_cardinal, '#');

    final Handler uiHandler = new Handler(this);
    renderer = new ShaderRenderer(shader, uiHandler);

    shaderView = (ShaderGLView) findViewById(R.id.shader_view);
    shaderView.setRenderer(renderer);
    shaderView.setVRModeEnabled(false);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    int textSize = Integer.parseInt(prefs.getString("pref_editor_text_size", "14"));
    int opacity = Integer.parseInt(prefs.getString("pref_editor_opacity", "127"));
    editor = (ShaderEditor) findViewById(R.id.editor);
    editor.setTextSize(textSize);
    editor.setBackgroundColor(opacity << 24);
    editor.setHorizontallyScrolling(true);
    editor.setHorizontalScrollBarEnabled(true);

    editor.setText(shader.getText());

    ScrollView scroll = (ScrollView) findViewById(R.id.scroll);
    editor.setScrollView(scroll);

    compileRT = prefs.getBoolean("pref_compile_rt", true);
}

From source file:org.sufficientlysecure.keychain.ui.EncryptFileActivity.java

/**
 * Handles all actions with this intent//from  w  w w.  j  a  v  a2  s.c  o m
 *
 * @param intent
 */
private void handleActions(Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();
    String type = intent.getType();
    ArrayList<Uri> uris = new ArrayList<Uri>();

    if (extras == null) {
        extras = new Bundle();
    }

    if (intent.getData() != null) {
        uris.add(intent.getData());
    }

    /*
     * Android's Action
     */

    // When sending to OpenKeychain Encrypt via share menu
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        // Files via content provider, override uri and action
        uris.clear();
        uris.add(intent.<Uri>getParcelableExtra(Intent.EXTRA_STREAM));
    }

    if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
    }

    if (extras.containsKey(EXTRA_ASCII_ARMOR)) {
        mUseArmor = extras.getBoolean(EXTRA_ASCII_ARMOR, true);
    }

    // preselect keys given by intent
    mSigningKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
    mEncryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);

    // Save uris
    mInputUris = uris;

}

From source file:com.doplgangr.secrecy.views.FileViewer.java

private Intent generateCustomChooserIntent(Intent prototype, ArrayList<Uri> uris) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    List<HashMap<String, String>> intentMetaInfo = new ArrayList<HashMap<String, String>>();
    Intent chooserIntent;//from w ww .j  a v a2 s  .co m

    Intent dummy = new Intent(prototype.getAction());
    dummy.setType(prototype.getType());
    List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(dummy, 0);

    if (!resInfo.isEmpty()) {
        for (ResolveInfo resolveInfo : resInfo) {
            if (resolveInfo.activityInfo == null
                    || resolveInfo.activityInfo.packageName.equalsIgnoreCase("com.doplgangr.secrecy"))
                continue;

            HashMap<String, String> info = new HashMap<String, String>();
            info.put("packageName", resolveInfo.activityInfo.packageName);
            info.put("className", resolveInfo.activityInfo.name);
            info.put("simpleName",
                    String.valueOf(resolveInfo.activityInfo.loadLabel(context.getPackageManager())));
            intentMetaInfo.add(info);
            for (Uri uri : uris)
                context.grantUriPermission(resolveInfo.activityInfo.packageName, uri,
                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }

        if (!intentMetaInfo.isEmpty()) {
            // sorting for nice readability
            Collections.sort(intentMetaInfo, new Comparator<HashMap<String, String>>() {
                @Override
                public int compare(HashMap<String, String> map, HashMap<String, String> map2) {
                    return map.get("simpleName").compareTo(map2.get("simpleName"));
                }
            });

            // create the custom intent list
            for (HashMap<String, String> metaInfo : intentMetaInfo) {
                Intent targetedShareIntent = (Intent) prototype.clone();
                targetedShareIntent.setPackage(metaInfo.get("packageName"));
                targetedShareIntent.setClassName(metaInfo.get("packageName"), metaInfo.get("className"));
                targetedShareIntents.add(targetedShareIntent);
            }
            chooserIntent = Intent.createChooser(targetedShareIntents.remove(targetedShareIntents.size() - 1),
                    CustomApp.context.getString(R.string.Dialog__send_file));
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                    targetedShareIntents.toArray(new Parcelable[targetedShareIntents.size()]));
            return chooserIntent;
        }
    }

    return new Intent(Intent.ACTION_SEND); //Unable to do anything. Duh.
}

From source file:es.uma.lcc.lockpic.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainactivity);
    System.loadLibrary("jpg"); // load native libraries

    // This activity is able to open images directly from a file browser.
    // If this is the case, we store the path, which will be used in onPostCreate
    Intent intent = getIntent();
    if (Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getType() != null
            && (savedInstanceState == null || savedInstanceState.getBoolean("firstTime", true))) {
        if (intent.getType().startsWith("image/")) {
            mDirectDecryptPath = LockPicIO.getPathFromIntent(MainActivity.this, intent);
            if (mDirectDecryptPath == null)
                Toast.makeText(this, R.string.unknownIntent, Toast.LENGTH_SHORT).show();
        }// w w  w  .j a v  a2 s  .c o  m
    }

    // disable screen capture
    getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
}