Android adds shortcuts to the desktop to point to a specific webpage

Source: Internet
Author: User
Document directory
  • How does Android call the system's default browser for access?

Today, you need to add a shortcut to the desktop so that you can link to a specific webpage when you click it. I found this article online.

Http://www.moandroid.com /? P = 1699

It was inspired to implement this function.

/*

* Add shortcuts to the desktop

* @ Param icon shortcut icon

* @ Param name shortcut name

* @ Param Uri the intent URI of the shortcut

*/

Public VoidAddshortcut (parcelable icon, string name, Uri URI ){

Intent intentaddshortcut =NewIntent (Action_add_shortcut);

// Add a name

Intentaddshortcut. putextra (intent.Extra_shortcut_name, Name );

// Add an icon

Intentaddshortcut. putextra (intent.Extra_shortcut_icon_resource, Icon );

// Set the launcher's Uri data

Intent intentlauncher =NewIntent ();

Intentlauncher. setdata (URI );

// Add a shortcut startup Method

Intentaddshortcut. putextra (intent.Extra_shortcut_intent, Intentlauncher );

Sendbroadcast (intentaddshortcut );

}

Of course, you also need to add a permission

<Uses-Permission Android: Name ="Com. Android. launcher. Permission. install_shortcut"/>

How to obtain the first parcelable icon is as follows.

Parcelable icon = intent. Specify cuticonresource.Fromcontext(This, R. drawable.Icon);

 

 

How does Android call the system's default browser for access?

 

1. Start the default Android Browser

  1. Intent intent = new intent ();
  2. Intent. setaction ("android. Intent. Action. View ");
  3. Uri content_url = URI. parse ("http://www.cxybl.com ");
  4. Intent. setdata (content_url );
  5. Startactivity (intent );

In this way, android can call the default browser to access the mobile phone.

2. Specify the corresponding browser to access

1. Specify the android browser to access

  1. ("Com. Android. Browser": packagename; "com. Android. browser. browseractivity": Start the main activity)
  2.  
  3.  
  4. Intent intent = new intent ();
  5. Intent. setaction ("android. Intent. Action. View ");
  6. Uri content_url = URI. parse ("http://www.cxybl.com ");
  7. Intent. setdata (content_url );
  8. Intent. setclassname ("com. Android. Browser", "com. Android. browser. browseractivity ");
  9. Startactivity (intent );
  10.  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.