When I create a shortcut for my application, and when I want to delete shortcut with code, how should I do it? I try some method but not used.
The create shortcut code:
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "test");
shortcut.putExtra("duplicate", false);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClass(this, SecondActivity.class);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);`
The delete shortcut code:
actionIntent.addCategory(Intent.CATEGORY_LAUNCHER);
actionIntent.setClass(this, SecondActivity.class);
Intent intent = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "taotao");
intent.putExtra("duplicate", false);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
sendBroadcast(intent);`
Related
Using this i am creating app shortcut, but when user removes it from home screen then how to check
Intent shortcutIntent = new Intent(context, Doctor.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Constants.SEARCH_QUERY_HINT, getResources().getString(R.string.Search_By_name_speciality));
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Doctor");
addIntent.putExtra("duplicate", false);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.doctor));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
I want to choose a file via an Android File Manager.
so, to open file intent code is
Intent intent = new Intent();
intent.setType("file/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select File"), 1);
But I was unable to access file manager in samsung devices to resolve this problem i do
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivityForResult(intent, 1);
But this code in not working in other devices so what should i do to open file manager in all devices ?
private void openFile(int requestCODE) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
startActivityForResult(intent, requestCODE);
}
I'm working on a app-drawer replacement but I'm having trouble giving the user the ability to create home screen icons.
I can create the shortcuts, but I'm struggling to pull the icons from the respective apps.
I collect information on the apps using:
manager = getPackageManager();
apps = new ArrayList<AppDetail>();
Intent i = new Intent(Intent.ACTION_MAIN, null);
i.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> availableActivities = manager.queryIntentActivities(i,0);
Collections.sort(availableActivities, new ResolveInfo.DisplayNameComparator(manager));
for(ResolveInfo ri:availableActivities){
AppDetail app = new AppDetail();
app.name = ri.activityInfo.packageName;
app.label = ri.loadLabel(manager);
app.icon = ri.activityInfo.loadIcon(manager);
app.iconID = ri.getIconResource();
apps.add(app);
But I'm running into troubles when I try to create the shortcut
AppDetail selectedApp = apps.get(info.position);
...
Intent shortcutIntent = new Intent(this, selectedApp.getClass());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, selectedApp.label);
// the danger zone
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getBaseContext(),selectedApp.iconID));
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
finish();
How can I correctly reference the icon file of another app?
Please use
Drawable icon = manager.getApplicationIcon(app.name);
to obtain the icon graphics, and
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, selectedApp.label);
// this line in your code changed
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon.getBitmap());
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
The problem I have is that when this intent is started there are no apps to show. Why is that? I need all apps to be visible since onClick the button will go to any app the user wants to and save it (use this app as default). What could be the solution?
Intent intent = new Intent(Intent.ACTION_ALL_APPS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String title = getResources().getString(R.string.chooser_title);
Intent chooser = Intent.createChooser(intent, title);
chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(chooser);
Try-
Intent pickIntent = new Intent(Intent.ACTION_ALL_APPS);
pickIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
pickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(pickIntent);
This will give you all the apps in a list-
Intent pickIntent = new Intent(Intent.ACTION_MAIN, null);
pickIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List pkgAppsList = getPackageManager().queryIntentActivities( pickIntent, 0);
Log.d(MainActivity.class.getSimpleName(), pkgAppsList.toString());
//startActivity(pickIntent);
pkgAppsList will have the list of all the applications. Hope this solves your problem.
We are building a camera app that saves photos in a specific folder in the gallery. And we have to open the folder of our app in the gallery using an intent. We are using this code however it shows all folders.
View.OnClickListener goToGallery = new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
};
To open gallery I use this intent.
public static final int RESULT_GALLERY = 0;
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent , RESULT_GALLERY );
Try this code.
It will retrieve view pictures under storage/emulated/0/Pictures/MyAppPics
You can change the file path according to your directory path.
File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File f = new File(sdDir, "MyAppPics");
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.withAppendedPath(Uri.fromFile(f), "/MyAppPics"), "image/*");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);