Posts

Showing posts with the label Android

Android Widget Using Cordova

Answer : Yes, widgets are native Android constructions. But you CAN create your widget for your app with the help of cordova plugin called "cordova-plugin-ace". Made by Microsoft and opened to everyone. Documentation: Official site - http://microsoft.github.io/ace/ Doc for creating widget - http://microsoft.github.io/ace/docs/native-ui/#four I hope it'll be helpfully for you, me and others cordova devs. Widgets are android native constructs that extend a view on the application screen. http://developer.android.com/reference/android/widget/package-summary.html A cordova/phonegap app is an app with a webview backing. Note: webview not android native view. Until someone finds a way to construct a native widget that embeds a webview, then what you have been told so far is correct... i.e. "no". http://cordova.apache.org/docs/en/4.0.0/guide_overview_index.md.html#Overview http://cordova.apache.org/docs/en/4.0.0/guide_hybrid_webviews_index.md.html#...

Android Numberpicker For Floating Point Numbers

Answer : NumberPicker is not just for integers.. Even you can use Floats String etc. see this and read about it. for tutorials : http://gafurbabu.wordpress.com/2012/03/29/android-number-picker-dialog/ And I had used NumberPicker long ago like this and it might be some use posting here: NumberPicker np; String nums[]= {"Select Fraction","1/64","1/32","3/64","1/16","5/64","3/32","7/64","1/8","9/64","5/32","11/64","3/16","13/64","7/32","15/64","1/4","17/64","9/32","19/64","5/16","21/64","11/32","23/64","3/8","25/64","13/32","27/64","7/16","29/64"}; np = (NumberPicker) findViewById(R.id.np); np.setMaxValue(nums.length-1); np.setMin...

Android -room Persistent Library - DAO Calls Are Async, Therefore How To Get Callback?

Answer : If you want to do your query synchronously and not receive notifications of updates on the dataset, just don't wrap you return value in a LiveData object. Check out the sample code from Google. Take a look at loadProductSync() here There is a way to turn off async and allow synchronous access. when building the database you can use :allowMainThreadQueries() and for in memory use: Room.inMemoryDatabaseBuilder() Although its not recommended. So in the end i can use a in memory database and main thread access if i wanted super fast access. i guess it depends how big my data is and in this case is very small. but if you did want to use a callback.... using rxJava here is one i made for a list of countries i wanted to store in a database: public Observable<CountryModel> queryCountryInfoFor(final String isoCode) { return Observable.fromCallable(new Callable<CountryModel>() { @Override public CountryModel call() throws Exception { ...

Android: No Activity Found To Handle Intent Error? How It Will Resolve

Answer : Add the below to your manifest: <activity android:name=".AppPreferenceActivity" android:label="@string/app_name"> <intent-filter> <action android:name="com.scytec.datamobile.vd.gui.android.AppPreferenceActivity" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> in my case, i was sure that the action is correct, but i was passing wrong URL, i passed the website link without the http:// in it's beginning, so it caused the same issue, here is my manifest (part of it) <activity android:name=".MyBrowser" android:label="MyBrowser Activity" > <intent-filter> <action android:name="android.intent.action.VIEW" /> <action android:name="com.dsociety.activities.MyBrowser" /> <category android:name...

Auto Generate Id For Document And Not Collection In Firestore

Answer : If you are using CollectionReference's add() method, it means that it: Adds a new document to this collection with the specified POJO as contents, assigning it a document ID automatically. If you want to get the document id that is generated and use it in your reference, then use DocumentReference's set() method: Overwrites the document referred to by this DocumentRefere Like in following lines of code: String id = db.collection("collection_name").document().getId(); db.collection("collection_name").document(id).set(object); Since you already know the id of the document, just call set() instead of add() . It will create the document if it doesn't already exist. This answer might be a little late but you can look at this code here which will generate a new document name: // Add a new document with a generated id. db.collection("cities").add({ name: "Tokyo", country: "Japan" }) .then...

Arabic Number In Arabic Text In Android

Answer : There's such issue in Google's bugtracker: Arabic numerals in arabic language intead of Hindu-Arabic numeral system If particularly Egypt locale doesn't work due to some customer's issue(I can understand it), then you can format your string to any other western locales. For example: NumberFormat nf = NumberFormat.getInstance(new Locale("en","US")); //or "nb","No" - for Norway String sDistance = nf.format(distance); distanceTextView.setText(String.format(getString(R.string.distance), sDistance)); If solution with new Locale doesn't work at all, there's an ugly workaround: public String replaceArabicNumbers(String original) { return original.replaceAll("Ù¡","1") .replaceAll("Ù¢","2") .replaceAll("Ù£","3") .....; } (and variations around it with Unicodes matching (U+0661,U+0662,......

BLE Scan Is Not Working When Screen Is Off On Android 8.1.0

Answer : As of Android 8.1, unfiltered bluetooth scans are blocked when the screen is turned off. While it is surprising for such a dramatic change to be made in a minor release of Android, this is certainly an intended change based on the comments in the commit: Stop unfiltered BLE scans when the screen goes off. The workaround is to use a ScanFilter with all scans. The new 8.1 operating system code simply verifies that any scans active when the screen is off have at least one scan filter. If those conditions are met the scan results are delivered as in Android 8.0.x and earlier. In order to set up such a scan, you must use the APIs introduced in Android 5.0 and create a ScanFilter with each scan. Below is a filter that will find manufacturer advertisements for any device from Apple with manufacturer ID 0x004c (this will include iBeacons): ScanFilter.Builder builder = new ScanFilter.Builder(); builder.setManufacturerData(0x004c, new byte[] {}); ScanFilter filter = buil...

Android SetVisibility Does Not Display If Initially Set To Invisble

Answer : Had similar error but it was due to my silly mistake of not using the UiThread. Activity act = (Activity)context; act.runOnUiThread(new Runnable(){ @Override public void run() { mLayoutLights.setVisibility(View.VISIBLE); } }); Got it. You have to set the visibility of all the items in the layout, not just the layout. So this code worked: if (mLayoutLights.getVisibility() == View.VISIBLE) { ((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.GONE); ((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.GONE); mLayoutLights.setVisibility(View.GONE); } else { mLayoutLights.setVisibility(View.VISIBLE); ((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.VISIBLE); ((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.VISIBLE); } In my case, with a plain SurfaceView, I just set the View to GONE in xml, not INVISIBLE. Then I can set VISIBILITY correctly after that.

Add Android-studio/bin/ To PATH Environmental Variable

Answer : It looks like you edited this code snippet: if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi which is included in ~/.profile by default. The answer which lead you to do so is confusing IMNSHO. I'd suggest that you change that code back to what it looked like before, and instead add a new line underneath it: if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi PATH="$PATH:/usr/local/Android/android-studio/bin" Then, next time you log in, PATH ought to be altered, whether $HOME/bin exists or not.

Android: Styling Overflow Menu In Action Bar

Answer : I did it this way: <style name="Theme.yourapp" parent="@style/Theme.AppCompat.Light.DarkActionBar"> <item name="android:actionBarWidgetTheme">@style/Theme.yourapp.Widget</item> </style> <style name="Theme.yourapp.Widget" parent="@style/Theme.AppCompat"> <item name="android:textColor">@android:color/black</item> </style> For simplicity, the android: namespace pertains to anything built into the OS while anything without android: as the namespace would pertain to your application (and the libraries you are using). Most, if not all, support libraries for the ActionBar will try to use the native ActionBar implementation and therefor use the android: namespace attributes in your styles. When the native ActionBar is not available it would use the libraries implementation and the non- android: namespaced attributes. This is why you must specify every attribute w...

Android Project, Change Firebase Account

Answer : Follow the below steps, to switch firebase account Go to your firebase console, and select the project you want to shift Select the icon besides the project name on top right. Select Permissions from the flyout. You've reached the IAM & Admin page of firebase. Click on +Add button on top. Enter the email ID of the account to transfer the project to. In the dropdown, Select a role > Project > Owner. Click add Check mail in the email added above. Accept the invite, and go to IAM & Admin page of the transferred project. Use remove button to delete the previous user Hope this helps. 1- Yes, it's possible and you can follow this tutorial to do so. 2- If you want to simply switch projects, generate a new JSON on the console and remove the old one. If you want to migrate your database, it's possible, just check this question. 3- Both answers are "yes" so, try them out.

Androidx.test.InstrumentationRegistry Is Deprecated

Answer : You can use InstrumentationRegistry.getInstrumentation().getTargetContext() in the most cases from androidx.test.platform.app.InstrumentationRegistry . If you need the Application, you can use ApplicationProvider.getApplicationContext<MyAppClass>() . If you haven't already, I think you can also use the new test dependency: androidTestImplementation 'androidx.test:core:1.0.0-beta02' . When you're using Android X you need to make sure you have the following in your app's build.gradle file androidTestImplementation 'androidx.test:core:1.1.0' androidTestImplementation 'androidx.test.ext:junit:1.1.0' The second one is to make sure you have the correct AndroidJUnit4 to use in your tests. Make sure you import both of these. import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 Now instead of using val context = InstrumentationRegistry.getContext() you can use the lin...

Change Linear Layout Top Margin Programmatically Android

Answer : layout = (LinearLayout) findViewById(R.id.layoutbtnlinear_aboutme); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)layout.getLayoutParams(); params.setMargins(0, 50, 0, 0); layout.setLayoutParams(params); LayaoutParams usually create confusion while setting margin because of their parent layout... So this MarginLayoutParams is very useful which works with all layouts. Java Code MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams(); params.width = 200; //Ths value 200 is in px... Please convert in DP params.leftMargin = 100; params.topMargin = 200; Kotlin code val params: MarginLayoutParams = view!!.layoutParams as MarginLayoutParams params.width = 200 params.leftMargin = 100 params.topMargin = 200 This updates the top margin without the need to update the other margin values. LinearLayout layout = (LinearLayout) findViewById(R.id.your_linear_layout); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)...

Android Beginner Difference Between Padding And Margin

Image
Answer : Margin Margins make up the vertical and horizontal areas between elements. If elements have no margins around them, they will bump right up against each other. In other words, he space outside of, or between, elements is what comprises the margin areas. Padding The padding of an element is the horizontal and vertical space that’s set around the content area of the targeted element. So padding is on the inside of a box, not the outside. Padding is for inside/within components. Eg. TextView , Button , EditText etc. Eg. space between the Text and Border Margin is to be applied for the on-outside of the components. Eg. space between left edge of the screen and border of your component Visual representation is great in : Difference between a View's Padding and Margin With Padding , i have seen a difference in 2.2, 2.3 and say 4.3, 4.4 in such cases: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns...

Adb Command Not Found

Answer : In my case with Android Studio 1.1.0 path was this /Users/wzbozon/Library/Android/sdk/platform-tools Add the following to ~/.bash_profile export PATH=~/Library/Android/sdk/tools:$PATH export PATH=~/Library/Android/sdk/platform-tools:$PATH Is adb installed? To check, run the following command in Terminal: ~/Library/Android/sdk/platform-tools/adb If that prints output, skip these following install steps and go straight to the final Terminal command I list: Launch Android Studio Launch SDK Manager via Tools -> Android -> SDK Manager Check Android SDK Platform-Tools Run the following command on your Mac and restart your Terminal session: echo export "PATH=~/Library/Android/sdk/platform-tools:$PATH" >> ~/.bash_profile Note: If you've switched to zsh, the above command should use .zshenv rather than .bash_profile Make sure adb is in your user's $PATH variable. or You can try to locate it with whereis and run it wit...

Android Studio Database Inspector Does Not Show Any Databases

Answer : In my case, it showed me the same process a lot of times. And none of them worked. The solution was Invalidating the Cache: File -> Invalidate Caches/Restart -> Invalidate and restart After that everything started working again. I face 2 cases: First time connect to my device and database does not show, then i do an action to modify database -> database will show. After I use ADB Idea to clean app data or uninstall (or go to settings and clear cache or uninstall app) -> database does not show -> restart device -> database will show Looks like its problem with device . If you have some custom rom installed then you might run into this issue . Link to the issue tracker https://issuetracker.google.com/issues/159432618

Bypass With Wrong Cvv Of Debit Card And Getting OTP

Answer : But shouldn't it suppose verify before I get the OTP? What's the reason, Isn' it a security issue? This is absolutely NOT a security issue! quite the opposite it's a protection. Lets go through the steps. You put in card details. You put in CVV You put in the OTP. The payment is processed if and only if the combination of all of it are correct. Now assume a scenario where it tell's you the CVV is wrong before the 2FA that is just going to simply give the attacker a chance to better attack.Now the attacker knows the CVV is wrong and can simply change that.While in the correct scenario attacker will have to break 2 Factor authentication to gain that information As well as the general rule of not giving the attacker information by rejecting too early, there are some things specific to the payment industry which are somewhat relevant. Although often presented to the customer as mandatory, the authentication information on a payment i...

Android How Can I Convert A String To A Editable

Answer : As you probably found out, Editable is an interface so you cannot call new Editable() . However an Editable is nothing more than a String with Spannables, so use SpannableStringBuilder: Editable editable = new SpannableStringBuilder("Pass a string here"); If you only want to change the Spannables, never the text itself, you can use a basic SpannableString. Use Editable.Factory.getInstance().newEditable(str) From the android documentation: Returns a new SpannedStringBuilder from the specified CharSequence. You can override this to provide a different kind of Spanned.

Android PdfDocument File Size

Answer : There are a few main things that increases the size of a PDF file: hi-resolution pictures (where lo-res would suffice) embedded fonts (where content would still be readable "good enough" without them) PDF content not required any more for the current version/view (older version of certain objects) embedded ICC profiles embedded third-party files (using the PDF as a container) embedded job tickets (for printing) embedded Javascript and a few more Try using iText. Following links give a basice idea for iText in android. http://technotransit.wordpress.com/2011/06/17/using-itext-in-android/ http://www.mysamplecode.com/2013/05/android-itext-pdf-bluetooth-printer.html https://stackoverflow.com/a/21025162/3110609 In case anyone is still looking for a solution... I was working on a project to generate PDF from images and not satisfied with the file size generated by both Android's PdfDocument and 3rd party AndroidPdfWriter APW. After some trials I ended...

Base64 Encoder And Decoder

Answer : This is an example of how to use the Base64 class to encode and decode a simple String value. // String to be encoded with Base64 String text = "Test"; // Sending side byte[] data = null; try { data = text.getBytes("UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } String base64 = Base64.encodeToString(data, Base64.DEFAULT); // Receiving side byte[] data1 = Base64.decode(base64, Base64.DEFAULT); String text1 = null; try { text1 = new String(data1, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } This excerpt can be included in an Android activity. See android.util.Base64 It seems that this was added in API version 8 or android 2.2 so it will not be available on the older platforms. But the source of it is at android/util/Base64.java so if needed one could just copy it unchanged for older versions. Here is a simple method I was going to use until I realized that t...