Android Quick shortcuts [passing intent extra(or some data) in shortcuts.xml ]

╄→尐↘猪︶ㄣ 提交于 2020-01-24 12:08:29

问题


While implementing the static Shortcuts using shortcut.xml, i would like to pass few bundle extras with my intent.

need the passed extras to decide on few functionality in the target class after launching the app.

is it possible to access the extras? how and where to access it?

Any leads would be highly appreciated


回答1:


I'm not sure if there is another way, but I use this:

<intent
        android:action="android.intent.action.VIEW"
        android:targetPackage="target.package"
        android:targetClass="activity.with.package">
        <extra android:name="extraID" android:value="extravalue" />
</intent>

Then you can access extras as usual.




回答2:


Than why don't you create dynamic shortcuts?

ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

Intent thirdIntent = new Intent(this,ThirdActivity.class);
thirdIntent.setAction(Intent.ACTION_VIEW);

ShortcutInfo thirdScreenShortcut = new ShortcutInfo.Builder(this, "shortcut_third")
        .setShortLabel("Third Activity")
        .setLongLabel("This is long description for Third Activity")
        .setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
        .setIntent(thirdIntent)
        .build();
shortcutManager.setDynamicShortcuts(Collections.singletonList(thirdScreenShortcut));

You can pass whatever you want to send in Intent and access it to receiver activity.



来源:https://stackoverflow.com/questions/43361498/android-quick-shortcuts-passing-intent-extraor-some-data-in-shortcuts-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!