Skip to content

Instantly share code, notes, and snippets.

@sidhuparas
Created March 29, 2018 16:26
Show Gist options
  • Save sidhuparas/8b7759de766dc142d834fe65fccc4293 to your computer and use it in GitHub Desktop.
Save sidhuparas/8b7759de766dc142d834fe65fccc4293 to your computer and use it in GitHub Desktop.
This is just a cool code.
private void addShortcut(String path1, String pdfName) {
File file = new File(path1);
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
shortcutIntent.setDataAndType(path, "application/pdf");
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, pdfName);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this.getApplicationContext(),image));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
} else {
Toast.makeText(this, "Some error occurred!", Toast.LENGTH_SHORT).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment