I have a little problem with contextmenus in android. I searched a while but couldn't find an answer for that without listview.
For example i have the following code :
PHP:
TextView subject = new TextView(this);
subject.setText("asdf");
subject.setId(20);
registerForContextMenu(subject);
Checking which contextmenu item isn't the problem, but i need the id from that textview.
How could i solve these problem without using listview?
Related
Hi
I want to write an app that goes through all my stored SMS, lets me pick one and then would display the SMSC address which was involved in sending said SMS to my phone.
Question: Is this SMSC address stored somewhere? And just to be totally clear: I am not asking for the SMSC address of my operator which would be used for sending SMS from my phone to other phones, okay?
I tried to find something in the deprecated SMS content provider. But either I did not look hard enough or it's simply not there.
Has anybody got some tip for me regarding this?
thanks a lot!
gsm-man
Try the following code:
ContentResolver cr = context.getContentResolver();
final Cursor c = cr.query(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "date", "read", "body", "service_center"}, null, null, null);
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?
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,
Good afternoon. There is a task to develop a client for android news site. For notification of new posts to be used gcm.
Estimated algorithm:
1. Run the application, the database is empty, make a request to the api get the last 20 records, id 1000 to 980, write to the database.
3. Listview is scrolled to the last record, make a request for records whose id is less than 980, we record from 979 to 959 write to the database.
3. Comes gcm message or clicked update, make a request to the api, get the records whose id> 1000, we record with id 1001 to 1021 write to the database.
The question arises - how to behave in a situation where we assume the device was offline for a week, during which added another 1000 records.
The device connects to the network, gets send-to-sync message, makes a request to the api to get records whose id> 1021, in response to the 1000 records to come.
Intuition suggests that load all 1000 records are not correct, you need to download and say the last 20, but then it turns out that the database will be news for today, last week they will not, and then go for the news before last week
And question number 2 - how to clean old records, to avoid infinite growth of the DB?
What about this: make another table that have only 20 records and when a news comes, it stores it on the first record and deletes last record. Of course records 2-19 iterate.
When you get news on device, get them from this table. If you want to get older news, get the last id from this table and get next 20 news from table that stores all of the records.
---------- Post added at 10:29 AM ---------- Previous post was at 10:20 AM ----------
Answering question 2:
The best solution for me is to make model class News . It makes everything easier with DB. If you have this, you can do something like this:
public void deleteAllNews(){
String selectQuery = "SELECT * FROM " + TABLE_NEWS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(selectQuery, null);
// looping through all rows
if (c.moveToFirst()) {
do {
db.delete(TABLE_NEWS, KEY_ID + " = ?", new String[] { String.valueOf(c.getInt(c.getColumnIndex(KEY_ID)) });
} while (c.moveToNext());
}
db.close();
c.close();
}
Hello everyone,
I've queried Android's CallLog.Calls and populated an ArrayList with my call model object however when I display these objects in a RecyclerView, certain phone-numbers appear multiple times, once for each call entry that was made from or to that number.
I'd like to group the calls from the same number together.
Is there a built-in way in Android to group these call entries so that I can display them as a single entry in my call log RecyclerView?
I tried to add "GROUP BY" to the query but contentResolver.query() does not seem to accept it in any of its parameters.
Thanks!
You can remove the duplications after you get the data using a HashSet, for example:
ArrayList<String> items = getItems();
HashSet<String> hashset = new HashSet<>();
hashset.addAll(items);
items = new ArrayList<String>(hashset);