Launching custom implicit intent - android

Two activities are installed having the following manifest files on device respectively:
The First app's activity has in its manifest:-
where,
package="com.example.tictactoe"
<intent-filter>
<action android:name="com.example.tictactoe.YOYO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
The second app's activity has in its manifest:-
where,
package="com.example.project"
<intent-filter>
<action android:name="com.example.project.YOYO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
Now, i want to start one of these activity from third application using the following code:
i=new Intent();
i.setAction("YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);
But execution shows an error:-
03-11 08:12:30.496: E/AndroidRuntime(1744): FATAL EXCEPTION: main
03-11 08:12:30.496: E/AndroidRuntime(1744): android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=ACTION_SEND (has extras) }

You need to supply the full action name; supply the mimeType you used in manifest by calling setType() in your intent.
Manifest :
<intent-filter>
<action android:name="com.example.tictactoe.YOYO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
Java :
Intent i=new Intent();
i.setAction("com.example.tictactoe.YOYO");
i.setType("text/plain");
i.putExtra("KEY","HI..i am from third app");
startActivity(i);

You need to supply the full action:
i=new Intent();
i.setAction("com.example.tictactoe.YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);
Or (depending which project you want to launch):
i.setAction("com.example.project.YOYO");
You can do it also via: (supply action directly in constructor)
i=new Intent("com.example.tictactoe.YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);
Also loose the data mimeType or read up on how to use it. Because via putExtra is not going to work.

First of all you need to ensure that the name of the intent is the fully qualified name with the package name is the same in the intent filter and the activity firing the intent. In this case: "YOYO" should be "com.example.tictactoe.YOYO". You should also remove the mime type since you are not including data in the setData(), you are in this case using a bundle. So you should have for the activity firing the intent:
ACTIVITY FIRING INTENT
i=new Intent();
i.setAction("com.example.tictactoe.YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);
and for the receiving activity's entry in the manifest: You need to ensure you set the category as DEFAULT and remove the data type tag.
ACTIVITY RECEIVING INTENT
<intent-filter>
<action android:name="com.example.tictactoe.YOYO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Related

Can not list app using intent filter in Broadcast Receiver

I want to list apps (with same intent filter). I was able to achieve this by adding intent filter to an activity
<activity
android:name=".Activities.MainActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustNothing">
<intent-filter>
<action android:name="com.example.identifier" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="isApp" />
</intent-filter>
</activity>
and i could retrieve all apps having this intent with
String uri = "isApp:";
Intent intent = new Intent("com.example.identifier",
Uri.parse(uri));
PackageManager manager = getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(intent, 0);
However, this launches the activity when shown in intentChoose using this snippet:
Intent zoneIntent = new Intent("com.example.identifier",
Uri.parse(uri));
Intent openInChooser = Intent.createChooser(zoneIntent, "Complete Action with").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(openInChooser);
But i would want this to call a broadcast receiver. So, i moved the intent to a broadcast receiver in AndroidManifest.xml like:
<receiver
android:name=".ExampleReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.example.identifier" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="isApp" />
</intent-filter>
</receiver>
and the snippet that returns the number of apps with this intent returns 0 now even when the app is still on this device. Could this be done with Broadcast receiver or should i consider with another approach. Thanks.
Calling queryIntentActivities() will only return Activitys. It won't return BroadcastReceivers. If you want to do this with BroadcastReceivers, then you need to call queryBroadcastReceivers() instead.

Implicit Intent with user-specified action

I'm experimenting, specifying my own action for use in an implicit intent. In a single package, I define two activities. ActivityTwo is to be called from onClick() in ActivityOne, using an implicit intent with an action "course.labs.activitylab.MY_ACTION". But I haven't been able to make it work.
In strings.xml:
<string name="myfunnystring">course.labs.activitylab.MY_ACTION</string>
In AndroidManifest.xml:
<activity
android:name=".ActivityTwo"
android:label="#string/title_activity_activity_two" >
<intent-filter>
<action android:name="#string/myfunnystring" />
</intent-filter>
</activity>
In onClick() in the OnClickListener() in onCreate() in ActivityOne.java:
Intent intent = new Intent();
intent.setAction(getString(R.string.myfunnystring));
intent.setFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
startActivity(intent);
The program crashes in the emulator, and I find this in the logcat window:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=course.labs.activitylab.MY_ACTION flg=0x8 }
What am I doing wrong?
Add the default category to your intent filter.
<intent-filter>
<action android:name="course.labs.activitylab.MY_ACTION" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

Activity not appearing on Chooser dialog when using Implicit Intent

I would like to start MyBrowser, an application that show web pages like the built-in Browser app, from another application, IntentsLab.
I followed Launch custom android application from android browser to setup the intent, and also the official Intent and Intent-filters guide which does says "You need to include CATEGORY_DEFAULT to receive implicit intents".
So my intent-filter is so written:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.categroy.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
The code of the parent activity in IntentsLab to start the new activity is:
Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
String title = "Use Browser";
Intent chooserIntent = Intent.createChooser(baseIntent, title);
if(chooserIntent != null) startActivity(chooserIntent);
The MyBrowser application does not show up on the chooser dialog. However, when I created an Activity inside the IntentsLab and added to it a same intent-filter, this activity shows up in the chooser dialog. Is there anything wrong with the code? Or is there any difference between implicit intent towards Activities in a same Application with those in a different one?
Provided my AndroidManifest.xml for the MyBrowserActivity. It works perfectly for me. Even I am doing the coursera Android programming class :)
<activity android:name=".MyBrowserActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- TODO - Add necessary intent filter information so that this
Activity will accept Intents with the
action "android.intent.action.VIEW" and with an "http"
schemed URL -->
</activity>

Android Intent-filter problem

I'm trying to write an intent-filter to select a contact from the list of contacts (for purely educational purposes... I'm learning about intents). After calling startActivity on an implicit intent, android should find my custom activity as well as the default activity as candidate Activities and let me choose which one I want to use (intent resolution).
However, with my current setup, it opens android's default contact picker without giving me the choice. Here is my intent-filter.
<activity android:name=".ContactPicker" android:label="PICKER" >
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" android:host="com.android.contacts" android:path="contacts" />
</intent-filter>
</activity>
and here is how I am calling the implicit intent on the main activity:
Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://com.android.contacts/contacts"));
startActivityForResult(intent, PICK_CONTACT);
Try:
<intent-filter>
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="vnd.android.cursor.dir/contact"/>
</intent-filter>

Launch Skype from an App Programmatically & Pass Number - Android

Trying to launch and pass tel. no. to skype by this code from my app:
PackageManager packageManager = getPackageManager();
Intent skype = packageManager.getLaunchIntentForPackage("com.skype.raider");
skype.setData(Uri.parse("tel:65465446"));
startActivity(skype);
Skype is launched but it can't catch the number.
This code works for me to start a call between two Skype users:
Intent sky = new Intent("android.intent.action.VIEW");
sky.setData(Uri.parse("skype:" + user_name));
startActivity(sky);
To find this (and others), use apktool to open up the Skype APK. Look at the AndroidManifest.xml and you'll see all the intent filters they know about. If you want to trigger one of those intent filters, you need to make an intent that will match one. Here's the intent filter that the code above is matching:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="skype" />
</intent-filter>
You get the category "android.intent.category.DEFAULT" for free from new Intent(), so all that remains is to set the action and the URI.
The intent filter for tel: URIs looks like this:
<intent-filter android:icon="#drawable/skype_blue" android:priority="0">
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
So you set to the action and give the Intent a tel: URI and "the right thing happens". What happens is that Android finds the correct provider for the tel: URI. It might get the user's input to choose between the Phone App and Skype. The priority for Skype to handle tel: URIs zero, which is lowest. So if the Phone App is installed, it will probably get the Intent.
In case you want to trigger a video call you will have to add "?call&video=true" to your Skype URI.
Intent skypeVideo = new Intent("android.intent.action.VIEW");
skypeVideo.setData(Uri.parse("skype:" + "<username>" + "?call&video=true"));
startActivity(skypeVideo);
More information about Skype URIs are documented at:
http://developer.skype.com/skype-uris-program/skype-uri-ref
EDIT :
Direct Skype call without any intent chooser :
If you want direct skype call without any intent chooser, add these lines in your manifest file...
<intent-filter
android:icon="#drawable/skype"
android:priority="0" >
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
<intent-filter>
<intent-filter
android:icon="#drawable/skype"
android:priority="0" >
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="skype" />
</intent-filter>
</intent-filter>
Use this code for Skype version 2:
Intent skype_intent = new Intent("android.intent.action.VIEW");
skype_intent.setClassName("com.skype.raider", "com.skype.raider.Main");
skype_intent.setData(Uri.parse("skype:skypeusername"));
startActivity(skype_intent);
With this code you will get the intent of the Skype activity not the caller activity. So you have to find the intent for the activity which has the intent filter for action CALL. But more clearly Skype uses the action android.intent.action.CALL_PRIVILEGED, so find by this filter.
Just for information that caller activity is cmp=com.skype.raider.contactsync.ContactSkypeOutCallStartActivity.
Skype 2.X has significantly different manifest then Skype 1.X. There is no ContactSkypeOutCallStartActivity there. New manifest contains code:
<activity android:name="com.skype.raider.Main" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation" android:windowSoftInputMode="adjustResize">
...
<intent-filter android:icon="#drawable/skype_blue" android:priority="0">
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
...
</activity>
So you should write:
Intent skype_intent = new Intent("android.intent.action.CALL_PRIVILEGED");
skype_intent.setClassName("com.skype.raider", "com.skype.raider.Main");
skype_intent.setData(Uri.parse("tel:65465446"));
context.startActivity(skype_intent);
Please note, that this method doesn't allow you to start call/chat using Skype. It works with Skype Out only.
I found that the code above did not work...
Intent i = packageManager.getLaunchIntentForPackage("com.skype.raider");
// i.setAction("android.intent.cation.CALL_PRIVILEGED");
// i.setClassName("com.skype.raider", "com.skype.raider.contactsync.ContactSkypeOutCallStartActivity");
// i.setData(Uri.parse("tel:5551234"));
startActivity(i);
The commented out lines either stopped it functioning, or did nothing!
The code as presented will call Skype and arrive at a page where you can choose Skype contacts
More information will be most welcome
John

Categories

Resources