I have intent associated with my application.
Eg. Link to an web page.
Sometimes my application can't handle intent and should redirect it to other application (web browser).
The bottom line is that query parameters in link can't be distinguished from another one.
How can I do that?
You can get the Intent that was sent to your activity by simply calling:
Intent i = getIntent();
Then you can make any changes to it (if needed) and send it again by calling:
startActivity(i);
or perhaps:
sendBroadcast(i);
depending on what you want to trigger.
I've ended up with launching Intent chooser.
Related
I have an app that sends a call intent to another app (CsipSimple).
Intent intent = new Intent("android.phone.extra.NEW_CALL_INTENT");
intent.setData(Uri.parse("csip:" + number));
startActivity(intent);
But every time a chooser dialog is poping up to choose the CsipSimple app. Is there a way to avoid this chooser and use directly a defined app.
I found that it is possible to define the class name of the activity:
intent.setClassName("com.csipsimple.ui.outgoingcall", "com.csipsimple.ui.outgoingcall.OutgoingCallChooser");
But this doesn't work, i assume that this can only work if the intent caller and CsipSimple are both in the same process.
I m creating an app which opens another app in the background and my first app will be sending some string as a data to another app, so can I send Intents to another app's like we usually send intents to other classes containing data?
If we can then how can I send it?
Yes , you can send the intent to any app you like but its upto the receiving application to handle it.
Few apps may crash receiving it.
The way
Make an intent
Intent i=new Intent(yourContext,Activity_to_which_you_to_send.class);
Put some data-if you want to
i.putExtraString("key","value");
or put using a bundle
Bundle b=new Bundle();
b.putString(key,boolean_value);
b.putBoolean(key,boolean_value)
Starting the activity
startActivity(i);
Set the package of the app
i.setPackage("com.whatsapp");
Example
if you want to find out the main Activity of an app
go to command line
type adb shell pm -lf
pick any one and try it by passing as a second argument to the intent constructor defined above and then call startActivity method.
hope it helps you.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("text/plain");
intent.putExtra(name,yourString);
try{
startActivity(intent);
} catch (Exception ActivityNotFoundException){
ActivityNotFoundException.printStackTrace();
}
Use this code to send an intent to another app and specify the name value and string in putExtra function.
Yes you can send Intent to another app like we send to other classes with passing data as a string so you can see it HERE
Yes. "App" is not so well defined on Android, it's a loose term. Intents are used to start an Activity, among other things.
In my application, I have an intent-filter registered for one of my activities. When I click on a number in sms/e-mail, dialog is displayed whether I want to call though the standard dial of my phone of though the activity with intent-filter. What I want to do is not just open a particular activity, but also retrieve the number, that was clicked. Is it possible to do?
add the relative info while initializing your intent and then broadcast it.
for example:
Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:000000000"));
where 000000000 is your desired telephone number which may take out from any selected view
use intent.putExtra("key", "value") to set phone number in your intent before sending it, and at receiving side take this value out from your received intent
I've been reading the sample code from the dev docs on Android's site, specifically this:
http://developer.android.com/resources/samples/SampleSyncAdapter/src/com/example/android/samplesync/authenticator/AuthenticatorActivity.html
Which is the sole activity of the sample app. It refers to an intent in the onCreate method. I don't understand where this intent is coming from, or what it should contain if this is the only activity the app utilizes.
Log.i(TAG, "loading data from Intent");
final Intent intent = getIntent();
mUsername = intent.getStringExtra(PARAM_USERNAME);
mAuthtokenType = intent.getStringExtra(PARAM_AUTHTOKEN_TYPE);
mRequestNewAccount = mUsername == null;
mConfirmCredentials = intent.getBooleanExtra(PARAM_CONFIRM_CREDENTIALS, false);
That's the block of code working with the intent. Why would you have an intent for the only activity in the app? Is this app called in an unusual way? The Manifest does not include an intent filter for the activity... I guess I'm just a bit lost on this whole thing! If someone could set me straight that'd be great, thanks.
Why would you have an intent for the only activity in the app?
getIntent() gets you the intent that started this activity.
Is this app called in an unusual way?
I guess this activity is called programmatically from another app or activity, since it has been passed some extra data: getStringExtra() is used to extract some data from the intent that started it. putExtra.. and getExtra.. is a way to pass data between activities when they are started.
In that specific example, the intent is sent from the addAccount method in Authenticator.java. That method is called by the OS when you click the Add Account button in the Accounts & sync settings screen and choose your account type.
Is it possible to open up the default Android Messaging activity from inside an activity you write yourself? Like for example: I press a "Mail" button inside my program, and it opens the Android Messaging app just like as if I was to press the Messaging icon on the main screen.
I did something similar to this with the Contacts activity, but only the contact list comes up, no extra functionality like Adding/Modifying/Deleting, etc.
Any ideas?
edit: I found this way to open the "Compose New Message" Activity, I just need to back it up a step. Does anyone know the correct MIME type instead of this one?
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("vnd.android-dir/mms-sms");
m_activity.startActivity(sendIntent);
This starts the messaging app from another app:
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new ComponentName("com.android.mms","com.android.mms.ui.ConversationList"));
startActivity(intent);
Just put it inside a button listener or whatever user input you want to open it from.
Enjoy :-)
If you want to open the messaging app to view messages and not for sending a message, this should do the job:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setPackage("com.google.android.apps.messaging");
startActivity(intent);