Adding custom button to the share intent chooser - android

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

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.

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 unable to display chooser

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>

I need a code for pick image from my app while the press the attachment button in any app

I'm a new developer, I need a code for when a user clicks image attachment button from any app , my app will be shown and they can pick app image. Moreover, I want to send images from my app to all other apps.
When an attachment button is pressed in an app, an Intent with action PICK or GET_CONTENT is launched. So in your manifest.xml you should listen to these actions.
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.OPENABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
And return the Image Uri on your activity:
private void returnImage() {
Intent intent = getIntent();
intent.setData(mImageUri);
setResult(RESULT_OK, intent);
finish();
}
If you want to send the image to other apps, you can do it with this:
private void shareImage() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setDataAndType(mImageUri,"image/*");
startActivity(intent);
}

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