#StackBounty: #android #osmand Opening gpx file in Osmand, from another application

Bounty: 50

I have an Android application that basically stores a list of gpx files which are saved on the user’s phone. When the user clicks on the filename in the application, it should prompt the user to open the gpx file with whatever routing applications are available on his phone. Right now I am testing with opening the file in Osmand. The problem is, Osmand is opening, but then immediately crashing.

The code that tries to open the file is this:

File gpxFile = new File(Path);

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);

Uri gpxUri = FileProvider.getUriForFile(view.getContext(), AUTHORITY, gpxFile);
intent.setDataAndType(gpxUri, "application/gpx+xml");

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

The gpx files all look like this:

<?xml version="1.0"?>
<gpx creator="{CREATOR}" version="1.1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<wpt lat="{LAT_1}" lon="{LON_1}">
    <name>{WPT_NAME_1}</name>
</wpt>
...
<wpt lat="{LAT_N}" lon="{LON_N}">
    <name>{WPT_NAME_N}</name>
</wpt>
<trk>
  <name>{TRACK_NAME}</name>
  <trkseg>
    <trkpt lat="{LAT_1}" lon="{LON_1}"></trkpt>
    ...
    <trkpt lat="{LAT_N}" lon="{LON_N}"></trkpt>
  </trkseg>
</trk>
</gpx>

At first I thought it was something wrong with the format of the gpx files, but if I open Osmand manually and try to import the file using “Configure map” -> “Gpx track”, the track shows just fine on the map, including the waypoints.


Get this bounty!!!

#StackBounty: #android #cordova #camera How to restrict the plugin to switch rear/back camera in android / cordova

Bounty: 50

I am using media-capture plugin of cordova to capture the video only from front camera.
when it opens the camera, there is option to switch the back or rear camera, can anyone please guide, how to disable switching to back camera. I have done following modification in plugin and re added to app, but no luck.

intent.putExtra("android.intent.extras.LENS_FACING_BACK", 0);
intent.putExtra("android.intent.extra.USE_BACK_CAMERA", false);


Get this bounty!!!

#StackBounty: #unity #android #profiling Profiling unity games on Android devices

Bounty: 100

I would like to profile our Unity mobile game on Android devices in a way similar to profiling Unity games on iOS with Instruments.

I am aware of how to do this using Unity’s profiler, I would however like to use a third party profiler for the following reasons:

  • to validate Unity’s profiling data
  • to have more visibility into how the app is running, including Unity’s functions, etc.
  • the largest lag spikes cause unity’s profiler to run out of samples. I’m however very interested in precisely these spikes
  • I’d like to have profile data for longer periods than unity records for
  • I’d like to do analysis over time (not just detailed data for each frame, but also aggregated over a time span)

Essentially I’d like as much visibility as possible to make Android on-device profiling as comprehensive as possible. As close to Instruments on iOS as possible.

So far I’ve tried with DDMS, but could only get visibility into Andoid OS functions and seeminly nothing in the actual apk – at least nothing I recognised. I tried with mono2x and il2cpp, with all debug features that I’m aware of in build and player settings enabled.

The game is developed with Unity 5,4 with Mono2x.

All help is appreciated. I’ve listed my intents above, so even if profiling on device is not possible in this way on Andoid, alternate solutions to the listed intents are still very appreciated. Thanks!


Get this bounty!!!

#StackBounty: #android #recyclerview #android-nestedscrollview #onscrolllistener Recyclerview view is not working with setNestedScrolli…

Bounty: 50

I am two facing two problems

1) The first one scroll listener wont work
2)The recycler view never recycle any views when its attached to nested scroll view,its acts as set on linear layout inside scroll view.its create a huge memory and lags the screen.
3) I am attaching youtube player fragment on top of recycler view since i can’t put fragment inside recycler view.in my code you can see there is a frame layout.

i have the layout like this.

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nestedScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <FrameLayout               
            android:layout_width="match_parent"
            android:layout_height="240dp"
            android:layout_alignParentTop="true"/>





    </LinearLayout>


    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/youtube_layout"
        android:visibility="visible"/>




</LinearLayout>

i want to use scroll listener to load more items
so i have tried this.

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    Log.i(TAG, "onScrolled: ");
    // bail out if scrolling upward or already loading data
    if (dy < 0 || dataLoading.isDataLoading()) return;

    final int visibleItemCount = recyclerView.getChildCount();
    final int totalItemCount = layoutManager.getItemCount();
    final int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();

    if ((totalItemCount - visibleItemCount) <= (firstVisibleItem )) {
        onLoadMore();
    }


}

but layoutManager.findFirstVisibleItemPosition()==0 so its not working , and more over onScrolled never called twice since i set
recyclerview.setNestedScrollingEnabled(false)

so i have tried in onbindviewLike this

   public void onBindViewHolder(RecyclerView.ViewHolder customViewHolder, int i) {
    Log.w("d","inside bind view");

    if(i>=getItemCount()-1  &&   !datamanager.isDataLoading()){
        datamanager.loadmoreData();
    }

but recylerview binds the all the view in single time before i start scrolling ,so this method also deos not work

any help will be appreciated?


Get this bounty!!!

#StackBounty: #java #android #downloading Implementing resume for download files via internet

Bounty: 100

my below code for downloading file work fine when don’t implementing resume for that, after read more solution to implementing that and resolve problem i know i must check Last-Modified header and set it for connection,

but i can’t do that because of i get error such as android Cannot set request property after connection is made or i get null for httpURLConnection,

i’m using this reference

getHeaderField heaser return:

{
  null=[HTTP/1.1 200 OK], 
  Cache-Control=[public], 
  Connection=[keep-alive], 
  Content-Length=[8037404], 
  Content-Md5=[VEqXHCc/Off7a6D0gRFpiQ==], 
  Content-Type=[image/jpeg], 
  Date=[Tue, 19 Jan 2016 07:24:36 GMT], 
  Etag=["544a971c273f39f7fb6ba0f481116989"], 
  Expires=[Sat, 29 Jul 2017 10:07:00 GMT], 
  Last-Modified=[Thu, 18 Dec 2014 08:44:34 GMT], 
  Server=[bws], 
  X-Android-Received-Millis=[1501063623576], 
  X-Android-Response-Source=[NETWORK 200], 
  X-Android-Selected-Protocol=[http/1.1], 
  X-Android-Sent-Millis=[1501063623532]
}

now how can i set that to have resume for download files?

GitHub Link

public void run() {
    final URL         url;
    HttpURLConnection httpURLConnection = null;
    try {
        try {
            url = new URL(mUrl);
            String lastModified = httpURLConnection.getHeaderField("Last-Modified");
            if (!lastModified.isEmpty()) {
                httpURLConnection.setRequestProperty("If-Range", lastModified);
            }
            httpURLConnection = (HttpURLConnection) url.openConnection();

            if (mFile.exists()) {
                downloadedLength = mFile.length();
                Log.e("downloadedLength ", downloadedLength + "");
                httpURLConnection.setRequestProperty("Range", "bytes=" + downloadedLength + "-");
                fileOutputStream = new FileOutputStream(mFile, true);
            } else {
                fileOutputStream = new FileOutputStream(mFile);
            }
            httpURLConnection.setConnectTimeout(30000);
            httpURLConnection.setReadTimeout(30000);
            httpURLConnection.setRequestMethod("GET");
        } catch (IOException e) {
        }
        final int responseCode;
        final int total;
        try {
            responseCode = httpURLConnection.getResponseCode();
            total = httpURLConnection.getContentLength();
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("ER UPDATE ", e.getMessage());
        }
        if (responseCode == 200) {
            try {
                inputStream = httpURLConnection.getInputStream();
            } catch (IOException e) {
                e.printStackTrace();
                Log.e("IOException ", e.getMessage());
            }
            final byte[] buffer   = new byte[4 * 1024];
            int          length   = -1;
            int          finished = 0;
            long         start    = System.currentTimeMillis();
            try {
                while ((length = inputStream.read(buffer)) != -1) {
                    if (!isDownloading()) {
                        throw new CanceledException("canceled");
                    }
                    fileOutputStream.write(buffer, 0, length);
                    finished += length;
                    if (System.currentTimeMillis() - start > 1000) {
                        onDownloadProgressing(finished, total);
                        start = System.currentTimeMillis();
                    }
                }
                onDownloadCompleted();
            } catch (IOException e) {
                e.printStackTrace();
                Log.e("ER UPDATE ", e.getMessage());
            }
        } else {
            Log.e("responseCode ", responseCode + "");
        }
    } catch (DownloadException e) {
        e.printStackTrace();
        Log.e("ER UPDATE ", e.getMessage());
    } catch (CanceledException e) {
        e.printStackTrace();
        Log.e("ER UPDATE ", e.getMessage());
    }
}

and also i get 206 response code instead of 200


Get this bounty!!!

#StackBounty: #android #animation #textview How to do text writing animation?

Bounty: 50

I want to create text writing animation like in real life, how to do this on Android? Please help.

enter image description here


Get this bounty!!!

#StackBounty: #android #recyclerview #android-view How to make width of a view dependent on other view in a recyclerview?

Bounty: 50

I want to measure the width of a cardview and match to the cardview that is on its outside, to get a clear understanding I will attach an image along with the question:

enter image description here

Here, the inner cardview should be same width of the outer cardview in every case where inner cardview is the reply chat bubble and outer is the chat message bubble.

I have tried extending the cardview:

public class ExtendCardView extends CardView {

Integer newWidth;

public ExtendCardView(Context context) {
    super(context);
}

public ExtendCardView(Context context, AttributeSet attrs) {
    super(context, attrs);
}


@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    newWidth= MeasureSpec.getSize(widthMeasureSpec);
      super.onMeasure(newWidth, heightMeasureSpec);

}

public Integer getNewWidth() {
    return newWidth;
}

public void setNewWidth(Integer newWidth) {
    this.newWidth = newWidth;
}}

and on the onBindView of adapter I have added a view tree observer to change the width:

((CardView) holder).inner_card_view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            //((CardView) holder).inner_card_view.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);

            ((CardView) holder).inner_card_view.setNewWidth(((CardView) holder).outer_card_view.getNewWidth());
            //now we can retrieve the width and height
            //...
            //do whatever you want with them
            //...
            //this is an important step not to keep receiving callbacks:
            //we should remove this listener
            //I use the function to remove it based on the api level!

            if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
                ((CardView) holder).inner_card_view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            else
                ((CardView) holder).inner_card_view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });

What is the perfect way to achieve something like this, here is my layout file for the cardview:

      <com.example.ui.view.ExtendCardView
    android:id="@+id/outer_card"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="50dp"
    app:cardCornerRadius="8dp">


        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="2dp">

            <TextView
                android:id="@+id/tv_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:textAppearance="@style/TextAppearance.AppCompat.Small"
                android:textColor="@color/black" />

            <com.example.ui.view.ExtendCardView
                android:id="@+id/inner_card"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/tv_name"
                android:layout_margin="1dp"
                android:minWidth="80dp"
                app:cardBackgroundColor="@color/red"
                app:cardCornerRadius="8dp"
                app:cardElevation="0dp">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <RelativeLayout
                        android:id="@+id/rel_layout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_marginEnd="15dp"
                        android:layout_marginRight="15dp">

                        <TextView
                            android:id="@+id/tv_user_name"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentLeft="true"
                            android:layout_alignParentStart="true"
                            android:textStyle="bold" />

                        <LinearLayout
                            android:id="@+id/lin_layout"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@id/tv_user_name"
                            android:layout_marginBottom="8dp"
                            android:orientation="horizontal">

                            <ImageView
                                android:id="@+id/iv_type"
                                android:layout_width="18dp"
                                android:layout_height="18dp"
                                android:layout_marginEnd="4dp"
                                android:layout_marginRight="4dp"
                                android:tint="@color/dark_grey"
                                android:visibility="gone" />

                            <TextView
                                android:id="@+id/tv_message"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:autoLink="web"
                                android:maxLines="3" />
                        </LinearLayout>


                    </RelativeLayout>

                    <ImageView
                        android:id="@+id/iv_media"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:layout_gravity="center_vertical"
                        android:layout_marginEnd="8dp"
                        android:layout_marginLeft="15dp"
                        android:layout_marginRight="8dp"
                        android:layout_marginStart="15dp"
                        android:visibility="gone" />
                </LinearLayout>

            </com.nodd.nodd.ui.view.ExtendCardView>

            <TextView
                android:id="@+id/tv_reply_message"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/inner_card"
                android:layout_marginBottom="5dp"
                android:layout_marginEnd="4dp"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="4dp"
                android:layout_marginStart="4dp"
                android:autoLink="web"
                android:linksClickable="true"
                android:textColor="@color/white"
                android:textColorLink="@color/linkedin_blue" />

            <ImageView
                android:id="@+id/tv_reply_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/inner_card"
                android:visibility="gone"
                android:layout_marginBottom="5dp"
                android:layout_marginEnd="4dp"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="4dp"
                android:layout_marginStart="4dp"
                android:layout_marginTop="5dp" />
        </RelativeLayout>

    </RelativeLayout>
</com.example.ui.view.ExtendCardView>


Get this bounty!!!

#StackBounty: #android #libgdx #augmented-reality Android LibGDX 1.9.6 Augmented Reality captured images are black

Bounty: 50

Using LibGDX for an AR application and capturing image and merging lines and texts on LibGDX with image with this code.

 private Pixmap merge2Pixmaps(Pixmap mainPixmap, Pixmap overlayedPixmap) {
    // merge to data and Gdx screen shot - but fix Aspect Ratio issues
    // between the screen and the camera
    Pixmap.setFilter(Filter.BiLinear);
    float mainPixmapAR = (float) mainPixmap.getWidth() / mainPixmap.getHeight();
    float overlayedPixmapAR = (float) overlayedPixmap.getWidth() / overlayedPixmap.getHeight();
    if (overlayedPixmapAR < mainPixmapAR) {
        int overlayNewWidth = (int) (((float) mainPixmap.getHeight() / overlayedPixmap.getHeight())
                * overlayedPixmap.getWidth());
        int overlayStartX = (mainPixmap.getWidth() - overlayNewWidth) / 2;
        // Overlaying pixmaps
        mainPixmap.drawPixmap(overlayedPixmap, 0, 0, overlayedPixmap.getWidth(), overlayedPixmap.getHeight(),
                overlayStartX, 0, overlayNewWidth, mainPixmap.getHeight());
    } else {
        int overlayNewHeight = (int) (((float) mainPixmap.getWidth() / overlayedPixmap.getWidth())
                * overlayedPixmap.getHeight());
        int overlayStartY = (mainPixmap.getHeight() - overlayNewHeight) / 2;
        // Overlaying pixmaps
        mainPixmap.drawPixmap(overlayedPixmap, 0, 0, overlayedPixmap.getWidth(), overlayedPixmap.getHeight(), 0,
                overlayStartY, mainPixmap.getWidth(), overlayNewHeight);
    }
    return mainPixmap;
}

In 1.9.6 Pixmap.setFilter(Filter.BiLinear); is not available and it does not merge 2 pixmaps correctly. I tried setting BiLinear filter for both pixmaps or one at a time both none works.Black image


Get this bounty!!!

#StackBounty: #android #google-maps How to set google map loading tiles color?

Bounty: 200

Bright loading tiles on map with dark style don’t look good. Is there a way to change loading tiles colour?


Get this bounty!!!

#StackBounty: #android #ios #xamarin #webview #xamarin.forms Show Prompt to know the location

Bounty: 100

I am using Xamarin WebView controller to display a web site (in both iOS/Android). The web site’s home page prompts to access the device location. But that prompt is not showing when I have this website on a WebView (from the App). When I open this site on the browser, from the same mobile device it shows the message box. I am just wondering if it is possible to have such prompts on Xamarin WebView?

Here is an example prompt.

enter image description here

This is all I have in the Xamarin app.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:nCollar"
             x:Class="nCollar.MainPage">
    <ContentPage.Padding>
        <OnPlatform x:TypeArguments="Thickness">
            <OnPlatform.iOS>0,20,0,0</OnPlatform.iOS>
            <OnPlatform.Android>0,0,0,0</OnPlatform.Android>
            <OnPlatform.WinPhone>0,0,0,0</OnPlatform.WinPhone>
        </OnPlatform>
    </ContentPage.Padding>

    <WebView x:Name="webView"
                 Grid.Row="0"
                 VerticalOptions="FillAndExpand" 
                 Source="https://www.ncollar.com.au/"/>

</ContentPage>

UPDATE 1

Android

I’ve tried the solution mentioned in this post, but still it doesn’t show the prompt.

WebViewRenderer.cs

using Android.Webkit;
using Xamarin.Forms.Platform.Android;

[assembly: Xamarin.Forms.ExportRenderer(typeof(TestApp.Controls.WebView), typeof(TestApp.Droid.Renderers.WebViewRenderer))]
namespace TestApp.Droid.Renderers
{
    public class WebViewRenderer : Xamarin.Forms.Platform.Android.WebViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
        {
            base.OnElementChanged(e);

            if (this.Control == null)
            {
                return;
            }

            var webView = this.Element as TestApp.Controls.WebView;
            if (webView == null)
            {
                return;
            }


           // webView. ings.JavaScriptEnabled = true;
            this.Control.Settings.DomStorageEnabled = true;
            this.Control.Settings.DisplayZoomControls = true;
            this.Control.Settings.BuiltInZoomControls = true;
            this.Control.Settings.SetGeolocationEnabled(true);
            this.Control.Settings.JavaScriptCanOpenWindowsAutomatically = true;

            this.Control.SetWebViewClient(new GeoWebViewClient());
            this.Control.SetWebChromeClient(new GeoWebChromeClient());
        }
    }

    public class GeoWebChromeClient : WebChromeClient
    {
        public override void OnGeolocationPermissionsShowPrompt(string origin, GeolocationPermissions.ICallback callback)
        {
            callback.Invoke(origin, true, false);
        }
    }

    public class GeoWebViewClient : WebViewClient
    {
        public override bool ShouldOverrideUrlLoading(WebView view, string url)
        {
            view.LoadUrl(url);
            return true;
        }
    }
}

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-sdk android:minSdkVersion="15" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application android:label="TestApp.Android"></application>
</manifest>

iOS

Tried NSLocationWhenInUseUsageDescription in the plist file, but no difference.


Get this bounty!!!