Open my app from a link - android

In my app the server send this link: appname://veryfy?email=test#mail.com&token=asdf-asdf-asdf-xcfghfgh but is it possible to get the values like email= test#mail.com and the token = sdfdkgdkgjgfd.
So far I've only added this intent filter inside my manifest but the app is not called:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" android:scheme="appname://"/>
</intent-filter>
Note this should open my app when the link is clicked in the browser

You can get the email and token by getting the Activity's intent like this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" android:scheme="https"
android:host="api.myapp.com"
android:pathPrefix="/api/v2/verify"/>
</intent-filter>
Intent intent = getIntent();
Uri data = intent.getData();
String email = data.getQueryParameter("email");
String token = data.getQueryParameter("token");

The scheme in your filter should just be appname, not appname://
android:scheme="appname"

try this
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" android:scheme="appname"/>
</intent-filter>
</activity>
To get your url parameter write this in your activity
Uri data = getIntent().getData();
String scheme = data.getScheme();
String host = data.getHost();
List<String> params = data.getPathSegments();
String first = params.get(0);
String second = params.get(1);

Try this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" android:scheme="appname"/>
</intent-filter>
and the link on the web:
<a href="appname://veryfy?email=test#mail.com&token=asdf-asdf-asdf-xcfghfgh">
Getting data in your Activity:
// check if this intent is started via custom scheme link
Intent intent = getIntent();
String action = intent.getAction();
if (action != null && action.equals(Intent.ACTION_VIEW) {
Uri uri = intent.getData();
String scheme = uri.getScheme();
if (scheme.equals("appname") {
String email = uri.getQueryParameter("email");
String token = uri.getQueryParameter("token");
}
}

Related

Android deep linking path pattern

i have this url https://myportal.net/#!/search/main/34 i need to implemnt deep linking when user click on the url its open the app.
Note: 34 number is changing in the url
i do the following but its not working
<activity
android:name="ui.Activities.SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#style/SplashScreen">
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="${hostName}"
android:pathPattern="/.*/.*/.*/.*"
android:scheme="https" />
</intent-filter>
In Your Splash Activity
private void handleDeepLink(Intent intent) {
FirebaseDynamicLinks.getInstance()
.getDynamicLink(intent)
.addOnSuccessListener(pendingDynamicLinkData -> {
// Get deep link from result (may be null if no link is found)
Uri deepLink;
String finalLink = "";
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
String string = String.valueOf(deepLink);
String decodeUrl = Utils.decodeUrl(string);
String[] parts = decodeUrl.split("main/");
String part1= parts[0];
String part2= parts[1];
finalLink = part2.replaceAll(" ", "+");
Log.w("dynamiclink", finalLink);
if (!Validator.isEmptyString(finalLink)) {
getDataManager().setAuthSecret(finalLink);
}
}
getNavigator().openRegistrationActivity(finalLink);
})
.addOnFailureListener(e -> {
getNavigator().openRegistrationActivity("");
});`
}
In your Manifiest file
<intent-filter android:autoVerify="true">
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data
android:host="nms-rx.in"
android:pathPrefix="main/"
android:scheme="https" />
</intent-filter>

Open URL in my WebView after loading it from YouTube's share menu

I have an Android WebView project and I have added it in the share menu to get the URL from YouTube.
and I am using this code in manifest
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
I need the code to open the URL in the WebView after a click on my app icon from the share menu in YouTube.
For e.g.:
val intent = intent
intent.action = Intent.ACTION_SEND
val uri = intent.data
if (uri == null){
webframe.loadUrl("file:///android_asset/index.html")
}else{
webframe.loadUrl(uri.toString())
}
You can get params in your activity by following code snippet:
Intent intent = getIntent();
Uri uri = intent.getData();
//uri is what you need.
try this:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:host="www.youtube.com" android:mimeType="text/*" />
</intent-filter>
thanks to everyone I have found a solution to the problem
firs you mut to add this code to manifest:
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="
</intent-filter>
Next add this code to MainActivity:
when (intent?.action) {
Intent.ACTION_SEND -> {
if ("text/plain" == intent.type) {
webframe.loadUrl(intent.getStringExtra(Intent.EXTRA_TEXT))
}
}
else -> {
webframe.loadUrl("file:///android_asset/index.html")
}
}

dribbble authentication url not working in android

This is api doc. http://developer.dribbble.com/v1/oauth/
This is client Ids:
Client ID
3acdea730eaae4ea51dadf296be4e8edf7cd4b6ab030ce69c1de0d1a335b679d
Client Secret
4a9773911cd2304fa23047e703e35fffbd443f32a9c73207aa60b45852e17b64
Client Access Token
57fe6dc09292e4dadce94a3dc9fd895117792a48f7194bbc5b8bd229e6ef1388
Java code
String LOGIN_CALLBACK = "placeholder.com";
String LOGIN_URL = "https://dribbble.com/oauth/authorize?client_id="
+ "3acdea730eaae4ea51dadf296be4e8edf7cd4b6ab030ce69c1de0d1a335b679d"
+ "&redirect_uri=http%3A%2F%2F" + LOGIN_CALLBACK
+ "&scope=public+write+comment+upload";
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(LOGIN_URL)));
in manifest
<activity
android:name=".DribbbleLogin"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<data
android:host="dribbble-auth-callback"
android:scheme="plain" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
what should be put in callback url and what should be passed in redirect url, so that the flow redirect to my app?
Your callbackUrl should be like plain://example.com and there is one more thing that needs to be done in the android manifest
android:host="example.com"
android:scheme="plain"
Just put in callbackurl "plain://example.com"
in manifest
<activity
android:name=".DribbbleLogin"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<data
android:host="example.com"
android:scheme="plain" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
In DribbbleLogin Activity
String loginCallback = "electedface.com";
String code;
Intent intent = getIntent();
if (intent != null
&& intent.getData() != null
&& !TextUtils.isEmpty(intent.getData().getAuthority())
&& loginCallback.equals(intent.getData().getAuthority())) {
code = intent.getData().getQueryParameter("code");
}
Call login url "https://dribbble.com//oauth/token" with dribbble_client_id, dribbble_client_secret and this code. you will get access_token, token_type, scope in json.
Thanks All

Receiving data from other application comes null in android

I want to make my application like Instagram i can share pictures
directly from my application , like if i select any image from
gallery and when click on share my application shows on the list of chooser
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<activity
android:name=".ui.activities.SplashActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:screenOrientation="sensorPortrait"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Code for receiving data from intent is
private void initActivityState() {
if (getIntent() != null){
runShareActivityIntent();
}
}
public void runShareActivityIntent(){
Intent passIntent=getIntent();
String action = passIntent.getAction();
String type = passIntent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
Uri imageUri = (Uri) passIntent.getParcelableExtra(Intent.EXTRA_STREAM);
Intent intentcall = new Intent(this, MainActivity.class);
intentcall.putExtra(KEY_TYPE,type);
intentcall.putExtra(KEY_VALUE,imageUri.toString());
startActivity(intentcall);
finish();
}
}
Now in my case when my app is in background i am able to get
String type = passIntent.getType();
and i am able to get image uri but when my app is not running( kill app ) and i
select my application from chooser i get type as null
This worked for me:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
try adding permissions to your manifest file:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
You have to change in Manifeast.xml
<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="audio/*" />
</intent-filter>
In your Main activity you have to receive the intent on oncreate() method.
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (type.startsWith("image/")) {
handleSendImage(intent); // Handle single image being sent
}
else if (type.startsWith("audio/")) {
handleSendAudio(intent); // Handle single audio being sent
}
}
Now whenever you call the application using send. You can see the icon of your app. When you get the intent you can change according to your need.
I hope this may help you.

Why doesn't my app receive Intents?

i'm trying my app receive data shared by other apps. I.e. when somebody send a youtube link via Whatsapp, Youtube app can receive it and open to show.
I set this at the manifest:
<activity
android:name="com.example.app.MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="#string/app_name"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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>
</activity>
And this code is into MainActivity onCreate method:
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equalsIgnoreCase(action) && type != null) {
if ("text/plain".equals(type)) {
String codigoIn = intent.getStringExtra(Intent.EXTRA_TEXT);
if (codigoIn!=null) Toast.makeText(context, codigoIn, Toast.LENGTH_LONG).show();
}
}
I try to test sending myself links via Hangouts. When I click on link, the chooser only show Chrome and Internet navigators.
Please, what's wrong? Thank you very much
UPDATE: SOLVED
I already solved. I was very lost. I should not use the category ACTION_SEND but ACTION_VIEW. Now, Manifest is:
<intent-filter android:label="my app">
<data android:scheme="http" />
<data android:host="myHost.com" />
<data android:host="www.myHost.com" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
And I put at Activity -> onResume method:
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (action.equalsIgnoreCase(Intent.ACTION_VIEW)){
String dato = intent.getData().toString();
Intent nuevoIntent = new Intent(context, Resultado.class);
nuevoIntent.putExtra("codigo", dato);
startActivity(nuevoIntent);
}
I hope it's useful to someone. It took two days to fix
You can try the code from this answer :
String action = intent.getAction();
if (action.equalsIgnoreCase(Intent.ACTION_SEND) && intent.hasExtra(Intent.EXTRA_TEXT)) {
String s = intent.getStringExtra(Intent.EXTRA_TEXT);
Toast.makeText(context, s, Toast.LENGTH_LONG).show();
}

Categories

Resources