#See this https://stackoverflow.com/a/15029515/185022
I`m trying to select images from gallery, but i only found the way to select a single image.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
Is there a way to select multiple images?
Create a custom gallery same like: Android custom image gallery with checkbox in grid to select multiple
First of all you need to use putExtra with your photoPickerIntent
photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE);
Then in your on activity result you should get ClipData from Intent like this
ClipData clipData = data.getClipData();
//Where data is param intent of onActivityForResult
And iterate this clipData to get URI for specific picked image.
for (int i = 0; i < clipData.getItemCount(); i++){
Uri uri = clipData.getItemAt(i).getUri();
}
I hope this helps
Why don't you try ACTION_SEND_MULTIPLE thing. You will receive a set of Uris.
Something like
if (Intent.ACTION_SEND_MULTIPLE.equals(action))
&& Intent.hasExtra(Intent.EXTRA_STREAM)) {
ArrayList<Parcelable> list =
intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
for (Parcelable parcel : list) {
Uri uri = (Uri) parcel;
/// do things here.
}
}
Saw this code block on a google-groups post. Just try this out.
Thanks.
I think, you should implement custom gallery for multiple image pick action.
see here in details.
Related
For a scanning ticket app, I want to display full screen image.
The app does sequential operation. You scan your QrCode (first image), the device reach server (second image indicating to wait), then I display a third image if the ticket is validate, else I display the last one.
I'm using glide and the image path is indicated in a second activity, I transmit URI to main activity with a sharedPreferences file.
Here is the issue:
val settings = getSharedPreferences("PrefFile", 0)
if (S_mod){//priority on S_mod
uri_State_init = Uri.parse(settings.getString("mainUri", "none"))
uri_State_waiting = Uri.parse(settings.getString("waitUri", "none"))
uri_State_validated = Uri.parse(settings.getString("okUri", "none"))
uri_State_refused = Uri.parse(settings.getString("errorUri", "none"))
displayUri( uri_State_init, background)
image.setImageResource(R.drawable.empty)
}
where displayUri is
fun displayUri( uri: Uri?, dir:ImageView){//use to display image known by uri, only for full screen
Glide.with(this)
.load(uri)
.error(R.drawable.imagenotfound) // image in case of error
.override(1280, 800) // resizing if user doesn't respect the indicated dim
.centerCrop()//type of resizing
.into(dir)
}
The issue is that only the first image called by displayUri is displayed, the other call show the error image (imagenotfound)
It seem that I've not totally understood the glide extension.
If someone know about this particular issue thanks a lot!!
Here
val settings = getSharedPreferences("PrefFile", 0)
if (S_mod){//priority on S_mod
uri_State_init = Uri.parse(settings.getString("mainUri", "none"))
uri_State_waiting = Uri.parse(settings.getString("waitUri", "none"))
uri_State_validated = Uri.parse(settings.getString("okUri", "none"))
uri_State_refused = Uri.parse(settings.getString("errorUri", "none"))
displayUri( uri_State_init, background)
image.setImageResource(R.drawable.empty)
}
displayUri( uri_State_init, background)
You are just calling the display Image function with the same uri which means if you didn't passed the uri, then uri will be null and you will definitely get errors. What you can do is to send uri like this ,
val settings = getSharedPreferences("PrefFile", 0)
if (S_mod){//priority on S_mod
uri = Uri.parse(settings.getString("main_uri", "none"))
displayUri( uri_State_init, background)
image.setImageResource(R.drawable.empty)
}
Just change the value of main_uri in Shared Preferences whenever you want to change the state. You can also use onSharedPreferencesChanged Listener.
I'm new to Android. I want to display the copied coupon code.
Here is code:
ClipboardManager clipboard = (ClipboardManager) mCtx.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Code", artist.getCoupon_code());
clipboard.setPrimaryClip(clip);
Toast.makeText(mCtx, "coupon code: "+clip+" is copied" , Toast.LENGTH_SHORT).show();
How to remove the red-underlined text and only display the coupon code i.e. green underlined text.
output:
The string you want may be found in
clip.getItemAt(0).getText();
or
clipboard.getPrimaryClip().getItemAt(0).getText();
or, because you are setting the clip right there, you can just use the value directly, in the string
artist.getCoupon_code()
Good luck!
The snippet below should do the tric for you.
ClipboardManager clipboard = (ClipboardManager) mCtx.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
Toast.makeText(mCtx, "coupon code: "+item.getText()+" is copied" , Toast.LENGTH_SHORT).show();
Find more info about copying and pasting from the link below.
Copy and Paste | Android developers
So I managed to get my Android app working with both Firebase and Glide and I'm able to load a single image from Firebase into an ImageView like this:
imageview1;
imageview1 = (ImageView)findViewById(R.id.ivTest);
String url1 = "https://firebasestorage.googleapis.com/v0/b/zxtrix-e017d.appspot.com/o/fullsize%2Falligator.jpg?alt=media&token=1b85f1c4-4133-41d8-a65f-eg2e263g0403";
Glide.with(getApplicationContext())
.load(url1)
.into(imageview1);
However, I'm currently loading an array of images from my /res/ folder like this, and I want to change it so that it loads from Firebase instead.
Integer[] ApocImages = {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4,
R.drawable.image5, R.drawable.image6, R.drawable.image7, R.drawable.image8,
R.drawable.image9, R.drawable.image10, R.drawable.image11, R.drawable.image12,
R.drawable.image13, R.drawable.image14, R.drawable.image15, R.drawable.image16};
I've uploaded all the images in my /res/ folder to my Firebase app storage area.
How can I now load them from Firebase into my array?
Thanks!
You can make an array of URL same as drawable you made.
String[] url = {"https://firebasestorage.googleapis.com/v0/b/zxtrix-e017d.appspot.com/o/fullsize%2Falligator.jpg?alt=media&token=1b85f1c4-4133-41d8-a65f-eg2e263g0403",
"https://firebasestorage.googleapis.com/v0/b/zxtrix-e017d.appspot.com/o/fullsize%2Falligator.jpg?alt=media&token=1b85f1c4-4133-41d8-a65f-eg2e263g0403",
"https://firebasestorage.googleapis.com/v0/b/zxtrix-e017d.appspot.com/o/fullsize%2Falligator.jpg?alt=media&token=1b85f1c4-4133-41d8-a65f-eg2e263g0403"};
After this, set for loop
for (int i=0; i<url.size; i++) {
Glide.with(getApplicationContext())
.load(url.get(i))
.into(imageview1);
}
I want to be able to get the string package name and icon of all the applications installed in my phone.
What I have done:
Browsed and found this solution
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = this.getPackageManager().queryIntentActivities(mainIntent, 0);
for(int counter = 0; counter<=pkgAppsList.size()-1;counter++)
{
Log.e("TAG", pkgAppsList.get(counter).toString());
}
The problem is that it displays package and class name as as a as a mix and I can't get the icon. What I want is to show the user a list of all the applications installed on the phone with the icon. And I also need to be able to get the package name with a List.OnItemClickListener. I assume that using an array of app names and package name which are of same positioning I can do that. But how would I get the app icon and name with package name. Preferably as an Array or ArrayList that I can convert into a listView object. If there is any alternative method even let me know. I am still a beginner in Android.
And please do help.
Please use the below code and directions:
//check this code with some hard work then you will rock
List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
ArrayList<AppInfo> res = new ArrayList<AppInfo>();
for(int i=0;i<apps.size();i++) {
PackageInfo p = apps.get(i);
AppInfo newInfo = new AppInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
}
class AppInfo {
String appname = "";
String pname = "";
String versionName = "";
int versionCode = 0;
Drawable icon;
}
For more information try these links:
http://javatechig.com/android/how-to-get-list-of-installed-apps-in-android http://developer.android.com/reference/android/content/pm/PackageManager.html
Using this link from this question. I got the package name. Then using the answer from this question I got the package/app icon. Now as soon as I figure the array adapter to accommodate this. I guess its done then.
My Code:
final PackageManager pm = getPackageManager();
List<applicationinfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
//The log is not required so if you want to and I recommend during release you remove that statement.
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Drawable icon = getPackageManager().getApplicationIcon(packageInfo.packageName)
imageView.setImageDrawable(icon);
Hope this helps all readers as well.
get appliction icon image from package name
Drawable appicon = getPackageManager().getApplicationIcon("com.example.pkgname");
img.setImageDrawable(appicon);
Im creating a simple app which is for example i got 10 table row with check box and user click on 3 box and press next, i wan to print out only the 3 row the use clicked and adding extra button/icon beside it. Is it possible? please help ! Thank you !
to pass data to another Activity you can use Intents and putting your data as extra :
here is a sample :
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("data", "My data in second activity");
startActivity(intent);
and for retrieving data in SecondActivity :
String data = getIntent().getStringExtra("data");
Yes, use putExtra and pass an ArrayList of String:
Intent intent = new Intent(Recipes2.this, XMLParser.class);
intent.putStringArrayListExtra("myList", (ArrayList<String>) myList);
startActivity(intent);
Here is the answer:
Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);
startActivity(intent)
For more information check this link.