So, there are apps that can create shortcuts on the home screen.
My question is, How can my app opens/runs/starts a certain shortcut?
if I have 2 browser shortcuts, each of them loads a different url ... how can I choose between them? how to choose to open the 1st or the second one?
To open a URL/website you do the following:
String url = "http://www.example.com";
Intent mIntent = new Intent(Intent.ACTION_VIEW);
mIntent.setData(Uri.parse(url));
startActivity(mIntent);
Here's the documentation of Intent.ACTION_VIEW.
Related
I am looking for a way to create shortcuts from other apps.
Like launchs can query the apps that allow to create shortcuts and create them save them in thier program.
My API version is between M(21) to N7.1(25).
Even just a link or name of API it's fine. I just couldn't find it at all. All I found is about the new shortcut in android N.
Thx for ur time.
I found the way to do it. Since i don't see much info for this. I hope my share can help whoever is also looking for the answer.
So there will be 3 steps:
Get apps that can create shortcuts
Send Intent to the app that you want to create shortcut from
Get shortcut data in Activity.onActivityResult
1.
Since I just need to create shortcuts from certain apps. I skipped step one. But I guess using queryIntentActivities(...) or some other functions in PackageManager can get you the list.
Intent intent = new Intent("android.intent.action.CREATE_SHORTCUT");
PackageManager.queryIntentActitvies(intent,0);
2. Send intent to the app to create a shortcut.
Intent intent = new Intent("android.intent.action.CREATE_SHORTCUT");
intent.setComponent(...);
startActivityForResult(intent, requestCode);
3. Get data of shortcut:
Shortcut intent
Intent shortcutIntent = activityResultIntent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
Shortcut name
String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Shortcut icon
Bitmap shortcutIcon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
Is there any way to, in my app, to redirect a user to a specific settings 'page'? My app works as a lock screen app, so I want to be able to redirect the user directly to the "Lock Screen" section of the Android settings. (Preferably via a button or something similar)
ACTION_SECURITY_SETTINGS Intent:
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivity(intent);
For complete Settings Intents
I managed to find the correct answer in an old Stackoverflow-post from a while back. The code snippet now looks like this:
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivity(intent);
val intent = Intent(Settings.ACTION_SECURITY_SETTINGS)
intent.flags =
Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_CLEAR_TOP
startActivity(intent)
Note the flags. These are optional, but necessary to remove the previous settings screen from the screen if it was previously open (this is needed if your application wants to open multiple settings screens).
I have an android application that requires VPN. My users will be using Galaxy Note 3's and will be using the built in "VPN Client" (com.ipsec.vpnclient). I need to find a way to launch this application from my application, in the instance of the VPN dropping. I've already figured out a way to determine if the VPN dropped, but I still need a way to launch the application.
ANSWER:
Thanks to help from #Muthu I was able to get it working with the following method.
final Intent intent = new Intent("android.intent.action.VIEW");
intent.setComponent(new ComponentName("com.ipsec.vpnclient", "com.ipsec.vpnclient.MainActivity"));
EDIT:
To add to the confusion, I am easily able to add a shortcut to the activity (com.ipsec.vpnclient.MainActivity) via another Launcher like ADW or Nova. I also tried using com.ipsec.vpnclient.MainActivity instead of com.ipsec.vpnclient in the method below, to no avail.
Intent intent = getPackageManager().getLaunchIntentForPackage("com.ipsec.vpnclient");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
The above method works with other packages, but I can't seem to get this one to launch.
Here is the application when viewed in Android System Info.
Any ideas on how to launch this application programmatically?
You can Start any installed application by using intent. in your case like this
Intent LaunchVPN = getPackageManager().getLaunchIntentForPackage("com.ipsec.vpnclient");
startActivity( LaunchVPN );
Edit
You can open pre installed apps that can be found inside settings page by
final Intent i = new Intent("android.intent.action.VIEW");
i.setComponent(new ComponentName("com.android.settings","com.android.settings.InstalledAppDetails"));
startActivity(i);
Launching a specific browser by icon is done with a ACTION_MAIN.
Launching a specific url using default browser is done with a ACTION_VIEW.
What if you want to open a specific url in a specific browser?
If you know the package name and the class name of the browser,you can use
Intent.setClassName (String packageName, String className). looks like:
Intent i=new Intent(ACTION_VIEW, url);
i.setClassName("com.test.browser","BrowserActivity");
startActivity(i);
You can even call the specific browser via its package name.
Like this;
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.google.co.com"));
intent.setPackage("org.mozilla.firefox");
startActivity(intent);
I think this is a setting. You go to the Application Manager and go to your favorite Browser. Then at the Options it should show you to be your default.
I am not an Android Developer by the way...
I'm developing a pre-load-type application... the desktop icon needs to take you directly to the market details page where you can download the full app. i can't seem to figure out how to go straight to the market, bypassing any kind of actual application screen.. the application screen loads for a split second, displaying the value from the android:label tag from the manifest... then the market details loads.
Step #1: Add android:theme="#android:style/Theme.NoDisplay" to the <activity> element for your launcher activity.
Step #2: Call finish() just after calling startActivity() to bring up the Market activity.
try this:
Uri marketUri = Uri.parse("market://details?id=" + packageName);
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
startActivity(marketIntent);