Java Code Examples for android.content.ContentUris#parseId()

The following examples show how to use android.content.ContentUris#parseId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PersistentBlobProvider.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public boolean delete(@NonNull Uri uri) {
    switch (MATCHER.match(uri)) {
        case MATCH_OLD:
        case MATCH_NEW:
            long id = ContentUris.parseId(uri);
            cache.remove(id);
            return getFile(ContentUris.parseId(uri)).delete();
        default:
            break;
    }

    if (isExternalBlobUri(context, uri)) {
        String fileAuthority = BuildConfig.BCM_APPLICATION_ID + ".fileprovider";
        if (fileAuthority.equals(uri.getAuthority())) {
            return context.getContentResolver().delete(uri, null, null) > 0;
        }else {
            return new File(uri.getPath()).delete();
        }
    }

    return false;
}
 
Example 2
Source File: XmppFriendMessageProvider.java    From xmpp with Apache License 2.0 6 votes vote down vote up
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    int num = 0;
    switch (matcher.match(uri)) {

        case CHAT:
            long id = ContentUris.parseId(uri);
            String whereClause = "id=" + id;
            if (selection != null && !selection.equals("")) {
                whereClause = whereClause + "and" + selection;
            }
            num = db.delete("chat", whereClause, selectionArgs);

            break;

        case CHATS:
            num = db.delete("chat", selection, selectionArgs);

            break;

        default:
            throw new IllegalArgumentException("未知uri:" + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return num;
}
 
Example 3
Source File: ContactListManagerAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
/**
public Contact[] createTemporaryContacts(String[] addresses) {
    Contact[] contacts = mAdaptee.createTemporaryContacts(addresses);

    for (Contact c : contacts)
        insertTemporary(c);
    return contacts;
}**/

public long queryOrInsertContact(Contact c) {
    long result;

    String username = mAdaptee.normalizeAddress(c.getAddress().getAddress());
    String selection = Imps.Contacts.USERNAME + "=?";
    String[] selectionArgs = { username };
    String[] projection = { Imps.Contacts._ID };

    Cursor cursor = mResolver.query(mContactUrl, projection, selection, selectionArgs, null);

    if (cursor != null && cursor.moveToFirst()) {
        result = cursor.getLong(0);
    } else {
       // result = insertContactContent(c);
        Uri uriNewContact = insertContactContent(c, FAKE_TEMPORARY_LIST_ID, Imps.Contacts.TYPE_NORMAL, Imps.Contacts.SUBSCRIPTION_TYPE_NONE, Imps.Contacts.SUBSCRIPTION_STATUS_SUBSCRIBE_PENDING);
        result = ContentUris.parseId(uriNewContact);

    }

    if (cursor != null) {
        cursor.close();
    }
    return result;
}
 
Example 4
Source File: TestProvider.java    From Popular-Movies-App with Apache License 2.0 6 votes vote down vote up
public void testDeleteAllMovies() {
    ContentValues testValues = TestUtilities.createTestMovieValues();
    Uri movieUri = mContext.getContentResolver().insert(MoviesContract.MovieEntry.CONTENT_URI, testValues);
    assertTrue(movieUri != null);
    long id = ContentUris.parseId(movieUri);
    assertTrue(id != -1);
    assertEquals(MoviesContract.MovieEntry.buildMovieUri(id), movieUri);

    TestUtilities.TestContentObserver moviesObserver = TestUtilities.getTestContentObserver();
    mContext.getContentResolver().registerContentObserver(MoviesContract.MovieEntry.CONTENT_URI, true, moviesObserver);

    TestUtilities.TestContentObserver movieByIdObserver = TestUtilities.getTestContentObserver();
    mContext.getContentResolver().registerContentObserver(movieUri, true, movieByIdObserver);

    deleteAllRecordsFromProvider();

    moviesObserver.waitForNotificationOrFail();
    movieByIdObserver.waitForNotificationOrFail();

    mContext.getContentResolver().unregisterContentObserver(moviesObserver);
    mContext.getContentResolver().unregisterContentObserver(movieByIdObserver);
}
 
Example 5
Source File: TestProvider.java    From Popular-Movies-App with Apache License 2.0 5 votes vote down vote up
public void testDeleteMostPopularMovies() {
    ContentValues testValues = TestUtilities.createTestMovieValues();
    Uri movieUri = mContext.getContentResolver().insert(MoviesContract.MovieEntry.CONTENT_URI, testValues);
    assertTrue(movieUri != null);
    long movieRowId = ContentUris.parseId(movieUri);
    assertTrue(movieRowId != -1);

    ContentValues entryValues = new ContentValues();
    entryValues.put(MoviesContract.COLUMN_MOVIE_ID_KEY, movieRowId);

    Uri entryUri = mContext.getContentResolver().insert(MoviesContract.MostPopularMovies.CONTENT_URI, entryValues);
    assertTrue(entryUri != null);

    TestUtilities.TestContentObserver observer = TestUtilities.getTestContentObserver();
    mContext.getContentResolver().registerContentObserver(MoviesContract.MostPopularMovies.CONTENT_URI, true, observer);

    mContext.getContentResolver().delete(
            MoviesContract.MostPopularMovies.CONTENT_URI,
            null,
            null
    );

    // Did our content observer get called?
    observer.waitForNotificationOrFail();
    mContext.getContentResolver().unregisterContentObserver(observer);

    Cursor movies = mContext.getContentResolver().query(
            MoviesContract.MostPopularMovies.CONTENT_URI,
            null, // leaving "columns" null just returns all the columns.
            null, // cols for "where" clause
            null, // values for "where" clause
            null  // sort order
    );
    assertNotNull(movies);
    assertTrue(movies.getCount() == 0);

    movies.close();
}
 
Example 6
Source File: LauncherProvider.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
SqlArguments(Uri url, String where, String[] args) {
    if (url.getPathSegments().size() == 1) {
        this.table = url.getPathSegments().get(0);
        this.where = where;
        this.args = args;
    } else if (url.getPathSegments().size() != 2) {
        throw new IllegalArgumentException("Invalid URI: " + url);
    } else if (!TextUtils.isEmpty(where)) {
        throw new UnsupportedOperationException("WHERE clause not supported: " + url);
    } else {
        this.table = url.getPathSegments().get(0);
        this.where = "_id=" + ContentUris.parseId(url);
        this.args = null;
    }
}
 
Example 7
Source File: DataProvider.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    logger.debug("update({})", uri);
    if (uriMatcher.match(uri) != MAP_OBJECTS_ID) {
        if (uriMatcher.match(uri) == MAP_OBJECTS)
            throw new UnsupportedOperationException("Currently only updating one object by ID is supported");
        else
            throw new IllegalArgumentException("Unknown URI " + uri);
    }

    if (values == null) {
        throw new IllegalArgumentException("Values can not be null");
    }
    long id = ContentUris.parseId(uri);

    MapObject mo = MapTrek.getMapObject(id);
    if (mo == null)
        return 0;

    populateFields(mo, values);
    EventBus.getDefault().post(new MapObject.UpdatedEvent(mo));

    Context context = getContext();
    if (context != null)
        context.getContentResolver().notifyChange(uri, null);
    return 1;
}
 
Example 8
Source File: ImConnectionAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onGroupInvitation(Invitation invitation) {
    String sender = invitation.getSender().getUser();
    ContentValues values = new ContentValues(7);
    values.put(Imps.Invitation.PROVIDER, mProviderId);
    values.put(Imps.Invitation.ACCOUNT, mAccountId);
    values.put(Imps.Invitation.INVITE_ID, invitation.getInviteID());
    values.put(Imps.Invitation.SENDER, sender);
    values.put(Imps.Invitation.GROUP_NAME, invitation.getGroupAddress().getUser());
    values.put(Imps.Invitation.NOTE, invitation.getReason());
    values.put(Imps.Invitation.STATUS, Imps.Invitation.STATUS_PENDING);
    ContentResolver resolver = mService.getContentResolver();
    Uri uri = resolver.insert(Imps.Invitation.CONTENT_URI, values);
    long id = ContentUris.parseId(uri);
    try {
        if (mRemoteListener != null) {
            mRemoteListener.onGroupInvitation(id);
            return;
        }
    } catch (RemoteException e) {
        RemoteImService.debug("onGroupInvitation: dead listener " + mRemoteListener
                              + "; removing", e);
        mRemoteListener = null;
    }
    // No listener registered or failed to notify the listener, send a
    // notification instead.
    mService.getStatusBarNotifier().notifyGroupInvitation(mProviderId, mAccountId, id,
            sender);
}
 
Example 9
Source File: CalendarWriteTester.java    From PermissionAgent with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    try {
        TimeZone timeZone = TimeZone.getDefault();
        ContentValues value = new ContentValues();
        value.put(CalendarContract.Calendars.NAME, NAME);
        value.put(CalendarContract.Calendars.ACCOUNT_NAME, ACCOUNT);
        value.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
        value.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, NAME);
        value.put(CalendarContract.Calendars.VISIBLE, 1);
        value.put(CalendarContract.Calendars.CALENDAR_COLOR, Color.BLUE);
        value.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
        value.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
        value.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, timeZone.getID());
        value.put(CalendarContract.Calendars.OWNER_ACCOUNT, NAME);
        value.put(CalendarContract.Calendars.CAN_ORGANIZER_RESPOND, 0);

        Uri insertUri = CalendarContract.Calendars.CONTENT_URI.buildUpon()
            .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, NAME)
            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
            .build();
        Uri resourceUri = mResolver.insert(insertUri, value);
        return ContentUris.parseId(resourceUri) > 0;
    } finally {
        Uri deleteUri = CalendarContract.Calendars.CONTENT_URI.buildUpon().build();
        mResolver.delete(deleteUri, CalendarContract.Calendars.ACCOUNT_NAME + "=?", new String[] {ACCOUNT});
    }
}
 
Example 10
Source File: CallLogWriteTester.java    From PermissionAgent with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    try {
        ContentValues content = new ContentValues();
        content.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
        content.put(CallLog.Calls.NUMBER, "1");
        content.put(CallLog.Calls.DATE, 20080808);
        content.put(CallLog.Calls.NEW, "0");
        Uri resourceUri = mResolver.insert(CallLog.Calls.CONTENT_URI, content);
        return ContentUris.parseId(resourceUri) > 0;
    } finally {
        mResolver.delete(CallLog.Calls.CONTENT_URI, CallLog.Calls.NUMBER + "=?", new String[] {"1"});
    }
}
 
Example 11
Source File: CalendarWriteTest.java    From AndPermission with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    try {
        TimeZone timeZone = TimeZone.getDefault();
        ContentValues value = new ContentValues();
        value.put(CalendarContract.Calendars.NAME, NAME);
        value.put(CalendarContract.Calendars.ACCOUNT_NAME, ACCOUNT);
        value.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
        value.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, NAME);
        value.put(CalendarContract.Calendars.VISIBLE, 1);
        value.put(CalendarContract.Calendars.CALENDAR_COLOR, Color.BLUE);
        value.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
        value.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
        value.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, timeZone.getID());
        value.put(CalendarContract.Calendars.OWNER_ACCOUNT, NAME);
        value.put(CalendarContract.Calendars.CAN_ORGANIZER_RESPOND, 0);

        Uri insertUri = CalendarContract.Calendars.CONTENT_URI.buildUpon()
            .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, NAME)
            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
            .build();
        Uri resourceUri = mResolver.insert(insertUri, value);
        return ContentUris.parseId(resourceUri) > 0;
    } finally {
        Uri deleteUri = CalendarContract.Calendars.CONTENT_URI.buildUpon().build();
        mResolver.delete(deleteUri, CalendarContract.Calendars.ACCOUNT_NAME + "=?", new String[]{ACCOUNT});
    }
}
 
Example 12
Source File: CalendarWriteTester.java    From PermissionAgent with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    try {
        TimeZone timeZone = TimeZone.getDefault();
        ContentValues value = new ContentValues();
        value.put(CalendarContract.Calendars.NAME, NAME);
        value.put(CalendarContract.Calendars.ACCOUNT_NAME, ACCOUNT);
        value.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
        value.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, NAME);
        value.put(CalendarContract.Calendars.VISIBLE, 1);
        value.put(CalendarContract.Calendars.CALENDAR_COLOR, Color.BLUE);
        value.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
        value.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
        value.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, timeZone.getID());
        value.put(CalendarContract.Calendars.OWNER_ACCOUNT, NAME);
        value.put(CalendarContract.Calendars.CAN_ORGANIZER_RESPOND, 0);

        Uri insertUri = CalendarContract.Calendars.CONTENT_URI.buildUpon()
            .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, NAME)
            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
            .build();
        Uri resourceUri = mResolver.insert(insertUri, value);
        return ContentUris.parseId(resourceUri) > 0;
    } finally {
        Uri deleteUri = CalendarContract.Calendars.CONTENT_URI.buildUpon().build();
        mResolver.delete(deleteUri, CalendarContract.Calendars.ACCOUNT_NAME + "=?", new String[] {ACCOUNT});
    }
}
 
Example 13
Source File: AutoContentLoader.java    From NekoSMS with GNU General Public License v3.0 5 votes vote down vote up
public Uri insert(Context context, T data) {
    ContentResolver contentResolver = context.getContentResolver();
    ContentValues values = serialize(data);
    Uri uri = contentResolver.insert(getContentUri(), values);
    long id = -1;
    if (uri != null) {
        id = ContentUris.parseId(uri);
    }
    if (id < 0) {
        return null;
    } else {
        return uri;
    }
}
 
Example 14
Source File: TestProvider.java    From Popular-Movies-App with Apache License 2.0 5 votes vote down vote up
public void testDeleteFavorites() {
    ContentValues testValues = TestUtilities.createTestMovieValues();
    Uri movieUri = mContext.getContentResolver().insert(MoviesContract.MovieEntry.CONTENT_URI, testValues);
    assertTrue(movieUri != null);
    long movieRowId = ContentUris.parseId(movieUri);
    assertTrue(movieRowId != -1);

    ContentValues entryValues = new ContentValues();
    entryValues.put(MoviesContract.COLUMN_MOVIE_ID_KEY, movieRowId);

    Uri entryUri = mContext.getContentResolver().insert(MoviesContract.Favorites.CONTENT_URI, entryValues);
    assertTrue(entryUri != null);

    TestUtilities.TestContentObserver observer = TestUtilities.getTestContentObserver();
    mContext.getContentResolver().registerContentObserver(MoviesContract.Favorites.CONTENT_URI, true, observer);

    mContext.getContentResolver().delete(
            MoviesContract.Favorites.CONTENT_URI,
            null,
            null
    );

    // Did our content observer get called?
    observer.waitForNotificationOrFail();
    mContext.getContentResolver().unregisterContentObserver(observer);

    Cursor movies = mContext.getContentResolver().query(
            MoviesContract.Favorites.CONTENT_URI,
            null, // leaving "columns" null just returns all the columns.
            null, // cols for "where" clause
            null, // values for "where" clause
            null  // sort order
    );
    assertNotNull(movies);
    assertTrue(movies.getCount() == 0);

    movies.close();
}
 
Example 15
Source File: ChatSessionAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
private long insertOrUpdateGroupContactInDb(ChatGroup group, boolean isNewSession) {
    // Insert a record in contacts table
    ContentValues values = new ContentValues(4);
    values.put(Imps.Contacts.USERNAME, group.getAddress().getAddress());
    values.put(Imps.Contacts.NICKNAME, group.getName());
    values.put(Imps.Contacts.CONTACTLIST, ContactListManagerAdapter.LOCAL_GROUP_LIST_ID);
    if (isNewSession) {
        values.put(Imps.Contacts.TYPE, Imps.Contacts.TYPE_GROUP | Imps.Contacts.TYPE_FLAG_UNSEEN);
    } else {
        values.put(Imps.Contacts.TYPE, Imps.Contacts.TYPE_GROUP);
    }
    Uri contactUri = ContentUris.withAppendedId(
            ContentUris.withAppendedId(Imps.Contacts.CONTENT_URI, mConnection.mProviderId),
            mConnection.mAccountId);
  
    ContactListManagerAdapter listManager = (ContactListManagerAdapter) mConnection
            .getContactListManager();
    
    long id = listManager.queryGroup(group);
    
    if (id == -1)
    {
        id = ContentUris.parseId(mContentResolver.insert(contactUri, values));
    }

    for (Contact member : group.getMembers()) {
        insertGroupMemberInDb(member);
    }

    return id;
}
 
Example 16
Source File: PermissionsChecker.java    From permissions4m with Apache License 2.0 5 votes vote down vote up
/**
 * write and delete contacts info, {@link android.Manifest.permission#WRITE_CONTACTS}
 * and we should get read contacts permission first.
 *
 * @param activity
 * @return true if success
 * @throws Exception
 */
private static boolean checkWriteContacts(Activity activity) throws Exception {
    if (checkReadContacts(activity)) {
        // write some info
        ContentValues values = new ContentValues();
        ContentResolver contentResolver = activity.getContentResolver();
        Uri rawContactUri = contentResolver.insert(ContactsContract.RawContacts
                .CONTENT_URI, values);
        long rawContactId = ContentUris.parseId(rawContactUri);
        values.put(ContactsContract.Contacts.Data.MIMETYPE, ContactsContract.CommonDataKinds
                .StructuredName.CONTENT_ITEM_TYPE);
        values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId);
        values.put(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, TAG);
        values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, TAG_NUMBER);
        contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);

        // delete info
        Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
        ContentResolver resolver = activity.getContentResolver();
        Cursor cursor = resolver.query(uri, new String[]{ContactsContract.Contacts.Data._ID},
                "display_name=?", new String[]{TAG}, null);
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                int id = cursor.getInt(0);
                resolver.delete(uri, "display_name=?", new String[]{TAG});
                uri = Uri.parse("content://com.android.contacts/data");
                resolver.delete(uri, "raw_contact_id=?", new String[]{id + ""});
            }
            cursor.close();
        }
        return true;
    } else {
        return false;
    }
}
 
Example 17
Source File: TestProvider.java    From Popular-Movies-App with Apache License 2.0 5 votes vote down vote up
public void testInsertMostRatedMovie() {
    ContentValues testValues = TestUtilities.createTestMovieValues();
    Uri movieUri = mContext.getContentResolver().insert(MoviesContract.MovieEntry.CONTENT_URI, testValues);
    assertTrue(movieUri != null);
    long movieRowId = ContentUris.parseId(movieUri);
    assertTrue(movieRowId != -1);

    TestUtilities.TestContentObserver observer = TestUtilities.getTestContentObserver();
    mContext.getContentResolver().registerContentObserver(MoviesContract.MostRatedMovies.CONTENT_URI, true, observer);

    ContentValues entryValues = new ContentValues();
    entryValues.put(MoviesContract.COLUMN_MOVIE_ID_KEY, movieRowId);

    Uri entryUri = mContext.getContentResolver().insert(MoviesContract.MostRatedMovies.CONTENT_URI, entryValues);
    assertTrue(entryUri != null);

    // Did our content observer get called?
    observer.waitForNotificationOrFail();
    mContext.getContentResolver().unregisterContentObserver(observer);

    Cursor movies = mContext.getContentResolver().query(
            MoviesContract.MostRatedMovies.CONTENT_URI,
            null, // leaving "columns" null just returns all the columns.
            null, // cols for "where" clause
            null, // values for "where" clause
            null  // sort order
    );
    assertNotNull(movies);
    TestUtilities.validateCursor("Error validating MovieEntry", movies, entryValues);

    movies.close();
}
 
Example 18
Source File: CommonUtils.java    From SmartChart with Apache License 2.0 5 votes vote down vote up
/**
 * 往手机通讯录插入联系人
 *
 * @param ct
 * @param name
 * @param tel
 * @param email
 */
public static void insertContact(Context ct, String name, String tel, String email) {
    ContentValues values = new ContentValues();
    // 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
    Uri rawContactUri = ct.getContentResolver().insert(RawContacts.CONTENT_URI, values);
    long rawContactId = ContentUris.parseId(rawContactUri);
    // 往data表入姓名数据
    if (!TextUtils.isEmpty(tel)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);// 内容类型
        values.put(StructuredName.GIVEN_NAME, name);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
    // 往data表入电话数据
    if (!TextUtils.isEmpty(tel)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);// 内容类型
        values.put(Phone.NUMBER, tel);
        values.put(Phone.TYPE, Phone.TYPE_MOBILE);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
    // 往data表入Email数据
    if (!TextUtils.isEmpty(email)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);// 内容类型
        values.put(Email.DATA, email);
        values.put(Email.TYPE, Email.TYPE_WORK);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
}
 
Example 19
Source File: ChannelContents.java    From leanback-showcase with Apache License 2.0 4 votes vote down vote up
/**
 * A transaction id will be assigned to the added channel
 */
private Long addChannel(Context context, ChannelContents channelContents) {
    // This ID is associated with current context
    String channelInputId = createInputId(context);
    Channel channel = new Channel.Builder()
            .setDisplayName(channelContents.getName())
            .setDescription(channelContents.getDescription())
            .setType(TvContractCompat.Channels.TYPE_PREVIEW)
            .setInputId(channelInputId)
            .setAppLinkIntentUri(Uri.parse(SCHEME + "://" + PACKAGE_NAME
                    + "/" + MAIN_ACTIVITY))
            .setInternalProviderId(channelContents.getChannelContentsId())
            .build();

    /**
     * The interaction between current app and launcher interface is through ContentProvider
     * All the published data should be inserted into content provider
     */
    Uri channelUri = context.getContentResolver().insert(TvContractCompat.Channels.CONTENT_URI,
            channel.toContentValues());
    if (channelUri == null || channelUri.equals(Uri.EMPTY)) {
        Log.e(TAG, "Insert channel failed");
        /**
         * If the task is failed return null as a signal for error handling
         */
        return null;
    }
    long channelId = ContentUris.parseId(channelUri);
    sLookupTable.put(channelId, channelContents);
    channelContents.setChannelPublishedId(channelId);

    createChannelLogo(context, channelId, R.drawable.row_app_icon);

    List<VideoContent> videos = channelContents.getVideos();

    int weight = videos.size();
    for (int i = 0; i < videos.size(); ++i, --weight) {
        VideoContent clip = videos.get(i);
        final String clipId = clip.getVideoId();

        /**
         * Enable preview feature for the video added to the home screen
         */
        PreviewProgram program = new PreviewProgram.Builder()
                .setChannelId(channelId)
                .setTitle(clip.getTitle())
                .setDescription(clip.getDescription())
                .setPosterArtUri(Uri.parse(clip.getCardImageUrl()))
                .setIntentUri(Uri.parse(SCHEME + "://" + PACKAGE_NAME
                        + "/" + VIDEO_PLAY_ACTIVITY + "/" + clipId))
                .setPreviewVideoUri(Uri.parse(clip.getPreviewVideoUrl()))
                .setInternalProviderId(clipId)
                .setWeight(weight)
                .setPosterArtAspectRatio(clip.getAspectRatio())
                .setType(TvContractCompat.PreviewPrograms.TYPE_MOVIE)
                .build();

        Uri preview_uri =
                Uri.parse(CONTENT_ANDROID_MEDIA_TV_PREVIEW_PROGRAM);
        Uri programUri = context.getContentResolver().insert(preview_uri,
                program.toContentValues());
        if (programUri == null || programUri.equals(Uri.EMPTY)) {
            Log.e(TAG, "Insert program failed");
        } else {
            clip.setProgramId(ContentUris.parseId(programUri));
        }
    }
    return channelId;
}
 
Example 20
Source File: ChatSessionAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
public long getId() {
    return ContentUris.parseId(mChatURI);
}