Import app's packages without sending the actual code - android

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
}

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.

Android Intent, send parameters?

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");
}

How to get the package name of an external app which calls my app

My app com.test.sample is invoked by an external app com.testExternal.outsideApp. The external app uses an intent to invoke the MainActivity of com.test.sample by calling the startActivityForResult. What I am looking for is a way to programmatically obtain the package name of the external app. I tried several ways like
String parentPackageName = this.getParent().getPackageName();
//This fails since the parent is always returning NULL.
String packageName = this.getIntent().getPackage();
//This returns the package name of the current application which is not what I want.
Is there any other way to get the package name of the caller app?
You can do it if your application was started with Activity#startActivityForResult by using Activity#getCallingActivity().

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");

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