I am building an app where user can select participants from the contact and also he can remove participants later if he wishes not to invite him.
Right now am able to open contact list with the following code.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
I am thinking to store the mobile number in an array,but how the user will know which contact he has selected from the above code.
I am confused on how to proceed.
Any help could be appreciated.
Instead of just starting the activity with an intent, you'll want to start the activity for a result. Take a look at the documentation here - the first example is even picking a contact.
Related
My application involves tracking of vehicle movement through check gates
When a person posted at the gate clicks the Pass button against a vehicle number, that vehicle should be removed from the list. I have done it by calling the VehicleActivity class again with putting the gate id in key-value pair.
Intent intentClear = new Intent(context, VehicleActivity.class);
intentClear.putExtra(VehicleActivity.EXTRA_POSITION, Integer.toString(gate_id));
context.startActivity(intentClear);
However if the user presses the back button, the previous list shows up which may confuse the user. To remove the previous screen I can use Intent.FLAG_ACTIVITY_CLEAR_TOP, but then the information sent through putExtra gets removed.
Please suggest the best possible way of solving this as any problem in that list might make the vehicles stuck at checkgates.
To restart your current activity, simply call finish(); after startActivity();.
This will clear current activity after you start the new one and it doesn't exist in the back stack anymore.
There is 1 Button on my MainActivity and when user clicks on it, it starts the UserProfileActivity to view the current signed in user profile details along with names (values) on TextView.
e.g. it's something like this >>
"Name: Bean Smith",
" Age: 27 ",
" Gender: Male ".
I've already created the layout for the same and I know how to retrieve data's from the DatabaseReference to display values on TextView acting as the user details (from DataSnapShot). Issue:I want to load the user details before my MainActivity will start, so that when the user clicks on the button to check the user profile, the values should get auto populate automatically.
I've searched and found AsyncTask but I Don't really know how or when to use this. please any help from you guys will be highly appreciated..
thanks.
Suppose you have two screens, A and B, or you want that when screen B opens, it starts with filled data, use the following logic.
Firstly, when you are going from one activity to another, that time load all data on screen A and pass the data to screen B by intent, and get or check the received intent values using this, you can achieve your destination:
In class A
Intent intent=new Intent(A.this,B.class);
intent.putExtra("data","data_value");
startActivity(intent);
In class B
if(getIntent().getExtras()!=null)
{
String a=getIntent().getStringExtra("data").toString();
}
as follow you can send multiple data over the two screens.
You can do two things,
As Mayank Garg said you can download the data using AsyncTask task in MainActivity and pass them to other activity but in this case u have to be careful about the null checks.
You can write it Sqlite Database and retrieve it back from 2nd Activity.
Like getting an image. I want to give users the choice to access either the camera, gallery or any other app which can return an image.
Create dialog with three options camera, gallery, file explorer.
When user select an option from the dialog call proper intent to open selected application.
Please refer the link :http://www.theappguruz.com/blog/android-take-photo-camera-gallery-code-sample
Hope this will help you
So, if you haven't noticed. Many new launchers give you the option to select an application to be launched as default for a specific category.
My launcher consists of different fragments which displays cards, these cards hold a button which has a function where when the user touches the button, they're prompted with a window where they can select which application to run for that specific view. To make things easier for the user, the intent or app they selected should be saved, so if they select the button again, they don't have to select the app again.
If you would like a few examples to what I mean, take a look at 9 Cards Launcher or Smart Launcher, or any Windows 7 Phone Launcher. They prompt you with a small pop up which lets you select the application you want to run and its set.
how can I achieve this? Please I have literally searched everywhere, but nothings making sense. There are no tutorials on this, I have also decompiled various launchers to see how this works but I don't know where to start.
It'd be great if you could help.
1st of all you need to get the Installed Applications.
Then you will get the application package info from the user selected Application.
Finally launch the intent.
Here's what you can try out:
Create an intent with action=MAIN and category=LAUNCHER
Get the PackageManager from the current context using context.getPackageManager
packageManager.queryIntentActivity(<intent>, 0) where intent has category=LAUNCHER, action=MAIN or packageManager.resolveActivity(intent, 0) to get the first activity with main/launcher
Get the ActivityInfo you're interested in
From the ActivityInfo, get the packageName and name
Finally, create another intent with with category=LAUNCHER, action=MAIN, componentName = new ComponentName(packageName, name) and setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Finally, context.startActivity(newIntent)
I would also suggest to take a look at FreeTaskManager
I'm curious on the Intent.createChooser() method. I've done some research but haven't been able to find the specific answer I was looking for.
I have a requirement that depending on which application the user picks (either email or text) I'm to format the text differently. I'm OK with the chooser displaying other applications (I'd prefer to not remove options for users) but is there a way for my application to know which external application the user selected? From there I could maybe overload the initial Intent and send the properly formatted data.
Thank you in advance for any help.
I'm OK with the chooser displaying other applications (I'd prefer to not remove options for users) but is there a way for my application to know which external application the user selected?
No, sorry.
For that, you would need to create your own chooser dialog, using PackageManager and queryIntentActivities(). Based on what the user chooses in that dialog, you can then set the appropriate extras on the Intent, along with the selected ComponentName, and use the resulting Intent with startActivity().
(one of these days, I'll write one of these dialogs, as this question comes up a lot...)