When calling startActivity with a configured chooser intent, the Android chooser is not displaying any list of applications which can handle the intent. I suspect my handling activity is not configured correctly, but not combination of intent-filters has cause it to display.
Disclaimer: This is for an online course.
static private final String URL = "http://www.google.com";
Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
Intent chooserIntent = Intent.createChooser(baseIntent, CHOOSER_TEXT);
startActivity(chooserIntent);
The handling activity:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent-filter>
A chooser never displays. Android launches chrome instead.
This happens both on emulator, and on my touchpad.
Edit your intent-filter as below:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Related
I have a custom ROM and have no default browser except WebView Browser Tester. I have develop my own kind of web browser app(webviewclient activity) and install this in a phone. Now I want that whatever URLs when user click in a phone, my browser application will intercept and load this URL. Here is what I am using in intent_filter
<intent_filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent_filter>
But it is not working and still WebView browser Tester app launch and loading links. Can someone tell me how I can set my app as a default browser App OR use any special intent which can help to launch this activity while clicking on any URL?
Try adding both intent filters
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="*" />
</intent-filter>
For this you have to identify the launching Activity of Browser application, something like this:
Intent intent = new Intent();
intent.setComponent(new ComponentName("/*Pass your browser package*/","com.google.android.browser.BrowserActivity /*And pass Browser Activity*/"));
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
Uri uri = Uri.parse(url);
intent.setData(uri);
try
{
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
Answer already available on this link
Is it possible to add our custom buttons to the share intent chooser.
example
I have searched around the web and found nothing.
You can add your Activity to this list. You should use special intent filter with mime types for this:
<activity android:name=".ui.MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
See here for getting more details:
https://developer.android.com/training/sharing/receive.html
You have to add intent filter in your activity to do your task.
<intent-filter
android:label="Share with my app">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
Add mime type also, means what you are gonna receive in intent filter:
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
But you have to receive data at your activity when other app sent data to your app
This tutorial will help
You can't, except you make your custom view that contains the applications for share and your custom buttons. Although you can, that is an anti-pattern in Android. See Roman Nurik's post on Google+ here, item number 4.
4) Custom non-Android sharing (not using ACTION_SEND)
Here is the example code of how you can do that
private void showCustomView() {
PackageManager pm = activity.getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(getShareImageIntent("YOUR_IMAGE_URI"), 0);
// code for showing your custom view
// ...
// do whatever you want with your custom buttons
// end code for showing your custom view
// BELOW IS HOW YOU COULD LAUNCH THE SPECIFIC APPLICATION WHEN ONE OF THE APPLICATION ITEMS CLICKED
// from ResolveInfo you can get ActivityInfo
ActivityInfo activityInfo = resolveInfo.activityInfo;
// then you can create ComponentName
ComponentName componentName = new ComponentName(activityInfo.applicationInfo.packageName, activityInfo.name);
// launch the application you want to share
Intent intent = getShareImageIntent("YOUR_IMAGE_URI");
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
intent.setComponent(componentName);
context.startActivity(intent);
}
/**
* Example method to get share intent for applications that receive image Uri
*/
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
#SuppressWarnings("deprecation")
private Intent getShareImageIntent(Uri imageUri) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
else
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
return shareIntent;
}
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>
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>
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