2013年7月28日 星期日

建立shortcut (註冊shortcut)


Shortcuts had existed since API level 1, and can be used by 3rd party apps as well.
To add an activity to the shortcuts manu simply add this intent filter to your activity in your manifest:
    <intent-filter>
        <action android:name="android.intent.action.CREATE_SHORTCUT" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
To make the activity plant a new icon with an intent on the home screen, do this before finishing:
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent());
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "My shortcut");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, myIcon);
setResult(RESULT_OK, intent);
Change the new Intent() to whatever you want launched when this is clicked.
share|improve this answer
----------------------------------------------------------------
As the error message suggests, you could add
android:exported="true"
to your activity.
Although this should be the default value if I read the android documentation right:
android:exported
Whether or not the activity can be launched by components of other applications — "true" if it can be, and "false" if not. If "false", the activity can be launched only by components of the same application or applications with the same user ID. The default value depends on whether the activity contains intent filters. The absence of any filters means that the activity can be invoked only by specifying its exact class name. This implies that the activity is intended only for application-internal use (since others would not know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the activity is intended for external use, so the default value is "true".
Maybe someone else can clarify this.

沒有留言:

張貼留言

Related Posts Plugin for WordPress, Blogger...