I have a question in mobile apps using Xamarin. Suppose i have implemented 2 Apps like App1 and App2 in same platform(Exp - Android).
As per the business scenario From the App1 I need to switch to App2 in same platform(Assume both apps deployed in android device). But I am not sure how to do this using the Xamarin. Could you please help on this.
Do you mean you want to open App2 in App1 ?If yes
Here are several methods for it:
(1)use package name, specific Activity name pulled up
Intent intent = new Intent(Intent.ActionMain);
/** knows the packet life to jump to and the target Activity*/
ComponentName componentName = new ComponentName(package name, class name);//e.g ComponentName componentName = new ComponentName("kuyu.com.xxxx", "kuyu.com.xxxx.xxx.login.WelcomeActivity");
intent.SetComponent(componentName);
StartActivity(intent);
App2 needs to be added in the manifest file corresponding to the Activity:
android:exported="true"
(2) the package name is pulled up (this is going into the startup page)
Intent intent = PackageManager.GetLaunchIntentForPackage(package name);//e.g Intent intent = PackageManager.GetLaunchIntentForPackage("kuyu.com.xxxx");
if (intent != null)
{
intent.SetFlags(ActivityFlags.NewTask);
StartActivity(intent);
}
(3) url pull up (which as the answer above)
using Xamarin.Essentials;
await Browser.OpenAsync(uri, BrowserLaunchMode.SystemPreferred); }
Or
https://xamarinhelp.com/launching-mobile-app-via-uri-scheme/
I think this will help, and look deep linking in Xamarin :)
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);
On my Application level I receive null for getExtras(), but on Activity level i can see them correctly.
public class MyApplication extends Application
{
#Override
public void onCreate() {
super.onCreate();
Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.MyApp");
if (intent != null){
String mStaticWorldUrl = intent.getStringExtra("arg1Name");
String mStaticWorldIconUrl = intent.getStringExtra("arg2Name");
Log.i("LOG", mStaticWorldUrl + " --- " + mStaticWorldIconUrl);
}
}
}
I'm calling the app from some shortcuts that were created by this code:
(- each shortcut has different Extras sent to the Intent)
// create a shortcut for the specific app
public static void createShortcutForPackage(Context context,
String packageName, String className, String shortcutName,
String arg1Name, String arg1Val, String arg2Name, String arg2Val,
int iconID) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, className));
PackageManager pm = context.getPackageManager();
Context pkgContext = createPackageContext(context, packageName);
if (pkgContext == null)
return;
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
Intent shortcutIntent = pm.getLaunchIntentForPackage(packageName);
if (arg1Name != null)
shortcutIntent.putExtra(arg1Name, arg1Val);
if (arg2Name != null)
shortcutIntent.putExtra(arg2Name, arg2Val);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(context, iconID));
shortcut.putExtra("duplicate", false);
context.sendBroadcast(shortcut);
}
how can I read these Extras on the Application level?
or is there any other way to create different shortcuts for application and read its' "parameters" data on Application?
The Application class is static for the application: there is only ever a single instance of it for your app's process. If your app has been launched with a normal launch Intent, rather than a shortcut you created, then no extras would be present. The app process does not die when HOME or BACK is pressed, so the Intent used to launch the package may not be what you think it should be.
You should not need to look at the Intent at the Application level. Intent objects are not intended to be "sent" there, but rather to an Activity, Service or BroadcastReceiver.
This is conceptual error which facing to get data in application class using getExtra which is the method of Intent
Reason for this issue:
No extras is because the queried intent was one that was generated
one line earlier, it is the intent that the OS has generated for the
package as requested in the following code: Intent intent =
getPackageManager().getLaunchIntentForPackage("com.example.MyApp");
Intent objects within an Application class instance: they are not
delivered there
Let's understand following things to use in upcoming usage while anyone want to get data in application level
What is Intent ?
What is the Use of Intent?
What other things can we use to achieve this?
What is Intent?
An Intent provides a facility for performing Late runtime binding between the code in different applications . Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.
extras - This is a Bundle of any additional information. This can be used to provide extended information to the component. For example, if we have a action to send an e-mail message, we could also include extra pieces of data here to supply a subject, body, etc.
What is the Use of Intent?
Use to intents facilitate communication between components in several ways, Followings are standard use
To start an activity.
To start a service.
To deliver a broadcast
What other things can we use to achieve this?
There are lots of things we can use to achive this and solved this
issue.
But right now here i mentioned only one which is standard and secured
to use application
Content provider: To offer a file from your app to another app is to
send the receiving app the file's content URI and grant temporary
access permissions to that URI. Content URIs with temporary URI
access permissions are secure because they apply only to the app that
receives the URI, and they expire automatically.
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);
I am new to Android. Say, I open an app and I would like to open another App after clicking a button. How can I accomplish this task? Would appreciate if you can provide me some tutorial on this.
Intent intent = new Intent();
intent.setClassName("**package.name**", "**package.name.LauncherActivityName**");
startActivityForResult(intent,REQUEST_CODE);
You need to know the package and class names of the activity to call
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("app package name");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
Use this code:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.package");
startActivity(launchIntent);
The app you want to launch must be on the device.
Intent appIntent = getPackageManager().getLaunchIntentForPackage("your app package name ");
startActivity(appIntent );
If the other application is a pre-packaged application mean, this tutorial may help you.
If the other application is going to be your application, then you need to learn Implicit Intent tutorials.
Also include the activity of the other application which you are planning to call in the Manifest file of the calling package also.
I need to allow user to draw/sketch/paint something. There are already many apps(like Skitch, I will use this as an example) that accomplish this task. So I don't want to re-invent the wheel.
In Android, theoretically, we can launch other activity by intent. This is sort of like "pipe" in Unix.
The problem is, I don't know how to get the information for launching Skitch.
To integrate Skitch in my app, I need to know the Action it supports, the returning intent (if any) when it finishes.
I installed Skitch, photoshop, and lots of other touch drawing apps in my device, but this code doesn't work :
Uri data = Uri.fromFile(file);
Intent i = new Intent(Intent.ACTION_EDIT);
i.setData(data);
i.setType("image/*");
startActivityForResult(i, ACTIVITY_DRAW);
I can launch Skitch from my app in the following way: but obviously I can't get any returned result this way(code from here).
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.evernote.skitch");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
My question: Is there a standard way to find information for launching a third party app?
Is this site the only way to share/get such information?
Or if you have any suggestions for my problem, please help me.
Thank you!
As you might already know how to call another application Activity from your app ..this way Mentioned Here.
Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("<packet name>", "<class name>"));
List list = packageManager.queryIntentActivities(intent, packageManager.COMPONENT_ENABLED_STATE_DEFAULT);
if(list.size() > 0)
{
Log.i("Log", "Have application" + list.size());
startActivity(intent);
}
else
{
Log.i("Log", "None application");
}
All your require is Mainly Two Things to call any Activity
1) Package Name of that Activity
2) Activity Class Name
These two informations only can be available if they are opensource or made free to use .. like Zxing,Google Maps Application.
There is another way to start an application activity like,
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + numberField.getText())); // set the Uri
startActivity(intent);
For this way to use need to know the correct Action for the Activity you want to call and the Correct parameter to pass with.
And again,These information only can be available if they are opensource or made free to use .. like Facebook and Gmail apps to share and post messages.
So If you are searching for anything like which can tell you what you will need to pass to call any specific comercial apps in your device, you wont find it directly.
It's an old question but perhaps it could help somebody to know that Sony's AppXplore application (free) shows the package and name of the activities of every app installed on your device, so you can eventually use them to do explicit Intents.