Android:如何创建一个启动器

7
我之前从未为Android开发过,所以请在回答时考虑我毫无经验的情况:)
我想创建一个应用程序启动器,它会打开默认的web浏览器并跳转到给定的URL。换句话说,我想制作一个带有我的网站标志的图标,当您单击该图标时,它将在您的默认网络浏览器中打开该网站。
有没有人能指导我如何实现这个功能的教程/文档页面?如果很简单,也许可以在这里给我展示一些代码?
感谢您的时间!
P
4个回答

9
如果我理解您的需求正确,您可以创建一个简单的应用程序,只需要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)显示了什么?最好为此创建另一个问题。 - xil3

1

我已经为这个写了一篇教程 :=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!
    }
}

0

一句话回答

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

-2

为什么要创建一个应用程序来完成这个任务呢?您可以直接在主屏幕上创建一个快捷方式。

以下是操作步骤:
1. 在浏览器中打开网站
2. 为该站点添加书签(菜单,添加书签)
3. 转到您想要放置图标的主屏幕
4. 按住屏幕并保持按压状态,在弹出菜单中选择“添加快捷方式”
5. 选择“书签”
6. 找到刚刚创建的书签并单击它

完成了!!


2
目标是让用户下载应用程序并自动创建快捷方式,而不是为个人使用... - Pierre

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接