Android的:如何创建启动
-
25-09-2019 - |
题
我从来没有为Android开发之前,请考虑我100%哑当你回答:)
我想创建一个应用程序启动,将打开默认的Web浏览器到指定的网址。 换句话说,我想打一个图标,我的网站标志,当你点击它,它在默认Web浏览器中打开该网站。
有人能告诉我走向教程/文档页面来实现这一目标? 或者,如果它真的很简单,也许在这里告诉我一些代码?
感谢您的时间!
P
解决方案
如果我明白你需要正确的话,你可以只创建一个简单的应用程序只有1活动,在OnCreate坚持这样的:
Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.yourwebsite.com"));
startActivity(viewIntent);
和这里是关于创建简单的应用程序的一些资源:
这是你如何设置你的应用程序图标的一些信息:
其他提示
我已经写了教程只是此:= 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!
}
}
一行答案
startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url)));
为什么要创建一个应用程序做到这一点?您可以直接在主屏幕上直接创建一个快捷方式。
下面是做什么:点击 1.转到网站在浏览器中点击 2.添加一个书签网站(菜单,添加书签)点击 3.进入主屏幕,在这里你想要的标志点击 4.按住屏幕,当屏幕上弹出菜单中选择“添加快捷方式”点击 5.选择“书签”,点击 6.找到刚才创建的书签,点击它
您完成!!
不隶属于 StackOverflow