I have an app where the user should be able to share some text. Now I want to provide the default sharing options for plain text that Android provides. I do so with the following code:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
sendIntent.setType("text/plain");
Intent chooser = Intent.createChooser(sendIntent, "Share");
startActivity(chooser);
This will look a bit like that:
Source: http://developer.android.com/training/basics/intents/sending.html
But now I also would like to be able to have one more option in the Share-Service-Picker Dialog that triggers a custom action in my own code. Namely I want the user to be able to favourite an entry. So beside sharing via SMS, Email, FB, whatever, I'd like there to be one more item on the top of that list, saying "Add to favourites" (Including an icon if possible).
So my question is if that's possible?!? And if, how :)
Any tips are appreciated!
Intent filters inform the system what intents an application component is willing to accept. Similar to how you constructed an intent with action ACTION_SEND in the Sending Simple Data to Other Apps lesson, you create intent filters in order to be able to receive intents with this action. You define an intent filter in your manifest, using the element. For example, if your application handles receiving text content, a single image of any type, or multiple images of any type, your manifest would look like:
<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>
from Receiving Simple Data from Other Apps:Update Your Manifest
Related
What I want is to share the link of specific page of my application. Suppose I am in a profile page of some user in my app and I want to share that user to some of my friends so I would like to share it via WhatsApp and other applications.
So basically I want to share a link to my app.
This is what I am doing right now
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" + activity.getPackageName());
activity.startActivity(Intent.createChooser(shareIntent, "Share"));
I know this is not what I really want but it's partially done.
if user hasn't installed my app then this code redirect him to google play store page to download this app.
Main problem is when user have already this app this link just opens the app. I want to redirect user to that specific page when he clicks on a link.
How can I do this?
I heard something about intent-filter but not sure how to use them.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
UPDATED
Now I am trying to share my app link like this
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra("PostID", postID);
shareIntent.putExtra("UserID", userID);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" + activity.getPackageName());
activity.startActivity(Intent.createChooser(shareIntent, "Share"));
Inside my manifest I have declared an activity like this
<activity
android:name=".activities.ShareActivity"
android:screenOrientation="sensorPortrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="details"
android:scheme="market" />
<data
android:host="play.google.com"
android:pathPattern="/store/apps/details?id=my_package_name"
android:scheme="http" />
<data
android:host="play.google.com"
android:pathPattern="/store/apps/details?id=my_package_name"
android:scheme="https" />
</intent-filter>
</activity>
But I am still not able to see my app when I click on the link I shared using WhatsApp or any other means.
Please help me
Any help will be really appreciated.
Thanks in advance.
Add the following intent-filters to your activity declaration, in the AndroidManifest of your project :
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
Now, in the onCreate(), onResume() or onNewIntent() method of your activity lifecycle, you can use the getData() of the intent that has fired your activity.
In my android application, I have an intent filter linked to one of my activities in my AndroidManifest.xml like so:
<activity
android:name=".MainActivity"
android:label="#string/name >
<intent-filter>
<action android:name="android.intent.action.SEND />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
By my understanding this should add my app the list of apps in my browser (Chrome) that are under the "Share..." section so that my app can use the URL of the current web page. This list contains Flipboard, Android Beam, Twitter, Keep, Google+, etcetera.
I've found many examples on how to do this, they all use the above code. However, my app doesn't show up on that list for some reason. What could be the reason for this and how can I solve this issue?
Thanks!
You are including the action and category correctly but you also need to include the mimeTypes so that the Intent knows what type of sharing you want to support. Try including these two lines in order to support both text and image sharing:
<data android:mimeType="text/plain" />
<data android:mimeType="image/*" />
Like so:
<intent-filter>
<action android:name="android.intent.action.SEND />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:mimeType="image/*" />
</intent-filter>
If you then want to retrieve the URL from the Intent to utilise in your app then you'll want to add this code to your onCreate() method in MainActivity:
String action = intent.getAction();
if (action.equalsIgnoreCase(Intent.ACTION_SEND) && intent.hasExtra(Intent.EXTRA_TEXT)) {
String URL = intent.getStringExtra(Intent.EXTRA_TEXT);
}
The web and stackoverflow contain several examples how to get a file from another Android app (e.g., to use it as email attachment) using an ACTION_GET_CONTENT intent. But what kind of class do I have to implement to create an application providing content for the ACTION_GET_CONTENT event such as I can choose this app (e.g., for selecting an email attachment).
Is a ContentProvider the right solution? And what do I have to add to my AndroidManifest.xml?
After some hours of web search I found the following solution.
Implement an Activity handling intents. Within, use the following or more specific code:
Uri resultUri = // the thing to return
Intent result = new Intent();
result.setData(resultUri);
setResult(Activity.RESULT_OK, result);
finish();
Add the following to the Manifest:
<activity
android:name="ActivityName"
android:label="Some label" >
<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="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
starting from api level 18 incoming intent can also have EXTRA_ALLOW_MULTIPLE set to true and in this case you can send back in result more than one file. To do so you need to set it as ClipData:
resultIntent.setClipData(clipData)
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
When clicking an email address from a browser or contacts app...
Is there any way for my app to show a mail client in the intent list?
As you can see from the Mail application's source, having your application catch the intent is as simple as adding the intent-filter to your AndroidManifest.xml inside your mail composition activity definition.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
You can see that the <data> tag specifies to handle mailto: links. The BROWSABLE category means it can be launched from the browser.
K-9 Mail is similar, except using the SENDTO action only with the DEFAULT category, and the VIEW action only with the BROWSABLE category.
You need to use an Intent Filter. Check out http://developer.android.com/guide/topics/intents/intents-filters.html for more information. You usually declare these in your manifest file. The intent I believe you're looking for is Intent.ACTION_SEND.