Android how to hide intent sender package? - android

App package name A, send intent with action ACTION_VIEW and url data to system, app B get it and open, but I just want B open intent and don't want app B get app A's package name, How to do it?

The only way to find out the package that sent the Intent seems to be via Acitvity#getReferrer() (taken from this SO post). In its docs, the following is clearly stated
Return information about who launched this activity. If the launching Intent contains an Intent.EXTRA_REFERRER, that will be returned as-is; otherwise, if known, an Intent#URI_ANDROID_APP_SCHEME referrer URI containing the package name that started the Intent will be returned. This may return null if no referrer can be identified -- it is neither explicitly specified, nor is it known which application package was involved.
Hence you can add Intent.EXTRA_REFERRER to the intents you're sending to override the default value.
Ref
https://stackoverflow.com/a/37761737
https://developer.android.com/reference/android/app/Activity#getReferrer()
https://developer.android.com/reference/android/content/Intent#EXTRA_REFERRER

Related

What is the intent for the first activity launched?

When you launch for the first time ,does the starting activity receive any intent?
If it does, where does it come from? which class starts it?
AFAIK it is Looper which is instructed by ActivityManager initiated by eg. App drawer and usually it sends intent with
action = "android.intent.action.MAIN"
and
category = "android.intent.category.LAUNCHER"
Usually there is no data (extras) attached.
You can write your own Launcher it would require do to the following:
get the list of installed packages
check if package responds to intent with fields as mentioned above.
a. If there are multiple classes which resonds to intent you need to handle all of them (add icons)
If user clicks on an icon, send intent to that package with proper intent.

Different types of Android Intents

I have recently started a new Android project and I'm working off the previous developer's code. I'm relatively new to Android and I've come across something that I'm unsure of.
What is the difference between this:
Intent intent = new Intent("com.example.project.MENU");
and this:
Intent intent = new Intent(this, DisplayMenu.class);
I understand what the 2nd code snippet does, I just can't get my head around as to what the first one is doing? Is it referencing the file in the package? Thanks
The first one is an implicit intent, while the second is an explicit intent.
The first one fired an Intent for the action com.example.project.MENU. If you look inside you project AndroidManifest.xml you can see some <intent-filter> balise. This baslise register activity, service or broadcast receiver to different actions.
This mecanism can be used to allow third party app to launch some of your activities.
You can see more on this tutorial http://www.vogella.com/tutorials/AndroidIntent/article.html#intenttypes
Basically an Intent carries some information that are used by the system in order to determine which component should be called for executing the action.
These information are:
Component name: the name of the component that should be launched. (If present the Intent is Explicit)
Action: it specifies the generic action that should be executed (es. ACTION_VIEW, ACTION_SEND). It determines how the rest of the intent is strucutred.
Data: represents the URI that refers to the object that should be associated with the action. For example with the action ACTION_EDIT, the Data should contain the URI of the document that you want modify.
Category: Additional infromation (for example if you want that your app is shown in the launcher you can use CATEGORY_LAUNCHER)
Extras: keys-values pairs that carries additional information
Flags: it is like a metadata that specify how the intent should be managed by the system.
The Intent class provides a lot of different constructors.
The first one you asked for is public Intent (String action)
So, this sets the Action, and lets null all other fields.
The second one public Intent (Context packageContext, Class<?> cls) creates an intent for a specific component by its Component name. All other fields are null. This is a Explicit Intent, since you declare exactly which component should receive it.
The first one is used when you need to call Intent from System
such as Open Camera, Gallery, or Share something to other Application
for example
// this one call Camera to Capture Image
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// this one call gallery to let you select image
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
and That MediaStore.something here is just a Path to the system
for example
MediaStore.ACTION_IMAGE_CAPTURE = "android.media.action.IMAGE_CAPTURE"
Intent.ACTION_PICK = "android.intent.action.PICK"
The first type of intent is mostly used if you want to open another application from your application while the second type of intent is used to open another activity in your application.

Getting a list of all intents from a package

For a project I want to launch a specific application that will be installed on the android tablet.
It's not an application we have any control over (it's entirely third party) and I require a workflow for it similar to the way the Image_Capture Camera Intent works (ie, launch it, wait for it to finish and recieve the data in the onActivityResult function)
While I can launch the application using the following code:
Intent intent = this.getPackageManager().getLaunchIntentForPackage("my.thirdparty.package");
if(intent != null) {
startActivityForResult(intent,MY_INT_FLAG);
} else {
new AlertDialog.Builder(this).setMessage("This device does not appear to have the application installed").setPositiveButton("Okay",null).create().show();
}
it passes a resultCode of 0 (RESULT_CANCELLED) to the onActivityResult straight away since it's just launching the application.
What'd I'd like is to be able to discover a list of intents for a given package. There is a function in PackageManager called getInstalledApplications (which is how I got the package name in the first place) however, the flag PackageManager.GET_INTENT_FILTERS doesn't seem to populate the metaData property of any of the resulting ApplicationInfo objects.
Does anyone have any insight into either getting the intent list, or mining the data out of the APK?

ACTION_SEND intent android

I am trying to pass a url to a specific app using the ACTION_SEND intent, I want to by pass the chooser and just go straight to the app i desire but it doesn't seem to take the url unless i use the chooser..
private void shareIt(){
Intent pC = new Intent(Intent.ACTION_SEND);
pC.setType("text/plain");
pC.putExtra(Intent.EXTRA_TEXT, "http://www.bob.com");
pC.setType("text/plain");
pC.setClassName("com.sec.print.mobileprint","com.sec.print.mobileprint.UI.WebPrint");
//startActivity(pC);
startActivity(Intent.createChooser(pC,"Share jon"));
}
if i comment out the last line and comment back in the line before it.. it opens the app i want bypassing the chooser, but the app opens to google instead of bob.com.. if i leave it as is.. it brings up the chooser and should i choose the app it goes to bob.com .. how can i get it to go to bob.com while bypassing the chooser?
I suspect that the Intent.setClassName method you’re calling takes an unqualified class name as its second argument (after all, why bother repeating the package name qualification?). Alternatively, you can use setClass instead.
Are you sure you need to pass the URL via EXTRA_TEXT and not by pC.setData(Uri.parse("http://www.bob.com");?

Open my application from another in android

My boss asked me to prove that my application behaves properly when summoned by another application (dunno why he asked that).
So I have two apps here, one launches a second one. How I launch the specific app I want? Using Intent launch seemly any generic app that reaches a certain goal, not the app I really want.
Give this a try.
Intent secondIntent = new Intent();
secondIntent.setAction(Intent.ACTION_MAIN);
secondIntent.setClassName("com.example", "com.example.YourSecondApp");
startActivity(secondIntent);
I should point out that com.example should be the package of your second application (the one you want to call) and com.example.YourSecondapp is the class name where you have your onCreate() method.
Intent secondApp = new Intent("com.test.SecondApp");
startActivity(secondApp);
Check out for more examples
http://developer.android.com/resources/faq/commontasks.html#opennewscreen
Create one Intent using the following code
Explicit Intent
When you know the particular component(activity/service) to be loaded
Intent intent = new Intent();
intent.setClass("className/package name");
start<Activity/Service>(intent);
Imlicit Intent
When we do not have the idea which class to load and we know the Action to be perform by the launched application we can go with this intent.
Action needs to set, and the Android run time fallows the intent Resolution technique and list out(one or more components) the components to perform the action. from the list out components (if more than one), user will get the chance to launch his chosen application

Categories

Resources