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