2017-10-10 13 views
5

In the documentation एंड्रॉइड ओ में नए "पिन किए गए शॉर्टकट्स" फीचर के लिए, वे उल्लेख करते हैं कि "आप एक विशेष गतिविधि भी बना सकते हैं जो उपयोगकर्ताओं को शॉर्टकट बनाने में मदद करता है, कस्टम विकल्प और पुष्टिकरण बटन के साथ पूरा करता है" ।एंड्रॉइड ओ पिन किए गए शॉर्टकट्स - CREATE_SHORTCUT इरादा फ़िल्टर

मैं प्रलेखन निम्नलिखित की कोशिश की, लेकिन जब मैं एक नया शॉर्टकट बनाने की कोशिश की मैं केवल डिफ़ॉल्ट संवाद मेरी गतिविधि को देखा, और नहीं। - कैसे मुझे लगता है कि स्क्रीन पर मिलता है

<activity android:name=".ShortcutActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.CREATE_SHORTCUT"/> 
     </intent-filter> 
    </activity> 

पी.एस
प्रलेखन में उन्होंने यह भी Gmail ऐप्लिकेशन में एक उदाहरण दिखाता है:

यहाँ प्रकट में घोषणा है? मैं प्रवाह देखना चाहता था लेकिन मुझे यह नहीं मिला।

+0

आप मेटा को शामिल किया है डेटा –

+0

@OriWasserman की जाँच मेरी अद्यतन जवाब –

उत्तर

-2

एक नया संसाधन फ़ाइल बनाएँ: रेस/xml/shortcuts.xml। इस तरह आप, शॉर्टकट बनाने के बाद आप प्रकट में प्रकट

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> 
     <shortcut 
     android:shortcutId="compose" 
     android:enabled="true" 
     android:icon="@drawable/compose_icon" 
     android:shortcutShortLabel="@string/compose_shortcut_short_label1" 
     android:shortcutLongLabel="@string/compose_shortcut_long_label1" 
     android:shortcutDisabledMessage="@string/compose_disabled_message1"> 
     <intent 
      android:action="android.intent.action.VIEW" 
      android:targetPackage="your package" 
      android:targetClass="com.example.myapplication.ComposeActivity" /> 
     </shortcut> 
     <!-- Specify more shortcuts here. --> 
    </shortcuts> 

में nessicary परिवर्तन किया है गतिविधि टैग में यह जोड़ने के लिए,

<meta-data android:name="android.app.shortcuts" 
       android:resource="@xml/shortcuts" /> 

आप पढ़ना चाहते हैं है और इस संदर्भ लें doc यह पिन किए गए शॉर्टकट्स, स्थिर और गतिशील शॉर्टकट के बारे में बताता है।

यहाँ गूगल से एक example है, में उनके नमूने

+0

स्थिर और गतिशील शॉर्टकट के लिए केवल यह नहीं है? मैं पिन किए गए शॉर्टकट के बारे में पूछ रहा हूं।मेरी समस्या शॉर्टकट बनाने के साथ नहीं है, केवल वे कस्टम गतिविधि जिसका उल्लेख कर रहे हैं –

0

रेपो आप में जावा वर्ग

ShortcutManager sM = c.getSystemService(ShortcutManager.class); 

    Intent intent2 = new Intent(c.getApplicationContext(), ShortcutActivity.class); 
    intent2.setAction(Intent.ACTION_VIEW); 
    ShortcutInfo shortcut2 = new ShortcutInfo.Builder(c,MSG_SHORCUT_CUSTOM) 
      .setIntent(intent2) 
      .setShortLabel("ShortLabel") 
      .setLongLabel("LongLaber") 
      .setDisabledMessage("DisabledMessage") 
      .setIcon(Icon.createWithResource(c, R.mipmap.ic_add_outline_short)) 
      .build(); 
    listshortcut.add(shortcut2); 

    Intent pinnedShortcutCallbackIntent = mShortcutManager.createShortcutResultIntent(shortcut2); 
    PendingIntent successCallback = PendingIntent.getBroadcast(context, 0, pinnedShortcutCallbackIntent, 0); 

mShortcutManager.requestPinShortcut(pinShortcutInfo, successCallback.getIntentSender()); 
    sM.setDynamicShortcuts(listshortcut); 
0

सम्मिलित ACTION_CREATE_SHORTCUT, एप्लिकेशन आइकन पर लंबे समय नल, और प्रेस के रूप में कार्रवाई के साथ अपने शॉर्टकट गतिविधि लॉन्च करने के लिए विजेट आइकन, आपको एक 1x1 विजेट दिखाई देगा, जिस पर आपकी वांछित गतिविधि लॉन्च की जाएगी।

इसके अलावा, आप स्पष्ट रूप से अपने ऐप्लिकेशन से उस आशय के साथ-साथ पर फिर वांछित क्रिया आग कर सकते हैं।

3

आप संवाद के रूप में एक नई गतिविधि बनाने के लिए है, तो आप जो कुछ भी विकल्प आपको लगता है कि संवाद पर चाहते हैं जोड़ सकते हैं और संभाल कर सकते हैं के रूप में आप addShortcut विधि चाहते हैं।

मैं जोड़ सकते हैं और एक गतिशील शॉर्टकट दूर करने के लिए है कि कोड की कोशिश की और यह काम किया।

AndroidManifest.xml

<activity android:name=".DialogActivity" 
     android:excludeFromRecents="true" 
     android:theme="@style/Theme.AppCompat.Dialog" 
     > 
... 
</activity> 

DialogActivity.java

public class DialogActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_dialog); 
     this.setFinishOnTouchOutside(false); 
     findViewById(R.id.add_button).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       addShortcut(); 
      } 
     }); 
     findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       finish(); 
      } 
     }); 
    } 
    ... 
} 

activity_dialog.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_dialog" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.metax.myapplication.DialogActivity"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Do you want to add shortcut?"/> 

    <Button 
     android:id="@+id/cancel_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:layout_alignParentStart="true" 
     android:text="No thanks"/> 
    <Button 
     android:id="@+id/add_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:layout_alignParentEnd="true" 
     android:text="Add me"/> 
</RelativeLayout> 
संबंधित मुद्दे