7

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

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

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

谢谢你的时间!

4

4 回答 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

于 2011-01-05T11:40:35.210 回答
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!
    }
}
于 2011-01-05T13:35:46.143 回答
0

一行回复

startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url)));
于 2015-01-20T07:23:57.327 回答
-2

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

操作如下:
1. 在浏览器中访问网站
2. 为网站添加书签(菜单,添加书签)
3. 转到您想要徽标的主屏幕
4. 按住屏幕,当弹出菜单选择“添加快捷方式”
5. 选择“书签”
6. 找到刚刚创建的书签并单击它

你完成了!

于 2011-11-30T01:36:50.767 回答