Android Intent, send parameters? - android

So, I've been checking a couple of posts related to opening apps from the browser but my question is.
If I want to open the app but I also want to send a string in the link (the string will containt some passcode to open a certain part of the app that needs to load some specific information depending on the string I send)
How to achieve this? So far I can open the app and also have a fallback url if the app is not installed. Where can I put the parameter I'm trying to send?
In the example it opens the app, but how can I send say, a variable code="112233code"?
Take a QR code
Thanks!

Here's a question that might help you!
I don't know how you open your app from the browser, but if you are using an intent like this:
Do Whatever
Then you can enconde your parameter like this:
Do Whatever
This will pass an extra String called "mycode" with the value "112233code".
In your Android app, you can recover those extras in the onCreate method in the following way:
Bundle extras= getIntent().getExtras();
if (extras != null){
String mycode= extras.getString("mycode");
}

Related

How to know if an activity is opened from a link in android and fetch the GET parameter from the link?

I have both website and android application for the website.when user clicks on a link of my website it opens that up in my android application. But the problem is there is an important information present in the link which i need to fetch and the activity will make a server request upon that. To be precised the link looks like this: www.example.com/post.php?id=123 I need to get the ID part of the link when the activity is opened so that I can show information about posts bearing the ID. I have added the opening of the link in my app with help of intent filter but I am stuck at getting the GET parameter of the link.How to do that?
Once your activity is opened via the link, you can retrieve that URL from the intent like so:
String url = getIntent().getData().toString();
Then you can use .substring to get the parameters:
String id = url.substring(url.indexOf("id=") + 3)
OR, you can use Airbnb's library to achieve the result in a more elegant way, you can learn about it on their GitHub repo.
myLink = string.substring(string.lastIndexOf('=') + 1);
If the string/url was www.example.com/post.php?id=123 the string will now return 123.

Import app's packages without sending the actual code

I have written an android app, and now another app needs to use some of my data (both apps will be on the same device so access to the database is granted). How can the second app import my packages without having the actual code? Or what should I send in order for the second app to have access to my functions without actually seeing the implementation? Thank you!
You can use Content Provider
OR
Services using aidl
Try something like below. Put below code in your main activity from where you want to pass the data.
Intent i = new Intent("com.your_app_package_name.your_app_name.ActivtiyAlpha");
i.putExtra("KEY_DATA_EXTRA_FROM_ACTV_B", myString);
// add extras to any other data you want to send to b
and in other activity.
Bundle b = getIntent().getExtras;
if(b!=null){
String myString = b.getString("KEY_DATA_EXTRA_FROM_ACTV_B");
// and any other data that the other app sent
}

Unable to passing value to another activity in Android

I want to sent value to another activity. I'm using VS 2012 C# for developing apps. I have done lot of search from google. I have tried almost every methods. in my application getIntent(); giving error. that is, getIntent() does not exist in the current context.
I'm also not getting these below functions in my application.
Intent sender=getIntent();
getApplicationContext();
I have added all references. Help me where Am I wrong?
I got answer, I have to use below line of for getting value:
string extraData = Intent.GetStringExtra("KeyName");

ACTION_SEND Intent with custom extras causing other apps to crash

I'm implementing an option for sharing content from my app. When the user presses the share button the following code is executed.
public static void openShareIntent(Context context, String text, Wish wish)
{
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, text);
share.putExtra("share_wish", wish);
startIntent(context, share);
}
I'm setting one special extra for my Intent, that is object wish witch implements the Parcelable interface.
This object contains some extra information. I want to use this information if the user selects my app (current app actually sharing content) from the available apps for sharing text/plain.
But the problem is that all other popular apps (Facebook, Twitter, ...) and built-in apps (Messaging) crash when I include my Parcable object. It's not my applications that crashes, other apps are throwing quit unexpectedly error.
When I call my SharingActivity with some extra name that is not known to this Activity, it does not crash. It just ignore that extra.
Wish object source code
Am I doing something wrong or what?
Is this not possible because other apps don't know my Wish object?
But the problem is that all other popular apps (Facebook, Twitter, ...) and built-in apps (Messaging) crash when I include my Parcable object.
Never pass a custom Parcelable object to an app that lacks your Parcelable class definition.
Is this not possible because other apps don't know my Wish object?
Correct.
Instead, pass an identifier (string, int, whatever) that SharingActivity can use to find your Wish from your central data model.
Or, instead of creating a custom Wish, use a Bundle to represent the "wish", as Bundle has a common class definition across all apps.
You could just put your data in a bundle and send it with intent as well.
eg:
Bundle b = new Bundle();
b.putParcelable("object_key", yourObject);
shareIntent.putExtra("bundle_key", b);

get additional info from the link which launched my app

my app launches on clicking a link.
But there is additional information that the link contains which my app wants.
The link is something like this :
http://update_app_config.com?parameter1='value1'&parameter2='value2'&parameter3='value3'
can I get an object of key,value pair which contains the parameter and values or do I have to parse it myself?
Thanks
getIntent().getUri() will return a Uri object representing the link used to launch your app. You can then call methods like getQueryParameterNames() and getQueryParameters() to access the query parameters (stuff to the right of the ?).

Categories

Resources