【问题标题】:Android: How to create a launcherAndroid:如何创建启动器
【发布时间】:2011-06-03 22:58:06
【问题描述】:

我以前从未为 Android 开发过,所以当你回答时请认为我 100% 愚蠢:)

我想创建一个应用程序启动器,它将默认 Web 浏览器打开到给定的 url。 换句话说,我想用我的网站徽标制作一个图标,当您单击它时,它会在您的默认网络浏览器中打开该网站。

有人可以指导我访问教程/文档页面来实现这一点吗? 或者如果它真的很简单,也许在这里给我看一些代码?

感谢您的宝贵时间!

P

【问题讨论】:

    标签: android mobile-website launcher


    【解决方案1】:

    如果我正确理解您的需求,您可以创建一个只有 1 个活动的简单应用,并将其粘贴在 onCreate 中:

    Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.yourwebsite.com"));  
    startActivity(viewIntent);
    

    这里有一些关于创建简单应用的资源:

    http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/HelloWorld.html

    以下是有关如何设置应用图标的一些信息:

    http://www.connorgarvey.com/blog/?p=97

    【讨论】:

    • 无需使用特殊的 api - 只需使用最新的 SDK 版本。 ADB 日志 (adb logcat) 说什么?可能最好为此创建另一个问题。
    【解决方案2】:

    我为此写了一个教程:=D

    http://www.anddev.org/code-snippets-for-android-f33/button-to-open-web-browser-t48534.html

    修改版:

    package com.blundell.twitterlink;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    
    public class Main extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            sendToTwitter();         // Open the browser
            finish();                // Close this launcher app
        }
    
        protected void sendToTwitter() {
            String url = "http://twitter.com/blundell_apps"; // You could have this at the top of the class as a constant, or pass it in as a method variable, if you wish to send to multiple websites
            Intent i = new Intent(Intent.ACTION_VIEW); // Create a new intent - stating you want to 'view something'
            i.setData(Uri.parse(url));  // Add the url data (allowing android to realise you want to open the browser)
            startActivity(i); // Go go go!
        }
    }
    

    【讨论】:

      【解决方案3】:

      您为什么要创建一个应用程序来执行此操作?您可以直接在主屏幕上创建快捷方式。

      这是怎么做的:
      1. 在浏览器中访问网站
      2.为网站添加书签(菜单,添加书签)
      3. 转到您想要徽标的主屏幕
      4. 长按屏幕,在弹出菜单时选择“添加快捷方式”
      5. 选择“书签”
      6.找到刚刚创建的书签并点击

      你已经完成了!

      【讨论】:

      • 目标是让用户下载应用程序并自动创建快捷方式,它不是供个人使用的......
      【解决方案4】:

      一行回答

      startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url)));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-29
        • 1970-01-01
        • 2016-02-26
        • 2012-09-27
        • 1970-01-01
        • 2013-09-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多