Android shortcut creation failure bug [resolved]

Source: Internet
Author: User

Pay special attention to the following questions about the inability to create shortcuts:

 

In many cases, the meaning of this sentence is to prevent duplicate creation of shortcuts, but the problem I encountered today is that this sentence makes it impossible to create shortcuts on the desktop.

My approach is:

1. Use SharedPreferences to determine whether the application is started for the first time.

2. Use isInstallShortcut () to determine whether there is a shortcut

3. Create a shortcut (

private void createShortCut() {        SharedPreferences userini = getSharedPreferences(                getString(R.string.useriniXML), Activity.MODE_PRIVATE);        Log.e("H3c","sh.."+userini.getInt("seflshotcut", 0));        if (userini.getInt("seflshotcut", 0) == 0) {            m_tool.createShortCut(Main.this);            SharedPreferences.Editor sEdi = userini.edit();            sEdi.putInt("seflshotcut", 1);            sEdi.commit();        }    }

private boolean isInstallShortcut() {        boolean isInstallShortcut = false;        final ContentResolver cr = MarketApplication                .getMarketApplicationContext().getContentResolver();        String AUTHORITY = "com.android.launcher.settings";        Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY                + "/favorites?notify=true");        Cursor c = cr.query(CONTENT_URI,                new String[] { "title", "iconResource" }, "title=?",                new String[] { "XXXX" }, null);        if (c != null && c.getCount() > 0) {            isInstallShortcut = true;        }        if (c != null) {            c.close();        }        if (isInstallShortcut) {            return isInstallShortcut;        }        AUTHORITY = "com.android.launcher2.settings";        CONTENT_URI = Uri.parse("content://" + AUTHORITY                + "/favorites?notify=true");        c = cr.query(CONTENT_URI, new String[] { "title", "iconResource" },                "title=?", new String[] { "XXXX" }, null);        if (c != null && c.getCount() > 0) {            isInstallShortcut = true;        }        return isInstallShortcut;    }

3.

/*** Create shortcuts **/public void createShortCut (Context contxt) {if (isInstallShortcut () {// if it has been created once, no return will be created ;} intent sIntent = new Intent (Intent. ACTION_MAIN); sIntent. addCategory (Intent. CATEGORY_LAUNCHER); // after adding action and category, the sIntent is automatically uninstalled when the program is uninstalled. setClass (contxt, Login. class); Intent installer = new Intent (); // installer. putExtra ("duplicate", false); installer. putExtra ("android. intent. extra. shortcut cut. INTENT ", sIntent); installer. putExtra ("android. intent. extra. shortcut cut. NAME "," XXXX "); installer. putExtra ("android. intent. extra. shortcut cut. ICON_RESOURCE ", Intent. using cuticonresource. fromContext (contxt, R. drawable. icon); installer. setAction ("com. android. launcher. action. INSTALL_SHORTCUT "); contxt. sendBroadcast (installer );}

Test: Click

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.