1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-16 01:12:08 +01:00

implement create launcher shortcut

This commit is contained in:
chizoba 2017-10-05 16:26:15 +01:00
parent ac8b8469b0
commit a558a463ef
4 changed files with 24 additions and 0 deletions

View file

@ -7,6 +7,8 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
// Permission to install shortcut icon
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<application <application
android:name="com.github.dfa.diaspora_android.App" android:name="com.github.dfa.diaspora_android.App"

View file

@ -1158,6 +1158,22 @@ public class MainActivity extends ThemedActivity
startActivity(new Intent(MainActivity.this, AboutActivity.class)); startActivity(new Intent(MainActivity.this, AboutActivity.class));
} }
break; break;
case R.id.nav_shortcut: {
Intent shortcutIntent = new Intent(MainActivity.this, MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
// The intent responsible for creating the shortcut
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(MainActivity.this, R.drawable.ic_launcher));
// To install shortcut
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
// Notify user of the shortcut created
Snackbar.make(fragmentContainer, R.string.shortcut_created, Snackbar.LENGTH_LONG).show();
}
break;
} }
navDrawer.closeDrawer(GravityCompat.START); navDrawer.closeDrawer(GravityCompat.START);

View file

@ -90,6 +90,10 @@
android:id="@+id/nav_about" android:id="@+id/nav_about"
android:icon="@drawable/ic_info_black_48px" android:icon="@drawable/ic_info_black_48px"
android:title="@string/nav_help_license" /> android:title="@string/nav_help_license" />
<item
android:id="@+id/nav_shortcut"
android:title="@string/nav_add_shortcut" />
</group> </group>
</menu> </menu>

View file

@ -96,4 +96,6 @@
<string name="jump_to_last_visited_timestamp_in_stream">Jump to last visited page in stream?</string> <string name="jump_to_last_visited_timestamp_in_stream">Jump to last visited page in stream?</string>
<string name="pref_summary__is_statusbar_hidden">Hide statusbar at main view</string> <string name="pref_summary__is_statusbar_hidden">Hide statusbar at main view</string>
<string name="pref_title__is_statusbar_hidden">Hide statusbar</string> <string name="pref_title__is_statusbar_hidden">Hide statusbar</string>
<string name="nav_add_shortcut">Add Launcher Shortcut</string>
<string name="shortcut_created">Shortcut Created</string>
</resources> </resources>