How can i make my app available in the "Open From" dialog of the file picker? and how do i handle that request in the activity code?
Here is a screenshot of the dialog where i want my app to appear as an option(This dialog is from while uploading a file to google drive):
You can specify mimeType in intent-filter in your mainfest file.
your app will be added to share list.
For example you need to add your app for text share then use
mimeType="text/plain"
<activity android:name="ShareActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
Handle share :
Write this code in onCreate method of your activity (Activity which is declared in mainfest with intent filter(above))
if (Intent.ACTION_SEND.equals(intent.getAction()))
{
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
//here you will get data which is shared.
}
I've faced same problem recently and solved it by handling this intent in my app:
<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="video/*" />
</intent-filter>
Related
I am developing an android app, in which user must need to login first to use it's features. So as usual user must need to login using provided user credential.
But I don't want user always enter username and password again and again, so that I am just sharing a URL with user and if user click on shared link from anywhere in phone (via mail, or WhatsApp, or Facebook, etc.) phone must prompt to choose my app and app should automatically extract the URL and directly redirect the app to my Home Screen by hitting the login api if username and password are correct.
The shared url will be look like this - http://www.myurl.com/sso?username=Scb56745&password=!l0Aeu0yQazxssx
For now I have managed to prompt the dialog using this code in my AndroidManifest file -
<activity
android:name="com.my.par.activities.UserActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter android:autoVerify="true" tools:targetApi="m">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.myurl.com"
android:path="/sso"
android:scheme="http" />
<data
android:host="www.yoururl.com"
android:path="/sso1"
android:scheme="https" />
</intent-filter>
</activity>
I am getting this clicked URL link in my UserAcitivity's on getIntent() method, like this -
Uri uri = getIntent().getData();
String path = uri.getPath();
So my real question is how to extract the username and password separately and so that I can call my login api by sending this username and password from this url (for ex. http://www.myurl.com/sso?username=Scb56745&password=!l0Aeu0yQazxssx). - Done
And how can I put a dynamic URL or host name, path and scheme in AndroidMenifest file? - Done
How can we force our app to always directly open the app,(don't need to show the chooser dialog) because no use of it even user click on browser nothing gonna happen.
Happy coding :-)
Karzel is also right but it's written in Kotlin, I believe you are expecting the solution for Java I'll answer the same in Java
Uri uri = getIntent().getData();
String strUsername = "", strPassword = "";
if (uri != null) {
strUsername = uri.getQueryParameter("username");
strPassword = uri.getQueryParameter("password");
}
else {
// Your app will pop up even if http://www.myurl.com/sso is clicked, so better to handle null uri
}
To answer your next part about dynamic URL, you can have multiple intent-filters for that purpose
<activity
android:name="com.my.par.activities.UserActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter android:autoVerify="true" tools:targetApi="m">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.myurl.com"
android:path="/sso"
android:scheme="http" />
</intent-filter>
<intent-filter android:autoVerify="true" tools:targetApi="m">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.myurl.com"
android:path="/sso"
android:scheme="https" />
</intent-filter>
<intent-filter android:autoVerify="true" tools:targetApi="m">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.myurl.com"
android:path="/debug"
android:scheme="http" />
</intent-filter>
</activity>
and so on.
To open your app directly by clicking the link and not show a chooser dialog you'll have to use a custom URI, for example:
syn3sthete://myurl.com/sso?username=Scb56745&password=!l0Aeu0yQazxssx
You can change syn3sthete to any custom value you want.
Don't forget to add an intent-filter for your custom URI.
<intent-filter android:autoVerify="true" tools:targetApi="m">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="myurl.com"
android:path="/sso"
android:scheme="syn3sthete" />
</intent-filter>
Try using code like this :
fun getUsernameFromUrl(url: String): String? {
return Uri.parse(url).getQueryParameter("username")
}
fun getPasswordFromUrl(url: String): String? {
return Uri.parse(url).getQueryParameter("password")
}
And call it
val username = getUsernameFromUrl(path)
etc.
UPDATE:
The only "dynamic" way of adding URL I know is using something like this :
https://developer.android.com/studio/build/manifest-build-variables
you can change this URL depending on your Build Variant.
As is said here :
https://stackoverflow.com/a/43339476/8713068
you cannot update Android Manifest directly from code
If there's a WhatsApp chat which has location shared, when clicked it shows a chooser intent with some set of applications. I want to write an intent filter so that my application will also be listed there.
You can do it by supporting implicit intent to your Activity.
Define intent-filter to Activity to which you want to open after clicking to your Application from options.
<activity android:name=".BrowserActivitiy"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
<data android:scheme="geo"/>
</intent-filter>
</activity>
To know more about Intents and Intent filters go to official website.
https://developer.android.com/guide/components/intents-filters
Add this to your Manifest file (Particular activity):
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="geo" />
</intent-filter>
How can I do that my application appears in the “share” list of another application? For example, I want to choose a pdf file and send it to my application.
I can’t find the solution, any idea?
Thanks
You can add an intent filter in your AndroidManifest.xml
for example for a pdf you can indicate the mimeType application/pdf.
<activity name="package.name.MyActivity">
<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:mimeType="application/pdf" />
</intent-filter>
</activity>
Look at the documentation at http://developer.android.com/guide/components/intents-filters.html#Receiving
My Android app can share links via Twitter or Facebook.
If someone clicks on a link that was shared and they already have the app installed, how can I make the app launch directly?
Updated -
Simple Issue Fixed from here -
Make a link in the Android browser start up my app?
You need to add <Intent-filter> under <activity> tag in manifest.xml file 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>
When another application tries to share any of these things by constructing an intent and passing it to startActivity(), your application will be listed as an option in the intent chooser.
If the user selects your application, the corresponding activity (.ui.MyActivity in the example above) will be started. It is then up to you to handle the content appropriately within your code and UI.
And go to this for better understanding: http://developer.android.com/training/sharing/receive.html
Facebbok/twitter
facebook
After facebbok login OnComplete() is called. So, fire your intent in this method.
public void onComplete(Bundle values)
{
# fire desired intent
}
twitter
put this code into your manifest file with activity name and on which activity
want to redirect put the below line so link is created and you will redirect
<activity
android:name="com.example.mainactivity"
android:screenOrientation="portrait" >
<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:host="home"
android:scheme="oauth" />
</intent-filter>
</activity>
*********************************************************************
<h6>put this into your mainactivty</h6>
static final String TWITTER_CALLBACK_URL = "oauth://home";
static final String TWITTER_CALLBACK_URL = "oauth://home";
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)