Reputation: 25
I am very new to android and I want to recreate something like what ES does about pinning items to the desktop. I want to place a icon on the homescreen and then when that icon is selected it will open a specific part of my app. I hope this is understandable. I did some research and I found that I may have to use Intent-filters to listen for the intent....
Upvotes: 0
Views: 97
Reputation: 12919
This creates an intent to add a shortcut to the home screen (launcher):
Intent shortcutIntent = new Intent (this, YourActivity.class);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Title");
addIntent.putExtra("duplicate", false);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
You can then actually add the item by calling:
sendBroadcast(addIntent);
For adding a specific file to your shortcut, you can set the Intent
's data to the address of the data you want to reference to:
addIntent.setData(Uri data);
If the data you add does not have a real address, you will have to implement your own way of adding an identifier for the data.
When the shortcut is pressed, you will be able to read the data from the opening Intent
:
getIntent().getData()
You also need to add the following permission to you AndroidManifest.xml
:
com.android.launcher.permission.INSTALL_SHORTCUT
NOTE: The used mechanism is undocumented, so it may break with a future iteration of Android and might not work with all devices and third-party launchers.
Upvotes: 1
Reputation: 881
so you need your app to launch a specific activity once it's the app is launched ? If this is what you mean then you have to put your activity as a launcher in the manifest.
<activity
android:name=".ActivityName"
android:label="ActivityLabel">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Upvotes: 0