2

it seems like this information must be available somewhere on the internet but I cannot seem to find it. I want to run an android application that I've written on an Amazon Fire TV stick. I found some tutorials how to load the app on the stick, but I could find information on how to get the Fire TV remote to work with the app.

The main user interface of the app consists of large tiles (RelativeLayout) that are clickable by recognizing onTouch on the Layout. So no Buttons. How does the remote behave in this scenario? Do I need to adapt my layout? If so how?

Thanks for your help.

Androidicus
  • 1,688
  • 4
  • 24
  • 36
  • 1
    "How does the remote behave in this scenario?" -- not well, I imagine. "Do I need to adapt my layout?" -- most likely, yes. "If so how?" -- it needs to be usable by a keyboard, as the Fire TV remotes send key events for the D-pad and other buttons. This is also needed for accessibility, so visual- and motor-impaired users can use assistive technologies to help navigate your app. – CommonsWare Jan 14 '16 at 17:41
  • 1
    @CommonsWare hi, so you would think that by following these guidelines I can make my app amazon fire ready: http://developer.android.com/training/keyboard-input/navigation.html ? – Androidicus Jan 14 '16 at 17:43
  • 1
    Yes, though the tab navigation portion will not be relevant. The directional navigation part will map to what the Fire TV remote does. If you do not want to test constantly on a Fire TV, an emulator or a Bluetooth keyboard with a regular Android device are good ways of testing keyboard input. – CommonsWare Jan 14 '16 at 17:47
  • @CommonsWare I see. Thanks for your help. That's what I wanted to know. – Androidicus Jan 14 '16 at 17:48

1 Answers1

1

Follow these instructions. You need to install eclipse first.You have to start the eclipse android app and hence to run app. Connect fire tv stick with a usb cable with the server.

While to start the app you need to invoke, adb shell am start -n com.amazon.sample.helloworld.MainActivity

For complete working Mainactivity see code below,

       package com.example.firetv;
       import android.support.v7.app.ActionBarActivity;
       import android.app.Activity;
       import android.os.Bundle;
       import android.view.Menu;
       import android.view.MenuItem;
       import android.webkit.WebChromeClient;
       import android.webkit.WebSettings;
       import android.webkit.WebSettings.LayoutAlgorithm;
       import android.webkit.WebSettings.PluginState;
       import android.webkit.WebView;
       import android.webkit.WebViewClient;
       import android.widget.Toast;

public class Init extends ActionBarActivity {
WebView web;
private static boolean sFactoryInit = false;
private WebSettings webSettings;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_init);
    web = (WebView) findViewById(R.id.myWebView);

    webSettings = web.getSettings();

    webSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setBuiltInZoomControls(true);
    web.getSettings().setPluginState(PluginState.ON);

    web = new WebView(this);
    web.getSettings().setJavaScriptEnabled(true); // enable javascript

    web.setWebChromeClient(new WebChromeClient() {
    });

    final Activity activity = this;
    web.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
        }
    });
    web.clearCache(true);
    web.loadUrl("http://server.com/firetv/out/");
    setContentView(web);

    web.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            web.loadUrl("http://google.com");
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.init, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}