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:org.sufficientlysecure.keychain.ui.DecryptFilesActivity.java

/**
 * Handles all actions with this intent/*from  w ww  .  ja v a2s .com*/
 */
private void handleActions(Bundle savedInstanceState, Intent intent) {
    String action = intent.getAction();
    String type = intent.getType();
    Uri uri = intent.getData();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        // When sending to Keychain Decrypt via share menu
        // Binary via content provider (could also be files)
        // override uri to get stream from send
        uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        action = ACTION_DECRYPT_DATA;
    } else if (Intent.ACTION_VIEW.equals(action)) {
        // Android's Action when opening file associated to Keychain (see AndroidManifest.xml)

        // override action
        action = ACTION_DECRYPT_DATA;
    }

    // No need to initialize fragments if we are being restored
    if (savedInstanceState != null) {
        return;
    }

    // Definitely need a data uri with the decrypt_data intent
    if (ACTION_DECRYPT_DATA.equals(action) && uri == null) {
        Toast.makeText(this, "No data to decrypt!", Toast.LENGTH_LONG).show();
        setResult(Activity.RESULT_CANCELED);
        finish();
    }

    boolean showOpenDialog = ACTION_DECRYPT_DATA_OPEN.equals(action);
    DecryptFilesFragment frag = DecryptFilesFragment.newInstance(uri, showOpenDialog);

    // Add the fragment to the 'fragment_container' FrameLayout
    // NOTE: We use commitAllowingStateLoss() to prevent weird crashes!
    getSupportFragmentManager().beginTransaction().replace(R.id.decrypt_files_fragment_container, frag)
            .commitAllowingStateLoss();

}

From source file:com.tct.mail.browse.EmlViewerActivity.java

private void doCreate(Bundle savedInstanceState) {
    final Intent intent = getIntent();
    final String action = intent.getAction();
    final String type = intent.getType();
    if (savedInstanceState == null) {
        if (Intent.ACTION_VIEW.equals(action) && MimeType.isEmlMimeType(type)) {
            final FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.add(R.id.root, EmlMessageViewFragment.newInstance(intent.getData(), mAccountUri),
                    FRAGMENT_TAG);/*from  ww w . j  a  v a2s.com*/
            transaction.commit();
            Analytics.getInstance().sendEvent("eml_viewer", null, null, 0);
        } else {
            LogUtils.wtf(LOG_TAG, "Entered EmlViewerActivity with wrong intent action or type: %s, %s", action,
                    type);
            finish(); // we should not be here. bail out. bail out.
            return;
        }
    }
}

From source file:org.thezero.qrfi.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    pager = (ViewPager) findViewById(R.id.pager);
    c = this;/*from   w ww .jav  a2 s.co m*/

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitleTextColor(getResources().getColor(R.color.primary_text));
    toolbar.setLogo(R.drawable.wifi2);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(adapter);
    tabs.setViewPager(pager);
    pager.setCurrentItem(1);

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

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
            handleDecodeImage(imageUri); // Handle single image being sent
        }
    }

}

From source file:com.duy.pascal.ui.activities.SplashScreenActivity.java

private void handleActionView(@NonNull Intent from, @NonNull Intent to) {
    if (from.getData() == null || from.getType() == null) {
        return;//from   w w w .ja  va  2 s. com
    }
    DLog.d(TAG, "handleActionView() called with: from = [" + from + "], to = [" + to + "]");
    if (from.getData().toString().endsWith(".pas") || from.getData().toString().endsWith(".txt")) {
        Uri uriPath = from.getData();
        DLog.d(TAG, "handleActionView: " + uriPath.getPath());
        try {
            String filePath = FileManager.getPathFromUri(this, uriPath);
            if (filePath != null) {
                to.putExtra(CompileManager.EXTRA_FILE, new File(filePath));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (from.getType().equals("text/x-pascal")) {
        Uri uri = from.getData();
        try {
            //clone file
            InputStream inputStream = getContentResolver().openInputStream(uri);
            FileManager fileManager = new FileManager(this);
            File file = fileManager.createRandomFile(this);
            fileManager.copy(inputStream, new FileOutputStream(file));

            to.putExtra(CompileManager.EXTRA_FILE, file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.krayzk9s.imgurholo.activities.ImgurLinkActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    destroyed = false;/*from   w  ww  .  j av  a 2  s  .  co m*/
    if (getActionBar() != null)
        getActionBar().setDisplayHomeAsUpEnabled(true);
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    Log.d("New Intent", intent.toString());
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
            Intent serviceIntent = new Intent(this, UploadService.class);
            if (intent.getExtras() == null)
                finish();
            serviceIntent.setData((Uri) intent.getExtras().get("android.intent.extra.STREAM"));
            startService(serviceIntent);
            finish();
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        Log.d("sending", "sending multiple");
        Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
        ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        Intent serviceIntent = new Intent(this, UploadService.class);
        serviceIntent.putParcelableArrayListExtra("images", list);
        startService(serviceIntent);
        finish();
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null
            && intent.getData().toString().startsWith("http://imgur.com/a")) {
        String uri = intent.getData().toString();
        album = uri.split("/")[4];
        Log.d("album", album);
        Fetcher fetcher = new Fetcher(this, "/3/album/" + album, ApiCall.GET, null, apiCall, ALBUM);
        fetcher.execute();
    } else if (Intent.ACTION_VIEW.equals(action)
            && intent.getData().toString().startsWith("http://imgur.com/gallery/")) {
        String uri = intent.getData().toString();
        final String album = uri.split("/")[4];
        if (album.length() == 5) {
            Log.d("album", album);
            Fetcher fetcher = new Fetcher(this, "/3/album/" + album, ApiCall.GET, null, apiCall, ALBUM);
            fetcher.execute();
        } else if (album.length() == 7) {
            Log.d("image", album);
            Fetcher fetcher = new Fetcher(this, "/3/gallery/image/" + album, ApiCall.GET, null, apiCall, IMAGE);
            fetcher.execute();
        }
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData().toString().startsWith("http://i.imgur")) {
        String uri = intent.getData().toString();
        final String image = uri.split("/")[3].split("\\.")[0];
        Log.d("image", image);
        Fetcher fetcher = new Fetcher(this, "/3/image/" + image, ApiCall.GET, null, apiCall, IMAGE);
        fetcher.execute();
    }
}

From source file:com.hippo.nimingban.ui.TypeSendActivity.java

private Bundle createArgs() {
    Bundle bundle = new Bundle();
    Intent intent = getIntent();
    if (intent != null) {
        bundle.putString(TypeSendFragment.KEY_ACTION, intent.getAction());
        bundle.putString(TypeSendFragment.KEY_TYPE, intent.getType());
        bundle.putInt(TypeSendFragment.KEY_SITE, intent.getIntExtra(KEY_SITE, -1));
        bundle.putString(TypeSendFragment.KEY_ID, intent.getStringExtra(KEY_ID));
        bundle.putString(TypeSendFragment.KEY_TEXT, intent.getStringExtra(KEY_TEXT));
        bundle.putString(TypeSendFragment.KEY_EXTRA_TEXT, intent.getStringExtra(Intent.EXTRA_TEXT));
        bundle.putParcelable(TypeSendFragment.KEY_EXTRA_STREAM, intent.getParcelableExtra(Intent.EXTRA_STREAM));
    }/*from   w w w . jav a 2 s  .c om*/
    return bundle;
}

From source file:com.android.mail.browse.EmlViewerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.eml_viewer_activity);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    final Intent intent = getIntent();
    final String action = intent.getAction();
    final String type = intent.getType();
    mAccountUri = intent.getParcelableExtra(EXTRA_ACCOUNT_URI);

    if (savedInstanceState == null) {
        if (Intent.ACTION_VIEW.equals(action) && MimeType.isEmlMimeType(type)) {
            final FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.add(R.id.eml_root, EmlMessageViewFragment.newInstance(intent.getData(), mAccountUri),
                    FRAGMENT_TAG);//w ww  .ja v  a2 s.c  o  m
            transaction.commit();
        } else {
            LogUtils.wtf(LOG_TAG, "Entered EmlViewerActivity with wrong intent action or type: %s, %s", action,
                    type);
            finish(); // we should not be here. bail out. bail out.
            return;
        }
    } else {
        if (savedInstanceState.containsKey(SAVED_ACCOUNT)) {
            mAccount = savedInstanceState.getParcelable(SAVED_ACCOUNT);
        }
    }

    // Account uri will be null if we launched from outside of the app.
    // So just don't load an account at all.
    if (mAccountUri != null) {
        getLoaderManager().initLoader(ACCOUNT_LOADER, Bundle.EMPTY, mAccountLoadCallbacks);
    }
}

From source file:com.amytech.android.library.views.imagechooser.api.BChooser.java

protected boolean wasVideoSelected(Intent data) {
    if (data == null) {
        return false;
    }//from  w w  w.  j a  v  a  2s. co  m

    if (data.getType() != null && data.getType().startsWith("video")) {
        return true;
    }

    ContentResolver cR = getContext().getContentResolver();
    String type = cR.getType(data.getData());
    if (type != null && type.startsWith("video")) {
        return true;
    }

    return false;
}

From source file:com.frankegan.sqrshare.MainActivity.java

/**
 * {@inheritDoc}/*from w w  w . jav a 2  s.  c o m*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);
    status = (FrameLayout) findViewById(R.id.status);
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    pic_fragment = (PictureHolder) getSupportFragmentManager().findFragmentByTag(tag);

    if (pic_fragment == null) {
        pic_fragment = new PictureFragment();
        getSupportFragmentManager().beginTransaction().add(R.id.fragment, (Fragment) pic_fragment, tag)
                .commit();
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        status.setMinimumHeight(getStatusBarHeight());

    //this if for apps sharing to the app
    if (Intent.ACTION_SEND.equals(action) && type != null && (type.startsWith("image/"))) {
        Log.i("frankegan", "image was sent to activity");
        handleSentImage(intent); // Handle single image being sent to you
    }

    //this is for apps trying to open images with our app
    if ((Intent.ACTION_VIEW.equals(action)) && (type != null) && (type.startsWith("image/"))) {
        Log.i("frankegan", "image was viewed in activity");
        handleViewImage(intent); // Handle single image being sent to you
    }
}

From source file:net.kourlas.voipms_sms.activities.NewConversationActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.new_conversation);

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    if (Intent.ACTION_SEND.equals(action) && type != null && type.equals("text/plain")) {
        this.messageText = intent.getStringExtra(Intent.EXTRA_TEXT);
    }/*w  w  w  .j  a v a2s  . c  o  m*/

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    ViewCompat.setElevation(toolbar, getResources().getDimension(R.dimen.toolbar_elevation));
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);

        actionBar.setCustomView(R.layout.new_conversation_toolbar);
        actionBar.setDisplayShowCustomEnabled(true);
    }

    final Activity newConversationActivity = this;

    final NewConversationListViewAdapter newConversationListViewAdapter = new NewConversationListViewAdapter(
            this);

    if (actionBar != null) {
        SearchView searchView = (SearchView) actionBar.getCustomView().findViewById(R.id.search_view);
        searchView.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                String phoneNumber = newText.replaceAll("[^0-9]", "");
                if (phoneNumber.equals("")) {
                    newConversationListViewAdapter.hideTypedInItem();
                } else {
                    newConversationListViewAdapter.showTypedInItem(phoneNumber);
                }
                newConversationListViewAdapter.refresh(newText);
                return true;
            }
        });
        searchView.requestFocus();

        // Hide search icon
        ImageView searchMagIcon = (ImageView) searchView.findViewById(R.id.search_mag_icon);
        searchMagIcon.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
    }

    final ListView listView = (ListView) findViewById(R.id.list);
    listView.setAdapter(newConversationListViewAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ContactItem contactItem = (ContactItem) newConversationListViewAdapter.getItem(position);

            String phoneNumber = contactItem.getPhoneNumber().replaceAll("[^0-9]", "");

            Intent intent = new Intent(newConversationActivity, ConversationActivity.class);
            intent.putExtra(getString(R.string.conversation_extra_contact), phoneNumber);
            if (messageText != null) {
                intent.putExtra(getString(R.string.conversation_extra_message_text), messageText);
            }
            intent.putExtra(getString(R.string.conversation_extra_focus), true);
            startActivity(intent);
        }
    });
    listView.setFastScrollEnabled(true);

    newConversationListViewAdapter.refresh("");
}