2011-06-27 11 views
11

मुझे लगता है कि मैंने इंटरनेट पर मिलने वाले सभी समाधानों का प्रयास किया है, लेकिन कोई भी काम नहीं करता है- कोई बल बंद नहीं होता है, लेकिन डेस्कटॉप पर कुछ भी नहीं दिखाई देता है।डेस्कटॉप पर किसी भी ऐप के लिए शॉर्टकट बनाएं

public Intent getIntentShortcut() 
{  

    Intent i = new Intent(); 
    i.setClassName(packageName, name); 
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    return i; 
} 

और प्रकट में:

<permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> 

मैं क्या याद आ रही है

private void createShortcutOnDesktop(Application app) { 

    Intent shortcutIntent = new Intent(); 
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, app.getIntentShortcut()); 
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, app.getName()); 
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.home_button)); 
    shortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
    this.sendBroadcast(shortcutIntent); 
    finish(); 

} 

app.getIntentShortcut() यह है: अब, मैं इस किया है? धन्यवाद।

+0

संदर्भ के लिए, आपके सवाल का संपादन यह टक्कर अप करने के लिए पर्याप्त है सामने वाले पृष्ठ पर फिर से। –

+1

क्या आप कृपया पूर्ण स्रोत कोड प्रदान कर सकते हैं। – Nirav

उत्तर

15

हल हो गया। बस प्रकट में बदलने के लिए:

इस:

<permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> 
इस के लिए

:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> 

बस एक 'का उपयोग करता है' ¬¬

+0

आपका कोड प्रोग्राम के निष्पादन पर डेस्कटॉप शॉर्टकट उत्पन्न करने लगता है! क्या कोई तरीका है जिसके द्वारा मैं इसे चलाने से पहले ऐप की स्थापना पर डेस्कटॉप आइकन बना सकता हूं। –

+0

नहीं, आप ऐसा नहीं कर सकते क्योंकि जावा कोड मुख्य गतिविधि के अंदर होना चाहिए जो ऐप लॉन्च करते समय चलाया जाता है –

संबंधित मुद्दे