Example usage for android.content ContentUris appendId

List of usage examples for android.content ContentUris appendId

Introduction

In this page you can find the example usage for android.content ContentUris appendId.

Prototype

public static Uri.Builder appendId(Uri.Builder builder, long id) 

Source Link

Document

Appends the given ID to the end of the path.

Usage

From source file:Main.java

private static Uri getInstancesUri(final String getDataMilliSeconds) {
    final Uri.Builder builder = Instances.CONTENT_URI.buildUpon();
    // StartDate/*w w w. j  av  a2s .  c  om*/
    ContentUris.appendId(builder, Long.valueOf(getDataMilliSeconds));
    // EndDate
    ContentUris.appendId(builder, Long.valueOf(getDataMilliSeconds));
    return builder.build();
}

From source file:Main.java

public static void addToCalendar(Activity context, Long beginTime, String title) {
    ContentResolver cr = context.getContentResolver();

    Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
    Long time = new Date(beginTime).getTime();
    ContentUris.appendId(builder, time - 10 * 60 * 1000);
    ContentUris.appendId(builder, time + 10 * 60 * 1000);

    String[] projection = new String[] { "title", "begin" };
    Cursor cursor = cr.query(builder.build(), projection, null, null, null);

    boolean exists = false;
    if (cursor != null) {
        while (cursor.moveToNext()) {
            if ((time == cursor.getLong(1)) && title.equals(cursor.getString(0))) {
                exists = true;/*from  w w  w  .ja  v  a2s.co m*/
            }
        }
    }

    if (!exists) {
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", time);
        intent.putExtra("allDay", false);
        intent.putExtra("endTime", time + 60 * 60 * 1000);
        intent.putExtra("title", title);
        context.startActivity(intent);
    } else {
        Toast.makeText(context, "Event already exist!", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

static Intent createOpenCalendarAtDayIntent(Context context, DateTime goToTime) {
    Intent launchIntent = createCalendarIntent(Intent.ACTION_VIEW);
    Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
    builder.appendPath(TIME);//from w  w w .j  a va  2 s. co  m
    if (goToTime.getMillis() != 0) {
        launchIntent.putExtra(KEY_DETAIL_VIEW, true);
        ContentUris.appendId(builder, goToTime.getMillis());
    }
    launchIntent.setData(builder.build());
    return launchIntent;
}

From source file:com.pindroid.platform.NoteManager.java

public static Note GetById(int id, Context context) throws ContentNotFoundException {
    final String[] projection = new String[] { Note.Account, Note.Title, Note.Text, Note.Pid, Note.Hash,
            Note.Added, Note.Updated };//from   www  .jav a 2  s.  c  o  m

    Uri uri = ContentUris.appendId(Note.CONTENT_URI.buildUpon(), id).build();

    Cursor c = context.getContentResolver().query(uri, projection, null, null, null);

    if (c.moveToFirst()) {
        final int accountColumn = c.getColumnIndex(Note.Account);
        final int titleColumn = c.getColumnIndex(Note.Title);
        final int textColumn = c.getColumnIndex(Note.Text);
        final int pidColumn = c.getColumnIndex(Note.Pid);
        final int hashColumn = c.getColumnIndex(Note.Hash);
        final int addedColumn = c.getColumnIndex(Note.Added);
        final int updatedColumn = c.getColumnIndex(Note.Updated);

        Note n = new Note(id, c.getString(titleColumn), c.getString(textColumn), c.getString(accountColumn),
                c.getString(hashColumn), c.getString(pidColumn), c.getLong(addedColumn),
                c.getLong(updatedColumn));

        c.close();

        return n;
    } else {
        c.close();
        throw new ContentNotFoundException();
    }
}

From source file:com.jefftharris.passwdsafe.sync.GDriveLaunchActivity.java

@Override
protected void onCreate(Bundle args) {
    super.onCreate(args);

    Intent intent = getIntent();/*from   w  ww.jav  a 2s. c om*/
    String action = intent.getAction();
    boolean doFinish = true;
    if (action.equals("com.google.android.apps.drive.DRIVE_OPEN")) {
        String fileId = intent.getStringExtra("resourceId");
        PasswdSafeUtil.dbginfo(TAG, "Open GDrive file %s", fileId);

        Pair<DbProvider, DbFile> rc = getFile(fileId);
        if (rc != null) {
            Uri uri = PasswdSafeContract.Providers.CONTENT_URI;
            Uri.Builder builder = uri.buildUpon();
            ContentUris.appendId(builder, rc.first.itsId);
            builder.appendPath(PasswdSafeContract.Files.TABLE);
            ContentUris.appendId(builder, rc.second.itsId);
            uri = builder.build();
            PasswdSafeUtil.dbginfo(TAG, "uri %s", uri);
            Intent viewIntent = PasswdSafeUtil.createOpenIntent(uri, null);
            try {
                startActivity(viewIntent);
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "Can not open file", e);
            }
        } else {
            PasswdSafeUtil.showFatalMsg(getString(R.string.cant_launch_drive_file), this);
            doFinish = false;
        }
    }
    if (doFinish) {
        finish();
    }
}

From source file:com.googlecode.android_scripting.facade.SmsFacade.java

private Uri buildMessageUri(Integer id) {
    Uri.Builder builder = Uri.parse("content://sms").buildUpon();
    ContentUris.appendId(builder, id);
    Uri uri = builder.build();/*from w  ww  .  j  a v  a 2s . c o m*/
    return uri;
}

From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java

public static Uri getAvatarUri(Uri baseUri, long providerId, long accountId) {
    Uri.Builder builder = baseUri.buildUpon();
    ContentUris.appendId(builder, providerId);
    ContentUris.appendId(builder, accountId);
    return builder.build();
}

From source file:org.birthdayadapter.ui.BasePreferenceFragment.java

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

    mActivity = (BaseActivity) getActivity();
    mAccountHelper = new AccountHelper(mActivity, mActivity.mBackgroundStatusHandler);

    // if this is the first run, enable and sync birthday adapter!
    if (PreferencesHelper.getFirstRun(mActivity)) {
        PreferencesHelper.setFirstRun(mActivity, false);

        addAccountAndSync();//from   ww  w . j  av a 2s . co  m
    }

    mEnabled = (SwitchPreferenceCompat) findPreference(getString(R.string.pref_enabled_key));
    mEnabled.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue instanceof Boolean) {
                Boolean boolVal = (Boolean) newValue;

                if (boolVal) {
                    addAccountAndSync();
                } else {
                    mAccountHelper.removeAccount();
                }
            }
            return true;
        }
    });

    Preference openContacts = findPreference(getString(R.string.pref_contacts_key));
    openContacts.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(Intent.ACTION_VIEW, ContactsContract.Contacts.CONTENT_URI);
            startActivity(intent);
            return true;
        }
    });

    Preference openCalendar = findPreference(getString(R.string.pref_calendar_key));
    openCalendar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @SuppressLint("NewApi")
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
            builder.appendPath("time");
            ContentUris.appendId(builder, Calendar.getInstance().getTimeInMillis());
            Intent intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
            startActivity(intent);
            return true;
        }
    });

}

From source file:com.group13.androidsdk.mycards.NotificationService.java

private List<NotificationRule> getCalendarAsNotificationRules() {
    Calendar beginTime = Calendar.getInstance();
    beginTime.set(Calendar.HOUR_OF_DAY, 0);
    beginTime.set(Calendar.MINUTE, 0);
    beginTime.set(Calendar.SECOND, 0);
    long startMillis = beginTime.getTimeInMillis();

    Calendar endTime = Calendar.getInstance();
    endTime.set(Calendar.HOUR_OF_DAY, 23);
    endTime.set(Calendar.MINUTE, 59);
    endTime.set(Calendar.SECOND, 59);
    long endMillis = endTime.getTimeInMillis();

    Cursor cur;/*from w  w  w.j a  v a2s  .co m*/
    ContentResolver cr = getContentResolver();

    String selection = Instances.CALENDAR_ID + " = 1";
    String[] selectionArgs = new String[] {};

    Uri.Builder builder = CalendarContract.Instances.CONTENT_URI.buildUpon();
    ContentUris.appendId(builder, startMillis);
    ContentUris.appendId(builder, endMillis);

    cur = cr.query(builder.build(), INSTANCE_PROJECTION, selection, selectionArgs, null);

    List<NotificationRule> rules = new ArrayList<>();

    if (cur == null) {
        return rules;
    }

    while (cur.moveToNext()) {
        Calendar beginCalendar = Calendar.getInstance();
        beginCalendar.setTimeInMillis(cur.getLong(PROJECTION_BEGIN_INDEX));

        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTimeInMillis(cur.getLong(PROJECTION_END_INDEX));

        SimpleDatePattern datePattern = new SimpleDatePattern(beginCalendar.getTime(), endCalendar.getTime(), 0,
                0);
        rules.add(new NotificationRule(-1, datePattern, true));
    }
    cur.close();
    return rules;
}

From source file:com.vignesh.conf.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    List<String> list = new ArrayList<>();
    final ListView listView = (ListView) findViewById(R.id.info);
    Cursor cursor;//  w ww . j a v a 2  s.c  o m
    long time = new Date().getTime();
    ContentResolver contentResolver = getContentResolver();
    Uri uri = CalendarContract.Calendars.CONTENT_URI;
    SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(getApplicationContext());
    String cal = sharedPreferences.getString(CALENDAR_NAME, getResources().getString(R.string.no_calendar));
    String selection = "((" + CalendarContract.Calendars.ACCOUNT_NAME + " = ?))";
    int hours_before = Integer.valueOf(sharedPreferences.getString("past_hours", "2"));
    int hours_future = Integer.valueOf(sharedPreferences.getString("future_hours", "24"));
    String[] selectionArgs = new String[] { cal };

    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(getApplicationContext(), "No calendar permission", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    if (ActivityCompat.checkSelfPermission(getApplicationContext(),
            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(getApplicationContext(), "No calling permission", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    cursor = contentResolver.query(uri, CAL_PROJECTION, selection, selectionArgs, null);
    assert cursor != null;
    while (cursor.moveToNext()) {
        long calID = 0;

        // Get the field values
        calID = cursor.getLong(PROJECTION_ID_INDEX);

        Uri.Builder instanceUriBuilder = CalendarContract.Instances.CONTENT_URI.buildUpon();
        ContentUris.appendId(instanceUriBuilder, time - hours_before * 60 * 60 * 1000);
        ContentUris.appendId(instanceUriBuilder, time + hours_future * 60 * 60 * 1000);
        Uri instanceUri = instanceUriBuilder.build();
        String instanceSelection = "((" + CalendarContract.Instances.CALENDAR_ID + "= ?))";
        String[] instanceSelectionArgs = new String[] { "" + calID };
        Cursor instanceCursor = contentResolver.query(instanceUri, INSTANCE_PROJECTION, instanceSelection,
                instanceSelectionArgs, CalendarContract.Instances.BEGIN + " ASC");
        assert instanceCursor != null;
        while (instanceCursor.moveToNext()) {
            String title = instanceCursor.getString(1);
            Date begin = new Date(instanceCursor.getLong(2));
            Date end = new Date(instanceCursor.getLong(3));
            String loc = instanceCursor.getString(4);
            String desc = instanceCursor.getString(5);
            String full = title + "\n" + loc + "\n" + desc;
            Pattern passcodePattern = Pattern
                    .compile(sharedPreferences.getString(REGEX, "(\\d{8})[\\s\\t\\n#]"));
            Matcher passcodeMatcher = passcodePattern.matcher(full);
            String list_item = (title + "\n" + "START: " + begin + "\nEND: " + end + "\n");
            if (passcodeMatcher.find())
                list.add(list_item + "Conf code: " + passcodeMatcher.group().trim() + "\n");
        }
        instanceCursor.close();
    }
    cursor.close();
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getApplicationContext(), R.layout.list_layout, list);
    assert listView != null;
    listView.setAdapter(arrayAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String s = (String) parent.getItemAtPosition(position);
            SharedPreferences sharedPreferences = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext());
            String tel = sharedPreferences.getString(CONTACT_NUM,
                    getResources().getString(R.string.no_contact));
            Pattern pattern = Pattern.compile(sharedPreferences.getString(REGEX, "(\\d{8})[\\s\\t\\n#]"));
            Matcher matcher = pattern.matcher(s);
            if (matcher.find()) {
                if (!tel.equals(getResources().getString(R.string.no_contact))) {
                    String[] contact = tel.split(": ");
                    String suffix = sharedPreferences.getString(SUFFIX, "");
                    if (suffix != null)
                        try {
                            suffix = URLEncoder.encode(suffix, "UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                    String prefix = sharedPreferences.getString(PREFIX, "");
                    if (prefix != null)
                        try {
                            prefix = URLEncoder.encode(prefix, "UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                    Intent intent = new Intent(Intent.ACTION_CALL,
                            Uri.parse("tel:" + contact[1] + "%3B" + prefix + matcher.group() + suffix));

                    if (ActivityCompat.checkSelfPermission(MainActivity.this,
                            Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
                        startActivity(intent);
                    }
                } else {
                    new AlertDialog.Builder(MainActivity.this).setTitle("No contact Selected!")
                            .setMessage("Please Select Conference Call number via Settings Menu").show();
                }
            }
        }
    });
}