I am trying to open location settings from Chrome (on Android) on a button click using Android Intents. I am following the Barcode Scanner example and tried encoding the url similar way.
For location I have tried this:-
const uri = "intent://com.google.android.gms.location.settings.GOOGLE_LOCATION_SETTINGS#Intent;action=com.google.android.gms.location.settings.GOOGLE_LOCATION_SETTINGS;end"
I also tried opening settings using this:-
const uri = "intent://ACTION_SETTINGS#Intent;action=android.provider.Settings.ACTION_SETTINGS;end"
or this
const uri = "intent://android.provider.Settings.ACTION_SETTINGS#Intent;action=android.provider.Settings.ACTION_SETTINGS;end"
But nothing seems to work. Any help is appreciated.
I am attaching it to a button using href tag.
Seems you can't open Location Settings directly from Android Intents with Chrome because Settings Activities didn't support BROWSABLE category (for details take a look at this question of Dickeylth and answer of Rafal Malek). But You can 100% do this via custom android application and Deep Links to custom Activity with <category android:name="android.intent.category.BROWSABLE"/> support, like in that tutorial.
In that case your application SettingsActivity code should be like:
public class SettingsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
}
}
and AndroidManifest.xml part for SettingsActivity
<activity android:name=".SettingsActivity">
<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="open.location.settings"
android:scheme="http"/>
</intent-filter>
</activity>
and, finally, "deep" link for SettingsActivity in HTML file:
Open Location Settings
Seems, if you don't want to install app on user side, you can also do this in Instant Apps. Details for links to Instant App you can find here.
Related
The deeplinking works fine from WhatsApp, Slack and even Facebook Messenger but doesn't work from the Facebook App itself.
In the branch.io Link Settings I did enable:
✓ Always try to open app
✓ Enable App Links + SHA256 Cert Fingerprints
Changed to custom Link Domain: sharing.kptncook.com
successfully authenticated the "Facebook Install Ads"
Facebook developer settings:
Packagename, class name and hashes are correct(Facebook login also works fine)
✓ SSO is activated
✓ Deep-Link is activated
Android App Versions:
Facebook Messenger: 126.0.0.9.84
Facebook: 133.0.0.19.83
Example link: sharing.kptncook.com/pIbQ/FKktug85TE
Activity part of Manifest:
<activity android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<data android:scheme="kptncook" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="sharing.kptncook.com" />
<data android:scheme="http" android:host="sharing.kptncook.com" />
</intent-filter>
</activity>
<receiver android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
Activity:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onStart() {
super.onStart();
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchReferralInitListener(){
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
}
}, this.getIntent().getData(), this);
}
#Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}
}
Additional info: In the emulator some links won't open and some does. If I send a link that doesn't work from the emulator to a real device it works on the real device.
What am I doing wrong?
Update:
New shared links work now on the Real device in both Facebook Messenger and Main App. But if I open the exact same link in the messenger on an emulator it redirects to "r31v.test-app.link..." and doesn't show anything except a toast "Can't load page". It's so frustrating. Any ideas how to debug it?
Alex from Branch.io here:
Facebook deep linking is one of the hardest things to debug — they intentionally don't want users to leave their app, wherever possible.
A few notes for debugging:
The domain r31v.test-app.link is your original link domain. You customized this to sharing.kptncook.com, but there are times when Branch needs to use both to handle certain edge cases. You need to add the following lines to your Manifest:
<data android:scheme="https" android:host="r31v.test-app.link" />
<data android:scheme="https" android:host="r31v-alternate.test-app.link" />
Other than the above, your in-app configuration implementation looks fine.
It's possible something is funky with your Dashboard configuration. Branch has separate Test and Live environments, and you're currently using the Test one. It's important to make sure you haven't split your implementation between values from both sides.
Deep linking behavior frequently doesn't work correctly in the emulators. It's always best to test with real devices, because results from emulators are usually not reliable.
Facebook sometimes caches the App Links tags, which means you may get unpredictable results when opening a URL that has just been shared, or when re-sharing a URL that has been posted before with different data.
Feel free to reach out to our Integrations team any time with questions!
I'm developing a small messaging app on my own and I was wondering if there is a possibility to allow the user to send messages using the Google Assistant. (Like WhatsApp and Google Allo)
Which API could I use to archive this?
Before going through the code please go through this links answer along with comments .
So as mentioned there are two types of actions that can be registered
1) Custom Action
2) System Action
Here app has been registered with TAKE A NOTE action(a system generated action).
This is registered in the Manifest to let the system know that it accepts the intents which are related to taking a note.(Hope i have not over explained it)
=== Code ===
Manifest.xml
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.google.android.gms.actions.CREATE_NOTE" />
<category android:name="android.intent.category.VOICE"/>
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
MainActivity.java
public class VoiceAction extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_voice_action);
Intent t = getIntent();
String s = t.getStringExtra(Intent.EXTRA_TEXT);
System.out.println("====" + s);
} }
This how i tested it
Ok Google -> take a note -> google asks me choose an app -> choose the app to be tested -> give a note or a text to it -> see your log (text you said is printed there).
I will edit the answer to meet your need exactly in some time . Hope this helps
I saw something in the WhatsApp manifest :
Apparently they are using this action :
com.google.android.voicesearch.SEND_MESSAGE_TO_CONTACTS
No trace of that in any docs...
Coincidence, I think not...
https://github.com/GigaDroid/Decompiled-Whatsapp/blob/master/AndroidManifest.xml
I need a way to include a link in an email which either opens a mobile app or redirects the user to a website depending on whether the mobile app is installed or not. I need a solution for both Android and IOS, it is there a set practice on how to achieve this?
Thanks!
You need a combo of answers here I think.
For iOS, You can replace http:// with itms:// or itms-apps:// to avoid redirects.
How to link to apps on the app store
For Android, I think you'll want to look at the <intent-filter> element of your Mainfest file. Specifically, take a look at the documentation for the <data> sub-element.
Make a link in the Android browser start up my app?
On Android, you need to handle this via Intent Filter:
<activity
android:name="com.permutassep.IntentEvaluator"
android:label="#string/app_name">
<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="your/url"
android:scheme="http" />
<data
android:host="your/url"
android:scheme="https" />
</intent-filter>
</activity>
And the class you need to handle the intent data should look like this:
public class IntentEvaluator extends BaseActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = null;
if(getIntent() != null && getIntent().getData() != null){
// Do whatever you want with the Intent data.
}
}
}
Taken from an app I developed: https://raw.githubusercontent.com/lalongooo/permutas-sep/master/app/src/main/java/com/permutassep/IntentEvaluator.java
Currently I am having two web pages, home and about. The about is deep link in that ,so when i click on the link , android gives me the option to use a browser to or my own app to open that link. I would like to explicitly open that link in my app.I don't want list of the apps to handle it. Is this possible? Below is my code:
AndroidManifest.xml
<activity
android:name=".AboutPage"
android:label="#string/about_page">
<intent-filter android:label="#string/filter_name">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http"
android:host="appindexing.robscv.info"
android:pathPrefix="#string/aboutHTML"/>
</intent-filter>
</activity>
AboutPage.java
public class AboutPage extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.about_page);
// Enable the "Up" button for more navigation options
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
onNewIntent(getIntent());
}
protected void onNewIntent(Intent intent){
String action = intent.getAction();
String data = intent.getDataString();
Log.d(action, data);
}
}
In short. No
But
Its coming.
This is a feature scheduled for release in Android M.
All you have to do is add this to the Manifest
<intent-filter android:label="#string/filter_name" android:autoVerify="true">
//...categories etc
</intent-filter>
More info here
Just FYI what this will actually do is deep link directly to the app and if multiple apps on a users phone autoVerify then it will throw up the prompt.
I am using this piece of code to launch my app from a link.
<activity
android:name="com.example.myApp.myClass"
android:label="#string/app_name" >
<intent-filter>
<data
android:host="customHostName"
android:scheme="customScheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This is href link, i want to get the key in the end.
customScheme://customHost/49FYTJTF00
It is working fine on all previous versions of android, but is not working on Lollipop.
When I click the link it only shows the list of browsers to launch.
What should I do?
Edit:
After testing and testing, I found that if your scheme contains an uppercase character the browser won't be able to launch it. Your scheme should only contain lowercase characters!
Also note that bug 459156 of the chromium project still doesn't allow you to launch url's directly, you should reference users to a webpage containing this JavaScript code:
<!DOCTYPE html>
<html>
<body>
<script language="javascript">
window.location = 'customscheme://customHost/49FYTJTF00';
</script>
</body>
</html>
Users landing on this page will automatically be prompted with either an Activity chooser dialog or directly send to your Activity.
To try it, open the Android browser go to the url below and copy paste the above snippet in the editor:
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro
Gif showing browser + JavaScript opening the Activity
Original post
I tried out your custom URI and it works on Android 5.0
But you should be aware of the following two bugs/issues:
Bug 459156 of the Chromium project This basicly means launching custom schemes from the Android browser does not work unless the URL is applied using JavaScript. For a workaround see this StackOverflow post: OAuth and custom scheme result in a "ERR_UNKNOWN_URL_SCHEME" in Chrome
Bug 80971: URI with custom scheme are not clickable in SMS Text (Linkify?)
My approach
I created two separate Activities, one as intent receiver and the other as intent launcher. The launching activity has an EditText where the full URI can be entered and a button to launch the entered URI.
Main.java onClick (Launching activity)
#Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(input.getText().toString()));
try {
startActivity(intent);
} catch(ActivityNotFoundException e){
Toast.makeText(this, "Auww!! No Activity can open this URI!", Toast.LENGTH_SHORT).show();
}
}
manifest.xml (only the activities)
Note the <data android:pathPattern=".*"/> part. this part is important so anything after the host will be accepted as valid.
<activity
android:name=".Main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".UriActivity"
android:label="#string/app_name">
<!--
This intent-filter will open any URI with the following forms:
customscheme://customHost/49FYTJTF00
customscheme://customHost
https://www.google.com/something/something
http://www.google.com/
http://google.com/something
-->
<intent-filter>
<data android:scheme="https"/>
<data android:scheme="http"/>
<data android:host="google.com"/>
<data android:host="www.google.com"/>
<data android:scheme="customscheme"/>
<data android:host="customHost"/>
<data android:pathPattern=".*"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
UriActivity.java (Receiving activity)
public class UriActivity extends ActionBarActivity {
private TextView tvText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_uri);
tvText = (TextView) findViewById(R.id.text);
setTextFromIntent();
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setTextFromIntent();
}
private void setTextFromIntent(){
StringBuilder text = new StringBuilder();
Uri data = getIntent().getData();
if(data != null){
text.append("Path:\n");
text.append(data.getPath());
text.append("\n\nScheme:\n");
text.append(data.getScheme());
text.append("\n\nHost:\n");
text.append(data.getHost());
text.append("\n\nPath segments:\n");
text.append(Arrays.toString(data.getPathSegments().toArray()));
} else {
text.append("Uri is null");
}
tvText.setText(text);
}
}
Screenshot:
Test project download:
I made a download for the project if you wan't to try it out yourself.
Please use pathprefix.
android:pathPrefix="/"
It might solve your problem.
Please follow android developer guide URL.
Instead of using a link to customScheme://customHost/49FYTJTF00, have you tried using a link like
<a href="intent://customHostName/49FYTJTF00#Intent;scheme=customScheme;end">
Chrome should be able to open that in your app just fine. At the same time, this might not work on all browsers.
Keep in mind if you want run the app from Google Chrome you should do that in another way .
You wrote:
<data
android:host="customHostName"
android:scheme="customScheme" />
So, use customScheme://customHostName/49FYTJTF00
instead of customScheme://customHost/49FYTJTF00