Example usage for android.net Uri EMPTY

List of usage examples for android.net Uri EMPTY

Introduction

In this page you can find the example usage for android.net Uri EMPTY.

Prototype

Uri EMPTY

To view the source code for android.net Uri EMPTY.

Click Source Link

Document

The empty URI, equivalent to "".

Usage

From source file:de.appplant.cordova.plugin.notification.Asset.java

/**
 * The URI for a resource./*from  w  w  w  .java2  s  .c  o  m*/
 * 
 * @param path
 *            The given relative path
 * 
 * @return The URI pointing to the given path
 */
private Uri getUriForResourcePath(String path) {
    String resPath = path.replaceFirst("res://", "");
    String fileName = resPath.substring(resPath.lastIndexOf('/') + 1);
    String resName = fileName.substring(0, fileName.lastIndexOf('.'));
    String extension = resPath.substring(resPath.lastIndexOf('.'));
    File dir = activity.getExternalCacheDir();
    if (dir == null) {
        Log.e("Asset", "Missing external cache dir");
        return Uri.EMPTY;
    }
    String storage = dir.toString() + STORAGE_FOLDER;
    int resId = getResId(resPath);
    File file = new File(storage, resName + extension);
    if (resId == 0) {
        Log.e("Asset", "File not found: " + resPath);
        return Uri.EMPTY;
    }
    new File(storage).mkdir();
    try {
        Resources res = activity.getResources();
        FileOutputStream outStream = new FileOutputStream(file);
        InputStream inputStream = res.openRawResource(resId);
        copyFile(inputStream, outStream);
        outStream.flush();
        outStream.close();
        return Uri.fromFile(file);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return Uri.EMPTY;
}

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;//  ww  w.  jav a 2s  .  com
    }

    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:android.net.ProxyInfo.java

/**
 * @hide/*from  w ww  .  ja va  2s  . c  o  m*/
 */
public boolean isValid() {
    if (!Uri.EMPTY.equals(mPacFileUrl))
        return true;
    return Proxy.PROXY_VALID == Proxy.validate(mHost == null ? "" : mHost,
            mPort == 0 ? "" : Integer.toString(mPort), mExclusionList == null ? "" : mExclusionList);
}

From source file:com.android.mail.ui.TwoPaneController.java

@Override
public void onFolderSelected(Folder folder) {
    // It's possible that we are not in conversation list mode
    if (mViewMode.getMode() != ViewMode.CONVERSATION_LIST) {
        mViewMode.enterConversationListMode();
    }//from   ww w  .j  a va  2s. c  o m

    if (folder.parent != Uri.EMPTY) {
        // Show the up affordance when digging into child folders.
        mActionBarView.setBackButton();
    }
    setHierarchyFolder(folder);
    super.onFolderSelected(folder);
}

From source file:org.yammp.fragment.QueryFragment.java

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();/*from w w  w. j  a  v  a2 s . com*/

    String action = bundle != null ? bundle.getString(INTENT_KEY_ACTION) : null;
    String data = bundle != null ? bundle.getString(INTENT_KEY_DATA) : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = Uri.parse(data);
        if (data.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            mUtils.playAll(list, 0);
            getActivity().finish();
            return;
        } else if (data.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            return;
        } else if (data.startsWith("content://media/external/audio/artists/")) {
            // This is an artist, show the albums for that artist
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
            i.putExtra("artist", uri.getLastPathSegment());
            startActivity(i);
            return;
        }
    }

    mFilterString = bundle != null ? bundle.getString(SearchManager.QUERY) : null;
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_FOCUS) : null;
        String artist = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ARTIST) : null;
        String album = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ALBUM) : null;
        String title = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_TITLE) : null;
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (Audio.Albums.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (Audio.Artists.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
}

From source file:android.net.ProxyInfo.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    if (!Uri.EMPTY.equals(mPacFileUrl)) {
        sb.append("PAC Script: ");
        sb.append(mPacFileUrl);//from w w  w . ja  v a  2 s  .com
    } else if (mHost != null) {
        sb.append("[");
        sb.append(mHost);
        sb.append("] ");
        sb.append(Integer.toString(mPort));
        if (mExclusionList != null) {
            sb.append(" xl=").append(mExclusionList);
        }
    } else {
        sb.append("[ProxyProperties.mHost == null]");
    }
    return sb.toString();
}

From source file:de.appplant.cordova.plugin.notification.Asset.java

/**
 *Get Uri for HTTP Content/*w  ww  . j  av  a 2 s . c  o m*/
 * @param path HTTP adress
 * @return Uri of the downloaded file
 */
private Uri getUriForHTTP(String path) {
    try {
        URL url = new URL(path);
        String fileName = path.substring(path.lastIndexOf('/') + 1);
        String resName = fileName.substring(0, fileName.lastIndexOf('.'));
        String extension = path.substring(path.lastIndexOf('.'));
        File dir = activity.getExternalCacheDir();
        if (dir == null) {
            Log.e("Asset", "Missing external cache dir");
            return Uri.EMPTY;
        }
        String storage = dir.toString() + STORAGE_FOLDER;
        File file = new File(storage, resName + extension);
        new File(storage).mkdir();

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

        StrictMode.setThreadPolicy(policy);

        connection.setDoInput(true);
        connection.connect();

        InputStream input = connection.getInputStream();
        FileOutputStream outStream = new FileOutputStream(file);
        copyFile(input, outStream);
        outStream.flush();
        outStream.close();

        return Uri.fromFile(file);
    } catch (MalformedURLException e) {
        Log.e("Asset", "Incorrect URL");
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        Log.e("Asset", "Failed to create new File from HTTP Content");
        e.printStackTrace();
    } catch (IOException e) {
        Log.e("Asset", "No Input can be created from http Stream");
        e.printStackTrace();
    }
    return Uri.EMPTY;
}

From source file:com.google.samples.apps.iosched.explore.ExploreIOFragment.java

@Override
public Uri getDataUri(final ExploreIOQueryEnum query) {
    switch (query) {
    case SESSIONS:
        return ScheduleContract.Sessions.CONTENT_URI;
    default://from w w  w. j av a 2s .  co m
        return Uri.EMPTY;
    }
}

From source file:org.musicmod.android.app.QueryFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {

    // Dialog doesn't allow us to wait for a result, so we need to store
    // the info we need for when the dialog posts its result
    mQueryCursor.moveToPosition(position);
    if (mQueryCursor.isBeforeFirst() || mQueryCursor.isAfterLast()) {
        return;//from w  w w. j a  va2s. c  om
    }
    String selectedType = mQueryCursor.getString(mQueryCursor.getColumnIndexOrThrow(Audio.Media.MIME_TYPE));

    if ("artist".equals(selectedType)) {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
        intent.putExtra("artist", Long.valueOf(id).toString());
        startActivity(intent);
    } else if ("album".equals(selectedType)) {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
        intent.putExtra("album", Long.valueOf(id).toString());
        startActivity(intent);
    } else if (position >= 0 && id >= 0) {
        long[] list = new long[] { id };
        MusicUtils.playAll(getActivity(), list, 0);
    } else {
        Log.e("QueryBrowser", "invalid position/id: " + position + "/" + id);
    }
}

From source file:android.net.ProxyInfo.java

@Override
public boolean equals(Object o) {
    if (!(o instanceof ProxyInfo))
        return false;
    ProxyInfo p = (ProxyInfo) o;// w ww . java 2 s  .co  m
    // If PAC URL is present in either then they must be equal.
    // Other parameters will only be for fall back.
    if (!Uri.EMPTY.equals(mPacFileUrl)) {
        return mPacFileUrl.equals(p.getPacFileUrl()) && mPort == p.mPort;
    }
    if (!Uri.EMPTY.equals(p.mPacFileUrl)) {
        return false;
    }
    if (mExclusionList != null && !mExclusionList.equals(p.getExclusionListAsString())) {
        return false;
    }
    if (mHost != null && p.getHost() != null && mHost.equals(p.getHost()) == false) {
        return false;
    }
    if (mHost != null && p.mHost == null)
        return false;
    if (mHost == null && p.mHost != null)
        return false;
    if (mPort != p.mPort)
        return false;
    return true;
}