Consultation about add event to calendar - Java for Android App Development

i have this code for adding event to calendar
long calID = 3;
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2013, 3, 23, 7, 30);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2013, 3, 24, 8, 45);
endMillis = endTime.getTimeInMillis();
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DTEND, endMillis);
values.put(Events.TITLE, "My Test");
values.put(Events.DESCRIPTION, "My Calendar Test");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "Israel/tel-aviv");
Uri uri = cr.insert(Events.CONTENT_URI, values);
i need to change this line: long calID = 3;
with any default calendar id
how to get list of all calendar Accounts and fit him to id ?

Related

sdk help

Hello, I am writting a small app to replace my HTC Touch Today plugin because it is too damn big. My apps is almost done except for launching the different apps in certain case, and that is where I need help:
1- Starting cprog.exe in Call History mode
2- Going to the email
3- Going to the sms list
Thank you for your help
Ok got #3:
PROCESS_INFORMATION pi = {0};
DWORD dwRes = 0;
BOOL bret=CreateProcess(_T("\\Windows\\tmail.exe"), _T("-service \"SMS\""), NULL, NULL, NULL, 0, NULL, NULL, NULL, &pi);
Found #2, but how do you get the default Mail Account, or list them?
\Windows\tmail.exe -service "Name of email account"

[Q] Multiple Alarms

Hi ,
I am looking for someone to assist me with a problem that i have with multiple alerts .
i have created pending intents with different requestCode but i do not know how to catch this code in my broadcast handler
here is the relevant code :
Intent intent = new Intent(PROXIMITY_ALERT);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext() , 123, intent , PendingIntent.FLAG_CANCEL_CURRENT);
lm.addProximityAlert(30.28006245, 31.85403462, 200, -1, pendingIntent);
thanks !

Broadcast Receiver pass Data to MainActivity

Hi everyone,
I'm working on a small app. I'm launching the MainActivity and there's some Code. And after some specific Code, I've to wait for an incoming SMS and do other stuff in the MainActivity. But How are the Data's from the Incoming SMS passed to the Main Activity?
I've this BroadCast Receiver:
Code:
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
//---just a trial with app Context
// Starting appState = ((Starting)context);
// appState.setState("Receiver Datas");
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
//appState.setState(str);
//---display the new SMS message---
}
}
My Solution with the Application Context doesn't work...Any Ideas or Suggestions?
Thanks a lot in advance
Can you just launch it and pass it the data you need in the intent extras?
Code:
Intent it=new Intent();
it.setClassName("com.path","com.path.YourAppActivity");
it.putExtra("something","value1");
it.putExtra("something_else","value2");
startActivity(it);
So this can't work, because the Activity is already running...
So the Activity is running and is doing some stuff and then it has to wait until an SMS is received...and then continue...but it has to be in the same Activity.
Like you mentioned it I would start a new Activity...
I'm not entirely sure what it is that you're doing, but you may have to spawn this off as a service, then let the service handle SMS stuff and call back to its parent activity when something needs to be signaled. In this case, you'd need to implement some kind of callback Interface to handle events from the service.

List of all online gtalk contacts

I'd like to get a list of the email addresses associated with all the online gtalk contacts. I'm using it to generate a pick list to launch a gtalk chat session with that person from my app.
Code:
private Cursor getGtalkEmails()
{
ContentResolver cr = getContentResolver();
Uri uri = ContactsContract.Data.CONTENT_URI;
String[] projection = new String[] { ContactsContract.Data._ID,
ContactsContract.Data.CONTACT_PRESENCE,
ContactsContract.Data.DISPLAY_NAME,
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Im.PROTOCOL,
ContactsContract.CommonDataKinds.Im.DATA };
String selection = ContactsContract.Data.CONTACT_PRESENCE+"!='0' and " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Data.DISPLAY_NAME
+ " COLLATE LOCALIZED ASC";
return cr.query(uri, projection, selection, selectionArgs, sortOrder);
Unfortunately, this only returns a single contact... And I have 50 people online right now.
So I dumped the entire table and it looks like out of every contact on my phone, only one has a vnd.android.cursor.item/im entry.
So is there an alternative query I could use to filter these out? I can't just use email, because a lot of my contacts have more than one email. If they do, it could pick the wrong one and when I fire the intent to launch a gtalk session it would open up the "add contact" dialog instead of the chat activity.
Thoughts?

[Q] adding event to android calendar without showing the calendar

i have this code for adding event:
Code:
Intent calendarIntent = new Intent(Intent.ACTION_INSERT, Events.CONTENT_URI);
Calendar beginTime = Calendar.getInstance();
beginTime.set(2013,04,14,21,00,00);
Calendar endTime = Calendar.getInstance();
endTime.set(2013,04,14,21,10,00);
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("title", "Some title");
intent.putExtra("description", "Some description");
intent.putExtra("beginTime", beginTime.getTimeInMillis());
intent.putExtra("endTime", endTime.getTimeInMillis());
startActivity(intent);
but how to insert event without open the calendar ?
thanks
You'll need to use the CalendarContract API, and add a certain permission. This is only possible in 4.0 and up, however.
thank
thanks for the help,
can i get any sample code that works ?
i try some - but no one works for me
Regards,

Categories

Resources