I am trying to open particular activity using shortcut but always run application.
When application is running in background and click on shortcut icon -> particular activity is open.
If application is killed from background then how to open particular activity using shortcut.
* Below method use for create shortcut
private void createShortcutOfApp() {
Intent shortcutIntent = new Intent(getApplicationContext(),
YourTargetActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "App shortcut name");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.mipmap.logo_of_your_app_shortcut));
addIntent
.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent.putExtra("duplicate", false); //may it's already there so don't duplicate
getApplicationContext().sendBroadcast(addIntent);
}
permission in manifest
uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT
define in manifest
android:name=".YourTargetActivity"
android:exported="true"
I am tired to solve this problem, please help me.
Follw below link to know how to open particular activity on relaunch application.
It works for me.
How to make an android app return to the last open activity when relaunched?
Related
I am trying to open Sound settings from my app
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
Sound Settings Activity displays without any issue.
Scenarios After Opening Sound settings page
When I press back button on my device, it is going back to my application.
when I click on back arrow button(top left), it is going to Settings Main Screen.
Issue:
I want to go back to my app when click on back icon also.
startActivityForResult(new Intent(Settings.ACTION_SOUND_SETTINGS), 100);
I have also tried this. but no result.
I am testing this on OnePlus 6 (Android 10 (Q))
Create an intent:
Intent intent = new Intent(Settings.ACTION_SOUND_SETTINGS);
Add these lines to your intent:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
then call startActivity(intent);
I have just downloaded an app on google store and haven't run it. It automatically creates an app home shortcut at my home screen when downloading progress finishes. Every app on google store automatically do that ? If not? How can I do that?
I can create an app home shortcut when launching app at first time with this method:
public void createOrUpdateShortcut() {
appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
isAppInstalled = appPreferences.getBoolean("isAppInstalled", false);
String currentLanguage = Locale.getDefault().getDisplayLanguage();
String previousSetLanguage = appPreferences.getString("phoneLanguage", Locale.getDefault().getDisplayLanguage());
if (!previousSetLanguage.equals(currentLanguage)) {
shortcutReinstall = true;
}
if(!isAppInstalled || shortcutReinstall){
Intent HomeScreenShortCut= new Intent(getApplicationContext(),
BrowserLauncherActivity.class);
HomeScreenShortCut.setAction(Intent.ACTION_MAIN);
HomeScreenShortCut.putExtra("duplicate", false);
if(shortcutReinstall) {
Intent removeIntent = new Intent();
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, HomeScreenShortCut);
String prevAppName = appPreferences.getString("appName", getString(R.string.app_name));
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, prevAppName);
removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(removeIntent);
}
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, HomeScreenShortCut);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
//Make preference true
SharedPreferences.Editor editor = appPreferences.edit();
editor.putBoolean("isAppInstalled", true);
editor.putString("phoneLanguage", currentLanguage);
editor.putString("appName", getString(R.string.app_name));
editor.commit();
}
But I want to create a app home shortcut when installing app without launching because sometimes user don't open my app immediately at google store and they find the app home shortcut to open it after downloading progress finishes.
And I have another issue. My application title for homescreen shortcut can change on phone language change when launching app at first time with that code. But I want it changes immediately without launching.
Are there solutions for my problem? Thanks in advance.
But I want to create a app home shortcut when installing app without launching
That is not possible in general. Nothing of your code will run until either the user launches your launcher activity or something else uses an explicit Intent to start one of your components.
I'm about to launch my first app in a week,and want to know if google play automatically adds the shortcut to the home-screen or is it something if have to do with code. I have question like this but there's nothing about creating shortcut on install.
I launched my app found that Google Play does automatically creates a shortcut on the homescreen and we don't have to do it in our code,although i don't know if it works the same way in Amazon app store. hope this helps someone who is trying to find answer to the same question.
Mohit Madaan's answer was correct. Just don't forget to set duplicate to false otherwise you might have several shortcuts:
addIntent.putExtra("duplicate", false);
put this permission in manifest
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
below for creating the shortcut icon on android Homescreen
private void ShortcutIcon(){
Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Test");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);}
I came across this and I hope this helps you. http://viralpatel.net/blogs/android-install-uninstall-shortcut-example/
I know there is many question about it already.
But today I found this:
My phone is Gallaxy Note 4 and Samsung Gallery app works just as I want
'open App permissions page from Activity!' not setting-detail page.
Anyone knows how to do that?
Here is a method to open Settings > Permissions for your application:
public static void openPermissionSettings(Activity activity) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.parse("package:" + activity.getPackageName()));
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent);
}
You should consider using this when your permission is denied and shouldShowRequestPermissionRationale(Activity activity, String permission) returns true.
OK,I'm new at this forum, so don't blame me for putting this in the wrong tags,not putting something in,eg.
I want to learn how to create a shortcut(I did that by Googling) and link it to an activity (In this case, com.android.mms.ui.ComposeMessageActivity)
I tried doing it, but it only showed me a toast saying "Application not installed" and I'm pretty sure it is.
It would be better if you can display a "complete action with another application" dialog.
If I assumed your question correctly, you mean a button or something within an activity that leads to another activity, that being -- "com.android.mms.ui.ComposeMessageActivity"
if your activity that you want to link to is in another application-- then
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.mine", "com.android.mms.ui.ComposeMessageActivity"));
startActivity(intent);
if it is within the same application, then
Intent intent = new Intent(this, ComposeMessageActivity.class);
startActivity(intent);
//optional add this to your manifest to finish the current loading activity so
//as to not keep it in the activity stack
//<activity android:name="yourActivity" android:noHistory="true" ... />
EDIT If you mean a shortcut on a homescreen, then I would create a tiny application that only has one activity which uses the above method to link to a different application. Then I would drag that application to the home screen, and boom. If there's a better way, then please feel free to correct me