I have published my app now and found that it is creating two shortcut icons where as when I install through android studio it creates only one shortcut. I have added duplicate false and sharedpreference has also been used to check once icon is created. Why the app behaving different and how can I fix it now? This is my code for creating shortcut.
public void createShortCut() {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(StartupActivity.this).edit();
editor.putBoolean("shortcut", true).apply();
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutintent.putExtra("duplicate", false);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Smart App");
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), SplashScreen.class));
sendBroadcast(shortcutintent);
}
and before calling above method I have below code which runs on activity start.
if (!sharedPreferences.getBoolean("shortcut", false)) {
createShortCut();
}
When you install from Android Studio (directly from an .apk), no shortcut is made. However, apps installed from the Google Play Store will automatically sometimes create a shortcut after installation.
So when a user installs your app from the play store, two shortcuts are made, one from your app and one from the installation.
EDIT: This solution might prove useful to you: How to detect shortcut in Home screen
Related
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?
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/
Where does one actually place the code to launch the ParseLoginUI activity?
ParseLoginBuilder builder = new ParseLoginBuilder(MainActivity.this);
startActivityForResult(builder.build(), 0);
Is it in the ParseLoginDispatchActivity? This was not made very clear at all within any of the official documentation:
https://github.com/ParsePlatform/ParseUI-Android
https://www.parse.com/docs/android/guide#user-interface
I'm importing ParseLoginUI into my existing app. What do I once I've installed everything, updated my manifests, my build.gradle and now want to actually launch the Login activity once my app launches?
Do I put something in my manifest to indicate that the ParseLoginActivity should launch first? That doesn't seem to work as an Activity from my main application is required to launch as the initial intent. I'm a little lost here... Any thoughts?
Well I did find one solution, albeit a trivial one:
Intent loginIntent = new Intent(MainActivity.this, ParseLoginActivity.class); startActivity(loginIntent);
I launched the above Intent with an options menu item, but you could do it with a button or whatever else suits your needs.
If you're importing ParseLoginUI into an existing app, it appears you can just launch ParseLoginActivity with a simple Intent. I wish they mentioned this on their integration tutorial. Seems like the most straightforward way to get it running.
This solution definitely launches the Activity you want, but it doesn't check for whether the user is logged in or not and hence doesn't redirect you to the appropriate pages in your log-in flow (which I believe has more to do with your Manifest). It does, however, allow you to successfully register a user and log in with Parse, which is a great start.
A better solution would be to add the following to the onCreate method in the Activity that launches when your app launches. So if when your app launches you land on FirstActivity, the following will check to see if you are logged in. If you are not, you will be sent the login screen, and if you are logged in you will be sent to the second Activity, which is presumably where your users will want to be when they open your app.
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
Intent launchMainActivity = new Intent(this, SecondActivity.class);
startActivity(launchMainActivity );
} else {
ParseLoginBuilder builder = new ParseLoginBuilder(FirstActivity.this);
startActivityForResult(builder.build(), 0);
}
I'm trying to make a button in my App open the built in gallery.
public void onClick(View v) {
Intent intentBrowseFiles = new Intent(Intent.ACTION_VIEW);
intentBrowseFiles.setType("image/*");
intentBrowseFiles.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentBrowseFiles);
}
This results in an error message "The application Camera (process com.android.gallery) has stopped unexpectedly."
If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.
I'm trying to make a button in my App open the built in browser.
Your question subject says "Gallery". Your first sentence in the question says "browser". These are not the same thing.
If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.
Of course, actually telling us "what [you] want" would just be too useful, so you are making us guess.
I am going to go out on a limb and guess that you are trying to open the Gallery application just as a normal application. Note that there is no Gallery application in the Android OS. There may or may not be a Gallery application on any given device, and it may or may not be one from the Android open source project.
However, for devices that have the Android Market on them, they should support an ACTION_VIEW Intent with a MIME type obtained from android.provider.MediaStore.Images.Media.CONTENT_TYPE.