2014-10-06 95 views
0

我想做一个网站的快捷方式,我也混淆了如何使我的问题。 我使用下面的代码,但当我点击我的应用程序下的手机的应用程序部分,它只给我一个空白页面,但我发现它在主屏幕上创建一个快捷方式。在主屏幕上的android的网站的快捷方式

有什么办法让应用程序部分的快捷方式像其他网页一样:gmail,我希望网页不要再使用任何浏览器,比如我们点击打开网页时的gmail图标,以及不要使用浏览器。 如果我的问题不清楚,我真的需要帮助,原谅我。在此先感谢

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 


    Intent i = new Intent(); 
    i.setAction(Intent.ACTION_VIEW); 
    i.setData(Uri.parse("http://www.facebook.com")); 


    Intent installer = new Intent(); 
    installer.putExtra("android.intent.extra.shortcut.INTENT", i); 
    installer.putExtra("android.intent.extra.shortcut.NAME", "facebook"); 
    installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", "I THINK this is a bitmap"); //can also be ignored too 
    installer.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
    sendBroadcast(installer); 


} 

清单文件

回答

0

对不起,我在第一次误解。解决这个问题的方法之一是只是使搜索的启动活动的应用程序来处理URL的意图,像这样:

String url = getString(R.string.facebook_url); 
Intent i = new Intent(Intent.ACTION_VIEW); 
i.setData(Uri.parse(url)); 
startActivity(i); 

这是一个位的奇数的事情,虽然这取决于你的使用情况。记住你可以有多个启动器活动,所以你可以添加它,它不会干扰你的主应用程序。然而,这可能不是你实际想要在生产中发布的东西,因为用户不喜欢它。

+0

感谢您理解我的问题。你能告诉我应该如何在这里传递字符串中的网址。 String url = getString(R.string。“www.facebook.com”); – kiran 2014-10-07 13:32:42

+0

你可以简单地对字符串进行硬编码。 String url =“facebok.com”; 我建议要求你在项目的strings.xml文件中放置一个facebook_url。你可以这样做。那有意义吗? – dabluck 2014-10-07 14:49:43

+0

对不起,我不明白你能告诉我如何在strings.xml文件中使用。其实我是新来的Java和Android。 – kiran 2014-10-07 15:06:46

相关问题