Suppose we can use getPackageInfo in Package Manager in android and get any installed app's versionCode and all.
So can we find the architecture or the app? Like it's arm-v7a or arm64
I'll be very helpful to you.
Thank you
I found your question for "Java custom string encryption from a paragraph or set of strings", and would like to help because I've done something similar in c#.
I noticed that one of the largest reasons for that question being closed is because you were lacking in certain details that would help us determine what you needed.
This is an example of mine:
public static string Trans(string data) {
data = ToBinary(ConvertToByteArray(data));
string[] Adata = data.Split();
string output = "";
foreach(string word in Adata) {
int count = 0;
bool counting1s = false;
count = 0;
output = "";
foreach(var ch in word) {
if (ch == '0' && counting1s) {
counting1s = false;
if (count > 0) {
output += bit1[count - 1];
count = 0;
}
}
if (ch == '1' && !counting1s) {
counting1s = true;
if (count > 0) {
output += bit0[count - 1];
count = 0;
}
}
count++;
}
if (count > 0) {
output += (counting1s ? bit1 : bit0)[count - 1];
}
}
return output;
}
I could help you with making something in Java if youd like.
Related
Is there any equivalent to String.strip() in android, except trim()?
My development environments are Java11, minSdk24, targetSdk31 and compileSdk31. Is that possible to make String.strip() available if I upgrade one of them?
You can try upgrading your project to use Java 11, which has the function. Or write it yourself, its trivial.
public static String strip(String value) {
int firstChar = 0;
while (firstChar < value.length() && Character.isWhitespace(value.charAt(firstChar))) {
firstChar++;
}
int lastChar = value.length() - 1;
while (lastChar > firstChar && Character.isWhitespace(value.charAt(lastChar))) {
lastChar--;
}
return value.substring(firstChar, lastChar + 1);
}
I am stuck with the ObjectBox Like Query. I have done as below when I search for something.
QueryBuilder<MItemDetail> builder = mItemDetailListBox.query();
builder.contains(MItemDetail_.productName, search);
itemList = builder.build().find();
For example, My data is:
paracetamol
paracetamol potest
paracetamol_new
Problem:
Now as you know the contains works simply as that returns a list of items that contain a given search string.
What I Want:
If I search para new, I want the result paracetamol_new
If I search para p, I want the result paracetamol potest
If I search para e e, I want the result paracetamol potest and paracetamol_new
Is there any function or utility available in ObjectBox that can help me to achieve this?
Do let me know If you have any questions.
Edited:
The given links in a comment, My question is different. I know all the methods contains(), startsWith, and endsWith but my problem not getting solved using that.
With Reference to this answer I have done some changes as given and I got a perfect solution as I wanted.
QueryBuilder<MItemDetail> builder = mItemDetailListBox.query();
// builder.contains(MItemDetail_.productName, search);
builder.filter(new QueryFilter<MItemDetail>() {
#Override
public boolean keep(#NonNull MItemDetail entity) {
return like(entity.getProductName(), "%"+ search + "%");
}
}).order(MItemDetail_.productName);
businessModels = builder.build().find();
In the following methods, I have added one more replace statement .replace(" ",".*?")
private static boolean like(final String str, final String expr) {
String safeString = (str == null) ? "" : str;
String regex = quoteMeta(expr);
regex = regex.replace("_", ".").replace(" ",".*?").replace("%", ".*?");
Pattern p = Pattern.compile(regex,
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
return p.matcher(safeString).matches();
}
private static String quoteMeta(String s) {
if (s == null) {
throw new IllegalArgumentException("String cannot be null");
}
int len = s.length();
if (len == 0) {
return "";
}
StringBuilder sb = new StringBuilder(len * 2);
for (int i = 0; i < len; i++) {
char c = s.charAt(i);
if ("[](){}.*+?$^|#\\".indexOf(c) != -1) {
sb.append("\\");
}
sb.append(c);
}
return sb.toString();
}
Thank you.
In UWP c# in textbox.textchange event I'm using code like that
public static void wpisywanie_daty(TextBox sender)
{
var nowyWpis = "";
var plainText = sender.Text.Replace("/", "");
if (plainText.Length <= 5)
{
for (int i = 1; i <= plainText.Length; i++)
{
nowyWpis += plainText[i - 1];
if (i % 2 == 0) nowyWpis += "/";
}
sender.Text = nowyWpis;
sender.Select(sender.Text.Length, 0);
}
if (sender.Text.Length >= 10)
{
sender.IsEnabled = false;
sender.IsEnabled = true;
}
}
changing dinamicly text to format dd/mm/yyyy when you typing.
How to implement it in android c# xamarin?
When the code hit line sender.Text = nowyWpis; it rise textchanged eventhandler and start code from beginning.
The minimum Youtube App. version required to be installed on a device to use the Youtube API is 4.2.16
To get the youtube app. version installed on a device:
String version = YouTubeIntents.getInstalledYouTubeVersionName(getContext());
Thats could return as known a three numbers separeted by dots. How can I check if the returned version number is less than 4.2.16. Which is obviously not an integer and not a floating point number?
Accepted for the ##Original answer:
Original answer:
Well, this may not be the easiest way, but you can do something like this:
First split the string at the .'s:
String[] partsOfVersion = version.split("\\.");
Then convert each part into an int:
int first = partsOfVersion.length>0 ? Integer.parseInt(partsOfVersion[0]) : 0;
int second = partsOfVersion.length>1 ? Integer.parseInt(partsOfVersion[1]) : 0;
int third = partsOfVersion.length>2 ? Integer.parseInt(partsOfVersion[2]) : 0;
Then you can just use an if statement to check if they're above 4.2.16:
if((first == 4 && second == 2 && third >= 16) || (first == 4 && second >== 3) || first >= 5) {
...
}
And if you want to check if it's less than that, just use an else statement after that if statement.
That should work, I haven't tested it though.
Added:
Someone (#JeroenVannevel) pointed out to me that there's an easier way to do this.
First remove all occurrences of .:
version = version.replace(".", "");
Then convert the string to an int:
int versionInt = Integer.parseInt(version);
And finally, check if the number is greater than or equal to (or less than if you want incompatible devices) 4216:
if(versionInt >= 4216) {
...
}
Also, you might want to check if version is empty or not before starting.
the answer to your problem is very simple, as you see from AndroidManifest.xml file to
YouTube 4.2.16 android apk I found this line .
<manifest android:versionCode="4216" android:versionName="4.2.16" package="com.google.android.youtube" ...>
so to check if app you need to do to check if the VersionCode biger than int (4216) by Public methods
getInstalledYouTubeVersionCode(Context context)
for more info visit YouTubeIntents Reference Guide.
In final you can use this ready check
if(YouTubeIntents.isYouTubeInstalled(getActivity()) && YouTubeIntents.getInstalledYouTubeVersionCode(getActivity())>4216){
//do what you want whit YouTubeIntents
}else {
//Ask user to install the last youtube app .
}
I hope this answer help you.
I wrote a class for precisely this purpose, maybe it could be useful.
public class Version implements Comparable<Version>
{
public final int Major;
public final int Minor;
public final int Build;
public final int Revision;
public Version(int major, int minor)
{
this(major, minor, 0);
}
public Version(int major, int minor, int build)
{
this(major, minor, build, 0);
}
public Version(int major, int minor, int build, int revision)
{
Major = major;
Minor = minor;
Build = build;
Revision = revision;
}
public Version(String str)
{
int major = 0;
int minor = 0;
int build = 0;
int revision = 0;
if (Strings.hasValue(str))
{
String[] parts = str.split("\\.");
if (parts.length > 0)
major = parseInt(parts[0]);
if (parts.length > 1)
minor = parseInt(parts[1]);
if (parts.length > 2)
build = parseInt(parts[2]);
if (parts.length > 3)
revision = parseInt(parts[3]);
}
Major = major;
Minor = minor;
Build = build;
Revision = revision;
}
private static int parseInt(String str)
{
try
{
return Integer.parseInt(str);
}
catch (NumberFormatException e)
{
return 0;
}
}
#Override
public String toString()
{
return String.format("%s.%s.%s.%s", Major, Minor, Build, Revision);
}
public boolean isEmpty()
{
return (Major == 0 && Minor == 0 && Build == 0 && Revision == 0);
}
#Override
public int compareTo(Version another)
{
if (another == null)
throw new NullPointerException();
int[] thisV = new int[] { Major, Minor, Build, Revision };
int[] otherV = new int[] { another.Major, another.Minor, another.Build, another.Revision };
for (int i = 0; i < thisV.length; i++)
{
if (thisV[i] < otherV[i])
return -1;
else if (thisV[i] > otherV[i])
return +1;
// else, loop to consider less significant parts.
}
return 0; // All equal.
}
}
In my application there is a search option. If the user enters a search value, I have to get a value from the webservice. I am getting a large webservice value. In my webservice string values are coming. I am getting like <> like xml character entity reference like. I want to replace all characters and parse xml. Can anybody tell me how to do this and give an example?
I tried with StringBuffer for unescapexml character, I am getting out of memory error
public String unescapeXML(String str) {
if (str == null || str.length() == 0)
return "";
StringBuffer buf = new StringBuffer();
int len = str.length();
for (int i = 0; i < len; ++i) {
char c = str.charAt(i);
if (c == '&') {
int pos = str.indexOf(";", i);
if (pos == -1) { // Really evil
buf.append('&');
} else if (str.charAt(i + 1) == '#') {
int val = Integer.parseInt(str.substring(i + 2, pos), 16);
buf.append((char) val);
i = pos;
} else {
String substr = str.substring(i, pos + 1);
if (substr.equals("&"))
buf.append('&');
else if (substr.equals("<"))
buf.append('<');
else if (substr.equals(">"))
buf.append('>');
else if (substr.equals("""))
buf.append('"');
else if (substr.equals("'"))
buf.append('\'');
else if (substr.equals(" "))
buf.append(" ");
else
// ????
buf.append(substr);
i = pos;
}
} else {
buf.append(c);
}
}
return buf.toString();
}
I tried with stream, I am not able to do it. Can anybody give an example how to do this?
You should not parse it on your own. There are better ways - SAX or DOM.
This resource contains a lot of useful inforamtion about these both ways (and code examples too): http://onjava.com/pub/a/onjava/2002/06/26/xml.html
Take a look here in order to get more details about android included parsers :
http://developer.android.com/reference/javax/xml/parsers/package-summary.html
But make your own parser with SAX is probably the best choice in your case ;)