I would like to receive intents with the action VIEW
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
And I want to start other apps with intents with the same action VIEW
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/pdf");
context.startActivity(intent);
But I dont't want to start my own activity. I want that the user sees the standard list of activities that can receive the intent.
How can I acomplish this?
you can create a chooser for your intent
Intent chooser = Intent.createChooser(intent, "randome title");
or make your code like this
context.startActivity(Intent.createChooser(intent, "randome title"));
Related
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 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.
I am trying to make an intent that starts skype conversation with a certain person. Having looked through it all over the stackoverflow, I still cannot make it work properly. Here's my code:
String skypeUri = "skype:name?chat";
Intent intent = new Intent();
intent.setData(Uri.parse(skypeUri));
intent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
My intent filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:scheme="skype" />
</intent-filter>
It brings me to skype but only to the main page of it, no conversation is opened.
Any help would be appreciated.
just use below code
Intent skypeIntent = new Intent("android.intent.action.VIEW");
skypeIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
skypeIntent.setData(Uri.parse("skype:" + skypeId + "?chat"));
Assuming that is your exact code, the problem is that you are not passing the username of the person you want to call. You just have 'name' where their username should be. You need something like:
String skypeUri = "skype:"+username+"?chat";
I'm trying to create a chooser intent to display activities that are capable of viewing URL's. The first activity should be the Web Browser and the second activity should be a custom created activity I created call "MyBrowser".
When I run the code, no activities match my Intent. Here's how I'm calling the Implicit Intent:
Intent baseIntent = new Intent(Intent.ACTION_SEND, Uri.parse(URL));
Intent chooserIntent = Intent.createChooser(baseIntent, CHOOSER_TEXT);
if (baseIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooserIntent);
}
Here is my intent-filter for my custom Browser Activity:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
I believe it should be Intent.ACTION_VIEW not Intent.ACTION_SEND to browse web pages.
http://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW
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>