使用Fire TV远程控制Android应用

时间:2016-01-14 17:35:28

标签: android amazon-fire-tv

似乎这些信息必须在互联网上的某个地方可用,但我似乎无法找到它。 我想运行一个我在亚马逊Fire TV上写的Android应用程序。我找到了一些如何在棒上加载应用程序的教程,但我可以找到有关如何让Fire TV遥控器与该应用程序一起使用的信息。

应用程序的主要用户界面包含大型图块(RelativeLayout),可通过识别布局上的onTouch来点击。所以没有按钮。在这种情况下,遥控器的行为如何?我需要调整我的布局吗?如果是这样的话?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

关注these instructions。你需要先安装eclipse。你必须启动eclipse安卓应用程序,然后运行应用程序。用服务器连接带有USB线的消防电视棒。

启动应用时,您需要调用adb shell am start -n com.amazon.sample.helloworld.MainActivity

有关完整工作的Mainactivity,请参阅下面的代码,

       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);
}

}