Categories
discuss

Android deep linking works in ADB, but not browser

I am trying to add deep linking to my app. I have added 2 intent filters to one of my activities, one filter for the “http” scheme, and another for my custom scheme (I’m using “example”). I have added one intent filter per scheme, based on the info in this SO (Deep-linking intent does not work), so that I can handle both example://test and http://www.example.com/test type of links.

Here is my XML:

        <activity
    android:name="com.myapp.myapp.SplashActivity"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter android:label="Intent Filter label">
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.LAUNCHER" />
        <!-- Accepts URIs that begin with "http://www.example.com/test2” -->
        <data android:scheme="http"
              android:host="www.example.com"
              android:pathPrefix="/test2" />

    </intent-filter>
    <intent-filter android:label="Intent Filter label">
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.LAUNCHER" />

        <!-- Accepts URIs that begin with "example://test2” -->
        <data android:scheme="example"
              android:host="test2" />
    </intent-filter>
</activity>

They are loading correctly when I test in ADB:

adb shell am start -W -a android.intent.action.MAIN -d "example://test2" com.myapp.myapp

returns

Starting: Intent { act=android.intent.action.MAIN dat=example://test2 pkg=com.myapp.myapp }
Status: ok
Activity: com.myapp.myapp/com.app.myapp.SplashActivity
ThisTime: 357
TotalTime: 357
Complete

However, I get absolutely nothing in a browser. When I try this in a browser: “example://test2” in FF I get “couldn't find an app to open this link” and in Chrome and the Native Browser, it opens up new Google search for “example://test2“.

When I try the other style: “http://www.example.com/test2” it just tries to navigate to that web page in all 3 browsers.

I am deploying the app to my phone from Android Studio. I have also tried by generating a debug APK, sending it to my phone, and installing. Same result for both. What am I doing wrong? I’ve followed the guide (https://developer.android.com/training/app-indexing/deep-linking.html) to the letter as far as I can tell. Does my app need to be in the store for the deep linking to work?

Answer

Ughh, my action was MAIN when it should have been VIEW…

<intent-filter>
        <action android:name="android.intent.action.MAIN" />

<intent-filter>
        <action android:name="android.intent.action.VIEW" />
Categories
discuss

How to make an iFrame to go fullscreen on a button click?

I would to make the iFrame to appear on fullscreen with a button click using JavaScript.

<iframe id="iframe_view" class="embed-responsive-item container well well-small span6" style="height: 720px; width: 1280px; background-color: #2e2e2e;" src="https://www.google.com/" frameborder="0" scrolling="no" allowfullscreen>

Answer

You will have to do two things: make the window fullscreen, and then the <iframe> to fill up the whole size.

You can make it go fullscreen with JS such as in this SO answer.

Then, to make it full size, just add a few styles, like below. What this JS script does is add a class with those styles to the <iframe>.

JS

document.getElementsByTagName("iframe")[0].className = "fullScreen";

CSS

body, html {
    height: 100%;
    margin: 0;
}
.fullScreen {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

See this partially working* example on JSFiddle.

*partially working because JSFiddle doesn’t allow the fullscreen method because it deems it unsafe. But it should work for you.

Categories
discuss

Fill remaining space: LinearLayout and weight or RelativeLayout?

In case I have 2 views and I want one to take the necessary space and the other to take the remaining space, how should I go about it?

Let’s suppose I want to lay the views vertically. The view below should take the necessary space (wrap_content) and the view above should take the remaining space of the container layout.

I’ve used these 2 solutions (simplified code):

1) LinearLayout with weight

<LinearLayout ...>
  <View height="0dp" weight="1" .../>
  <View height="wrap_content" .../>
</LinearLayout>

2) RelativeLayout with aligning

<RelativeLayout ...>
  <View height="wrap_content"    id="@+id/big" alignParentTop .../>
  <View height="wrap_content" below="@+id/big" alignParentBottom .../>
</RelativeLayout>

TheLinearLayout approach always work, and the RelativeLayout usually works as expected but it is obviously ambiguous, since nothing says that the @+id/big view should be bigger than the one below.

I think the first approach is better, since is not ambiguous. However, I have seen many examples and answers with the second approach.

What solution do you use for these cases. Is there a best practice?

Thanks!

EDIT

Taking Touf‘s answer, now I would do this (note the match_parent):

<RelativeLayout ...>
  <View height="match_parent"    id="@+id/big" alignParentTop .../>
  <View height="wrap_content" below="@+id/big" alignParentBottom .../>
</RelativeLayout>

Answer

I would use relative layout:

<View height="match_parent"    id="@+id/big" android:layout_above="@+id/view2" alignParentTop ... >

<View height="wrap_content" id="@+id/view2" alignParentBottom ...>

This way the first view will fill the screen height until it hits the 2nd view.

Categories
discuss

Overlaying a text box on a leaflet.js map

This might seem a very simple question, but I’ve searched elsewhere for the answer with no luck!

How do I overlay a simple text box on to a Leaflet map that loads when the map loads (not fixed to any point on a map) – for example, to give a title and more information within the actual map object. Nothing fancy.

Answer

You have two simple options, extend a new L.Control and place it in one of the four corners of the map window with content created inside the onAdd method, or place a L.DivIcon anywhere on the map alongside a L.Marker, by either geographical coordinates or coordinates based upon the dimensions of the container.Making it “box” like would just include a small bit of CSS as you see fit, like some padding,background-color, etc.

Categories
discuss

How to avoid extra wrapping

Today I have started learning ReactJS and after an hour faced with the problem.. I want to insert a component which has two rows inside a div on the page.A simplified example of what I am doing below.

I have an html:

<html>
..
  <div id="component-placeholder"></div>
..
</html>

Render function like this:

...
render: function() {

    return(
        <div className="DeadSimpleComponent">
            <div className="DeadSimpleComponent__time">10:23:12</div >
            <div className="DeadSimpleComponent__date">MONDAY, 2 MARCH 2015</div>
        </div>
    )
}
....

And below I am calling render:

ReactDOM.render(<DeadSimpleComponent/>, document.getElementById('component-placeholder'));

Generated HTML looks like this:

<html>
..
  <div id="component-placeholder">
    <div class="DeadSimpleComponent">
            <div class="DeadSimpleComponent__time">10:23:12</div>
            <div class="DeadSimpleComponent__date">MONDAY, 2 MARCH 2015</div>
    </div>
</div>
..
</html>

The problem that I am not a very happy that React forcing me to wrap all in a div “DeadSimpleComponent”. What is the best and simple workaround for it, without explicit DOM manipulations?

UPDATE 7/28/2017: Maintainers of React added that possibility in React 16 Beta 1

Since React 16.2, you can do this:

render() {
  return (
    <>
      <ChildA />
      <ChildB />
      <ChildC />
    </>
  );
}

Answer

This requirement was removed in React version (16.0)]1, so now you are able to avoid that wrapper.

You can use React.Fragment to render a list of elements without creating a parent node, official example:

render() {
  return (
    <React.Fragment>
      <ChildA />
      <ChildB />
      <ChildC />
    </React.Fragment>
  );
}

More here: Fragments

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..