Example usage for android.content Intent ACTION_CREATE_SHORTCUT

List of usage examples for android.content Intent ACTION_CREATE_SHORTCUT

Introduction

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

Prototype

String ACTION_CREATE_SHORTCUT

To view the source code for android.content Intent ACTION_CREATE_SHORTCUT.

Click Source Link

Document

Activity Action: Creates a shortcut.

Usage

From source file:com.jefftharris.passwdsafe.LauncherFileShortcuts.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    PasswdSafeApp.setupDialogTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher_file_shortcuts);

    FragmentManager fragMgr = getSupportFragmentManager();
    FragmentTransaction txn = fragMgr.beginTransaction();
    txn.replace(R.id.sync, new SyncProviderFragment());
    txn.commit();//w  w  w.j  a v a 2  s  . c  o m

    if (savedInstanceState == null) {
        setFileChooseFrag();
    }

    Intent intent = getIntent();
    if (!Intent.ACTION_CREATE_SHORTCUT.equals(intent.getAction())) {
        finish();
        return;
    }

    itsIsDefaultFile = intent.getBooleanExtra(EXTRA_IS_DEFAULT_FILE, false);
    if (itsIsDefaultFile) {
        setTitle(R.string.default_file_to_open);
    } else {
        setTitle(R.string.shortcut_file);
    }
}

From source file:com.markupartist.sthlmtraveling.SearchDeparturesFragment.java

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

    // If the activity was started with the "create shortcut" action, we
    // remember this to change the behavior upon a search.
    if (Intent.ACTION_CREATE_SHORTCUT.equals(getActivity().getIntent().getAction())) {
        mCreateShortcut = true;/*  ww  w  .  ja  va2 s .c om*/
        registerScreen("Create departure shortcut");
    }

    mHistoryDbAdapter = new HistoryDbAdapter(getActivity()).open();
}

From source file:org.mozilla.fennec_satyanarayan.LauncherShortcuts.java

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

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.launch_app_list);

    final Intent intent = getIntent();
    final String action = intent.getAction();

    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        // Doing it as a background task, as it involves file access
        new FetchWebApps().execute();
    }//from  w  ww  . java 2 s  .  co m
}

From source file:com.jefftharris.passwdsafe.LauncherRecordShortcuts.java

@Override
public void onCreate(Bundle savedInstanceState) {
    PasswdSafeApp.setupDialogTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher_record_shortcuts);
    SharedPreferences prefs = Preferences.getSharedPrefs(this);
    prefs.registerOnSharedPreferenceChangeListener(this);

    itsFile = (TextView) findViewById(R.id.file);
    itsFileDataView.onAttach(this, prefs);

    Intent intent = getIntent();/*from  w w  w .ja va  2  s.co m*/
    switch (intent.getAction()) {
    case Intent.ACTION_CREATE_SHORTCUT: {
        setTitle(R.string.shortcut_record);
        itsMode = Mode.SHORTCUT;
        break;
    }
    case PasswdSafeApp.CHOOSE_RECORD_INTENT: {
        setTitle(R.string.choose_record);
        itsMode = Mode.CHOOSE_RECORD;
        GuiUtils.setVisible(itsFile, false);
        break;
    }
    default: {
        finish();
        return;
    }
    }

    int options = PasswdRecordFilter.OPTS_DEFAULT;
    if (intent.getBooleanExtra(FILTER_NO_ALIAS, false)) {
        options |= PasswdRecordFilter.OPTS_NO_ALIAS;
    }
    if (intent.getBooleanExtra(FILTER_NO_SHORTCUT, false)) {
        options |= PasswdRecordFilter.OPTS_NO_SHORTCUT;
    }
    if (options != PasswdRecordFilter.OPTS_DEFAULT) {
        itsFileDataView.setRecordFilter(new PasswdRecordFilter(null, options));
    }

    if (savedInstanceState == null) {
        FragmentManager fragMgr = getSupportFragmentManager();
        FragmentTransaction txn = fragMgr.beginTransaction();
        txn.replace(R.id.contents, PasswdSafeListFragment.newInstance(itsLocation, true));
        txn.commit();
    }
}

From source file:com.metinkale.prayerapp.BaseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (App.getContext() == null) {
        App.setContext(this);
    }/*from w  ww. j av a  2s  .c o  m*/

    if (Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
        int id = R.mipmap.ic_launcher;
        switch (mNavPos) {
        case 1:
            id = R.mipmap.ic_compass;
            break;
        case 2:
            id = R.mipmap.ic_names;
            break;
        case 3:
            id = R.mipmap.ic_calendar;
            break;
        case 4:
            id = R.mipmap.ic_tesbihat;
            break;
        case 7:
            id = R.mipmap.ic_zikr;
            break;
        }

        Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, id);

        Intent intent = new Intent();
        Intent launchIntent = new Intent(this, getClass());
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        launchIntent.putExtra("duplicate", false);

        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getStringArray(R.array.dropdown)[mNavPos]);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

        setResult(RESULT_OK, intent);
        finish();
    }

    if (!Utils.askLang(this)) {
        Utils.init(this);
        Changelog.start(this);
    }

}

From source file:com.android.music.PlaylistBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View view = inflater.inflate(R.layout.media_picker_activity, null);

    final Intent intent = getActivity().getIntent();
    final String action = intent.getAction();
    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        mCreateShortcut = true;/*from  w  ww  .j  a v a  2  s  . c  o  m*/
    }

    getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(getActivity(), new ServiceConnection() {
        public void onServiceConnected(ComponentName classname, IBinder obj) {
            if (Intent.ACTION_VIEW.equals(action)) {
                Bundle b = intent.getExtras();
                if (b == null) {
                    Log.w(TAG, "Unexpected:getExtras() returns null.");
                } else {
                    try {
                        long id = Long.parseLong(b.getString("playlist"));
                        if (id == RECENTLY_ADDED_PLAYLIST) {
                            playRecentlyAdded();
                        } else if (id == PODCASTS_PLAYLIST) {
                            playPodcasts();
                        } else if (id == ALL_SONGS_PLAYLIST) {
                            long[] list = MusicUtils.getAllSongs(getActivity());
                            if (list != null) {
                                MusicUtils.playAll(getActivity(), list, 0);
                            }
                        } else {
                            MusicUtils.playPlaylist(getActivity(), id);
                        }
                    } catch (NumberFormatException e) {
                        Log.w(TAG, "Playlist id missing or broken");
                    }
                }
                getActivity().finish();
                return;
            }
            MusicUtils.updateNowPlaying(getActivity());
        }

        public void onServiceDisconnected(ComponentName classname) {
        }

    });

    IntentFilter f = new IntentFilter();
    f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    f.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    f.addDataScheme("file");
    getActivity().registerReceiver(mScanListener, f);

    lv = (ListView) view.findViewById(android.R.id.list);
    lv.setOnCreateContextMenuListener(this);
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            if (mCreateShortcut) {
                final Intent shortcut = new Intent();
                shortcut.setAction(Intent.ACTION_VIEW);
                shortcut.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/playlist");
                shortcut.putExtra("playlist", String.valueOf(id));

                final Intent intent = new Intent();
                intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
                intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                        ((TextView) view.findViewById(R.id.line1)).getText());
                intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource
                        .fromContext(getActivity(), R.drawable.ic_launcher_shortcut_music_playlist));

                getActivity().setResult(getActivity().RESULT_OK, intent);
                getActivity().finish();
                return;
            }
            if (id == RECENTLY_ADDED_PLAYLIST) {
                Intent intent = new Intent(Intent.ACTION_PICK);
                intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
                intent.putExtra("playlist", "recentlyadded");
                startActivity(intent);
            } else if (id == PODCASTS_PLAYLIST) {
                Intent intent = new Intent(Intent.ACTION_PICK);
                intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
                intent.putExtra("playlist", "podcasts");
                startActivity(intent);
            } else {
                Intent intent = new Intent(Intent.ACTION_EDIT);
                intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
                intent.putExtra("playlist", Long.valueOf(id).toString());
                startActivity(intent);
            }

        }
    });

    mAdapter = (PlaylistListAdapter) getActivity().getLastNonConfigurationInstance();
    if (mAdapter == null) {
        //Log.i("@@@", "starting query");
        mAdapter = new PlaylistListAdapter(getActivity().getApplication(), this, R.layout.track_list_item,
                mPlaylistCursor, new String[] { MediaStore.Audio.Playlists.NAME },
                new int[] { android.R.id.text1 });
        lv.setAdapter(mAdapter);
        //setTitle(R.string.working_playlists);
        getPlaylistCursor(mAdapter.getQueryHandler(), null);
    } else {
        mAdapter.setActivity(this);
        lv.setAdapter(mAdapter);
        mPlaylistCursor = mAdapter.getCursor();
        // If mPlaylistCursor is null, this can be because it doesn't have
        // a cursor yet (because the initial query that sets its cursor
        // is still in progress), or because the query failed.
        // In order to not flash the error dialog at the user for the
        // first case, simply retry the query when the cursor is null.
        // Worst case, we end up doing the same query twice.
        if (mPlaylistCursor != null) {
            init(mPlaylistCursor);
        } else {
            //setTitle(R.string.working_playlists);
            getPlaylistCursor(mAdapter.getQueryHandler(), null);
        }
    }

    return view;
}

From source file:com.josephblough.sbt.activities.ShortcutActivity.java

/** Called when the activity is first created. */
@Override/*from  w  ww  .java 2  s .  c  om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final String action = intent.getAction();

    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        // Create a shortcut
        //ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
        ShortcutAdapter adapter = new ShortcutAdapter(this, R.layout.shortcut_type_row, ITEMS);
        setListAdapter(adapter);

        getListView().setOnItemClickListener(this);
    } else {
        // Perform the search
        final int searchType = intent.getIntExtra(SEARCH_TYPE, 0);
        final String criteria = intent.getStringExtra(CRITERIA);
        try {
            performSearch(searchType, criteria);
        } catch (JSONException e) {
            Log.e(TAG, e.getMessage(), e);
            Toast.makeText(this, "There was an error reading search criteria", Toast.LENGTH_LONG).show();
        }
    }

}

From source file:com.markupartist.sthlmtraveling.PlannerFragment.java

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

    // If the activity was started with the "create shortcut" action, we
    // remember this to change the behavior upon a search.
    if (Intent.ACTION_CREATE_SHORTCUT.equals(getActivity().getIntent().getAction())) {
        mCreateShortcut = true;// w  ww .j a v a2 s.co  m
    }

    if (savedInstanceState != null) {
        mStackLevel = savedInstanceState.getInt("level");
    }

    CursorLoader cursorLoader = new CursorLoader(getActivity(), Journeys.CONTENT_URI, PROJECTION, null, //selection,
            null, //selectionArgs,
            Journeys.HISTORY_SORT_ORDER);
    Cursor cursor = cursorLoader.loadInBackground();
    mAdapter = new JourneyAdapter(getActivity(), cursor);
}

From source file:com.xabber.android.ui.activity.ContactList.java

@Override
public void onCreate(Bundle savedInstanceState) {
    if (Intent.ACTION_VIEW.equals(getIntent().getAction()) || Intent.ACTION_SEND.equals(getIntent().getAction())
            || Intent.ACTION_SENDTO.equals(getIntent().getAction())
            || Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
        ActivityManager.getInstance().startNewTask(this);
    }/* www.  jav  a 2s .  c o  m*/
    super.onCreate(savedInstanceState);

    if (isFinishing()) {
        return;
    }

    setContentView(R.layout.contact_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setOnClickListener(this);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.application_title_short,
            R.string.application_title_short);
    drawerLayout.setDrawerListener(drawerToggle);

    toolbar.inflateMenu(R.menu.contact_list);
    optionsMenu = toolbar.getMenu();
    setUpSearchView(optionsMenu);
    toolbar.setOnMenuItemClickListener(this);

    barPainter = new BarPainter(this, toolbar);
    barPainter.setDefaultColor();

    toolbar.setTitle(R.string.application_title_full);

    if (savedInstanceState != null) {
        sendText = savedInstanceState.getString(SAVED_SEND_TEXT);
        action = savedInstanceState.getString(SAVED_ACTION);
    } else {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new ContactListFragment(), CONTACT_LIST_TAG).commit();

        sendText = null;
        action = getIntent().getAction();
    }
    getIntent().setAction(null);
}

From source file:com.xabber.android.ui.activity.ContactListActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    if (Intent.ACTION_VIEW.equals(getIntent().getAction()) || Intent.ACTION_SEND.equals(getIntent().getAction())
            || Intent.ACTION_SENDTO.equals(getIntent().getAction())
            || Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
        ActivityManager.getInstance().startNewTask(this);
    }/*from w w  w.  java 2 s .  c o m*/
    super.onCreate(savedInstanceState);

    if (isFinishing()) {
        return;
    }

    setContentView(R.layout.activity_contact_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setOnClickListener(this);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.application_title_short,
            R.string.application_title_short);
    drawerLayout.setDrawerListener(drawerToggle);

    toolbar.inflateMenu(R.menu.toolbar_contact_list);
    optionsMenu = toolbar.getMenu();
    setUpSearchView(optionsMenu);
    toolbar.setOnMenuItemClickListener(this);
    toolbar.setOverflowIcon(getResources().getDrawable(R.drawable.ic_overflow_menu_white_24dp));

    barPainter = new BarPainter(this, toolbar);
    barPainter.setDefaultColor();

    toolbar.setTitle(R.string.application_title_full);

    if (savedInstanceState != null) {
        sendText = savedInstanceState.getString(SAVED_SEND_TEXT);
        action = savedInstanceState.getString(SAVED_ACTION);
    } else {
        getFragmentManager().beginTransaction().add(R.id.container, new ContactListFragment(), CONTACT_LIST_TAG)
                .commit();

        sendText = null;
        action = getIntent().getAction();
    }
    getIntent().setAction(null);
}