Android - struggling to style Account Picker - android

I'm trying to implement an AccountPicker in my game, and I've tried using all three versions of newChooseAccountIntent, 2 coming from AccountManager and one from AccountPicker.
my code looks like this
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
intent = AccountManager.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, null, null, null, null);
} else {
intent = AccountManager.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, false, null, null, null, null);
}
or the same, but replace AccountManager for AccountPicker
My aim is to have a picker that looks like this
But using AccountManager I get
which is at least Material in colour
or this from AccountPicker (ICS!!)
Any ideas what I'm doing wrong?
I thought it might be that the AccountManager is populating the first field which is selectedAccount, but when I did that, it just selected the radio button against the appropriate account.

You can use Google Api Client document

Related

Deleting by Uri with ContentResolver

I am trying to delete content (chanel's program) like:
content://android.media.tv/preview_program/317
with this code:
getContentResolver().delete(TvContractCompat.buildPreviewProgramUri(ALlProgramIDs.get(i)), null, null);
// ALlProgramIDs.get(i) = 317; long type
or this code:
getContentResolver().delete(Uri.parse(ALsProgramIDs.get(i)), null, null);
// ALsProgramIDs.get(i) = content://android.media.tv/preview_program/317
and nothing to be happen. Programs are not deleting.
BUT this code:
getContentResolver().delete(Uri.parse(ALsProgramIDs.get(i).substring(0, ALsProgramIDs.get(i).length() - 3)), null, null);
// LsProgramIDs.get(i).substring(0, ALsProgramIDs.get(i).length() - 3 = content://android.media.tv/preview_program/
works fine - everything from this Uri (or storage) is deleted.
What is wrong with deleting certain IDs?
Seems done like here:
https://developer.android.com/reference/androidx/tvprovider/media/tv/PreviewProgram
Usage example when deleting a preview program:
getContentResolver().delete(TvContractCompat.buildPreviewProgramUri(existingProgram.getId()), null, null);
getContentResolver().delete(TvContractCompat.buildPreviewProgramUri(programId), null, null);
Should work, so you may want to connect the debugger and step through it to verify you're passing the ID you want to delete and that the built URI is correct. An alternative that will make your code more readable is to use the PreviewChannelHelper's deletePreviewProgram method.
PreviewChannelHelper(context).deletePreviewProgram(id);

getting event ID after creating it using intent

(first of all, sorry if any of this sounds stupid, but I'm a total nood regarding android)
I'm working on an organizer app where I want to create a Calendar Event using an intend, and afterwards I have to save the events ID in my app so I can open it up again to edit it and so my app can read the events start date.
the code I'm using, I got from this question:
How can I find out the result of my calendar intent?
The intend works but I can't get the rest to work. also, "EventUtility" and "mContext" show up as errors.
p.s. I also get a warning about a missing Permission but I have no idea where to add that
protected void kalender() {
long event_id = EventUtility.getNewEventId(mContext.getContentResolver());
Intent newEvent = new Intent(Intent.ACTION_INSERT)
.setData(CalendarContract.Events.CONTENT_URI)
.putExtra(CalendarContract.Events.TITLE, "Abgabe Termin")
.putExtra(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY)
.putExtra(CalendarContract.Events.HAS_ALARM, true)
.putExtra("allDay", true);
startActivity(newEvent);
}
public static long getNewEventId(ContentResolver cr) {
Cursor cursor = cr.query(CalendarContract.Events.CONTENT_URI, new String[]{"MAX(_id) as max_id"}, null, null, "_id");
cursor.moveToFirst();
long max_val = cursor.getLong(cursor.getColumnIndex("max_id"));
return max_val + 1;
}

sending MMS in Android KitKat (API-19)

In my android application I want to send MMS from background service without user interaction, I tried to use SmsManager.sendMultimediaMessage but this method requires API-21 atleast and I am working on API-19 (Android KitKat). So please tell how can I send MMS from background service without user interaction in Android API level 19 (KitKat)?
Use this page.
since i shouldn't answer with just a link. I copied some content from there.
Settings sendSettings = new Settings();
sendSettings.setMmsc(mmsc);
sendSettings.setProxy(proxy);
sendSettings.setPort(port);
you can get them something like (found at Set APN programmatically on Android - answear by vincent091):
Cursor cursor = null;
if (Utils.hasICS()){
cursor =SqliteWrapper.query(activity, activity.getContentResolver(),
Uri.withAppendedPath(Carriers.CONTENT_URI, "current"), APN_PROJECTION, null, null, null);
} else {
cursor = activity.getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"),
null, null, null, null);
}
cursor.moveToLast();
String type = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.TYPE));
String mmsc = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSC));
String proxy = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSPROXY));
String port = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSPORT));

how to specify account for ContactsContract editor

From my app, I want to invoke the Contacts editor to allow the user to add a new contact. I want to find a way for the app to pass to the editor an account to be used. How can this be done?
I have not found any documentation on how to do this. I did find some code on github which shows a contact editor retrieving account info (see ContactEditorActivity). It calls
getParcelable(Intents.Insert.ACCOUNT);
I think this must be deprecated code though, as I can't find the value Intents.Insert.ACCOUNT anywhere in the references.
Overall, my code for invoking the editor is working; here's an extract:
Intent intent = new Intent();
intent.setAction (Intent.ACTION_INSERT);
intent.setData (ContactsContract.Contacts.CONTENT_URI);
intent.putExtra (ContactsContract.Intents.Insert.NAME, name);
... "put" other values ...
startActivityForResult (intent, ACTIVITY_REQUEST_FULL_EDIT);
Thanks.
I know this is an old question, but here is my solution which seemed to work for me, just in case someone has the same problem.
I was using Xamarin for Android but the Java code is pretty much the same.
For API 23+, use the ExtraAccount field EG:
Android.Accounts.Account account = new Android.Accounts.Account(accountName, accountType);
...
intent.PutExtra(ContactsContract.Intents.Insert.ExtraAccount, account);
...
And for older APIs I used the field "com.android.contacts.extra.ACCOUNT" EG:
Android.Accounts.Account account = new Android.Accounts.Account(accountName, accountType);
...
intent.PutExtra("com.android.contacts.extra.ACCOUNT", account);
...
This opened the contact intent, defaulting to the passed in account (by-passing any phone defaults). This was handy because I was setting a whole bunch of information like url, job title etc and it was getting lost because the contact intent was defaulting to SIM card - which can not hold this data!
In case your are wondering how to get the accounts on the phone, you can use:
AccountManager.Get(context).GetAccountsByType("com.google");
to get google accounts, or
AccountManager.Get(context).GetAccounts();
to get all accounts. However neither include the phone account or SIM account, so I used this code to get these:
using Android.Accounts;
...
public List<Account> GetAccounts()
{
if (CheckReadContactsPermission())
{
var accountList = new List<Account>();
var uri = ContactsContract.Settings.ContentUri;
string[] projection = { ContactsContract.Settings.InterfaceConsts.AccountName,
ContactsContract.Settings.InterfaceConsts.AccountType };
var loader = new CursorLoader(context, uri, projection, null, null, null);
var cursor = (ICursor)loader.LoadInBackground();
if (cursor.MoveToFirst())
{
do
{
accountList.Add(new Account(cursor.GetString(cursor.GetColumnIndex(projection[0])),
cursor.GetString(cursor.GetColumnIndex(projection[1]))));
} while (cursor.MoveToNext());
}
return accountList;
}
return null;
}

Can't update event on phone's calendar from code

I'm attempting to update a calendar's event on my phone from my code, but context.getContentResolver().update keeps returning 0, and of course there are no changes made to the event when I look at it in the Calendar app.
I'm getting the event ID, start time, etc with context.getContentResolver().query, and I'm getting unique numbers like 431, 4, 233, etc, so I'm presuming the event IDs I'm using are real.
I understand the official way to do this is to go through Google's servers instead of using update(), but for my implementation it doesn't make sense to do it that way (or even in general, but I digress).
Am I doing something wrong, or am I trying to do something that Android simply isn't going to allow?
Uri updateEventUri = ContentUris.withAppendedId(Uri.parse("content://com.android.calendar/events"), id);
ContentValues cv = new ContentValues();
begin.set(Calendar.HOUR_OF_DAY, arg0.getCurrentHour()); //begin is a java.util.Calendar object
begin.set(Calendar.MINUTE, arg0.getCurrentMinute());
//cv.put("_id", id);
//cv.put("title", "yeahyeahyeah!");
cv.put("dtstart", begin.getTimeInMillis());
int updatedrowcount = context.getContentResolver().update(updateEventUri, cv, null, null);
System.out.println("updated "+updatedrowcount+" rows with id "+id);
A related question was posted here with no replies https://stackoverflow.com/questions/5636350/update-android-calendar-event
Let me know if I can clarify anything; I would really appreciate any input you guys and dolls could provide!
i had tried a lot and finally ended up with solution (Unreliable though).. but works fine..
public static boolean updateCalendar(Context context,String cal_Id,String eventId)
{
try{
Uri CALENDAR_URI = Uri.parse(CAL_URI+"events");
Cursor c = context.getContentResolver().query(CALENDAR_URI, null, null, null, null);
String[] s = c.getColumnNames();
if (c.moveToFirst())
{
while (c.moveToNext())
{
String _id = c.getString(c.getColumnIndex("_id"));
String CalId = c.getString(c.getColumnIndex("calendar_id"));
if ((_id==null) && (CalId == null))
{
return false;
}
else
{
if (_id.equals(eventId) && CalId.equals(cal_Id))
{
Uri uri = ContentUris.withAppendedId(CALENDAR_URI, Integer.parseInt(_id));
context.getContentResolver().update(uri, null, null, null);// need to give your data here
return true;
}
}
}
}
}
finally
{
return true;
}
}
and finally i'm not sure if it works with every device.
Ok, so, the problem was that I was using different URIs between fetching the events and editing them. I used the code sample from here and was using the URI "content://com.android.calendar/instances/when" to fetch the events and display them on the screen. When I had made a change I was using "content://com.android.calendar/events" to edit by id as in my example above.
What I found, thanks to your response, ntc, was that the ids for events between the two URIs were different, and therefore I couldn't edit the events consistently with the information each was giving me. I was presuming the event ids I was getting were system ids and universal to the phone.
I guess I'll have to do some testing and see what hardware isn't compatible with this method. I am using an HTC Evo for testing and so far so good.
When querying the Instances table, use Instances.EVENT_ID to get the identifier for the event you want to edit, instead of Instances._ID.

Categories

Resources