This is just a cool code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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