Enable deep linking for android for various structured urls - android

I've already enabled deep linking & it opens app from url. However it opens only the main url i.e. m.example.com & not m.example.com\products\iphone-5s\.
I'm using WebView to load my mobile website into an Android app.
Here's a code of xml file:
<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="m.example.com"
android:pathPrefix="/"
android:scheme="http" />
</intent-filer>
Java file:
private String url='m.example.com';
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
mainWebView.loadUrl(url);
}
Can anybody help to resolve this?

Get the URL link with this code, right after Uri data = intent.getData();
String link = intent.getDataString();
Then, set simple if/else
if (link == null) {
mWebView.loadUrl("yourMainURL");
} else {
mWebView.loadUrl(link);
}

Related

flutter how to open txt file with open with dialog to specific page?

I'm new on flutter and never used intent filter. so far I have everything working in my app. but I'm stuck in importing the file to app by open with dialog. I need the user when it click on the file it will go to the page and display the information in the file. I'm using ImportFile plugin and it work fine but it make it harder for the users to put the file they receive.
my app is list it in the open with dialog but when i click it, it just open the app I want it to open the app and view the text in the view text page not the homepage
AndroidManifest.xml
<
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.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:pathPattern="*.*\\.txt" />
</intent-filter>
MainActivity.java
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
new MethodChannel(getFlutterView(), "app.channel.shared.data").setMethodCallHandler(new MethodChannel.MethodCallHandler() {
#Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.contentEquals("getSharedText")) {
result.success(sharedText);
sharedText = null;
}
}
});
}
void handleSendText(Intent intent) {
sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}
Thank you in advance
FlutterView has a setInitialRoute method you can use to specify a non-default route on launch.

How to open a url located at a third party app or a browser (like a whatsapp message) directly into my webview app?

I have a blog and I made a app version of it using just Webview. The problem is: I would like to share my posts through other apps, like sending a whatsapp message or an email to someone with a link to a specific post located on my blog (like www.blogspot.myblog.com/2017/postexample), and then have the option to open this with my app, like Facebook does, or even Youtube does.
I made this:
<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="mywebsite.com"
android:pathPrefix="/"
android:scheme="http" />
<data
android:host="www.mywebsite.com"
android:pathPrefix="/"
android:scheme="http" />
</intent-filter>
it does launch my app, but (of course) it opens to the app's default page, not the www.blogspot.myblog.com/2017/postexample, so what should I do to open directly into the sent url? Thanks guys, a help would be greatly appreciated.
EDIT
Here's my code now:
<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:scheme="http"
android:host="www.blog.com"
android:pathPrefix="/" />
</intent-filter>
</activity>
And the Activity
public class BlogActivity extends AppCompatActivity {
private static final String TAG = "BlogActivity";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
//Get the link from that Uri
if (data != null) {
Log.d(TAG, "Data" + data.toString());
WebView WebView2 = (WebView)findViewById(R.id.web1);
WebView2.setWebViewClient(new WebViewClient());
WebView2.loadData(TAG, "text/html; charset=utf-8", "UTF-8");
WebSettings webSettings = WebView2.getSettings();
webSettings.setJavaScriptEnabled(true);
}
}
}
Have a look at: https://developer.android.com/training/app-indexing/deep-linking.html
From the above link:
Once the system starts your activity through an intent filter, you can use data provided by the Intent to determine what you need to render. Call the getData() and getAction() methods to retrieve the data and action associated with the incoming Intent. You can call these methods at any time during the lifecycle of the activity, but you should generally do so during early callbacks such as onCreate() or onStart().
Here’s a snippet that shows how to retrieve data from an Intent:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
//Get the link from that Uri
if(data != null) {
Log.d(TAG, "Data" + data.toString());
}
}

How to push an ingested deep link back to a web browser on Android

I'm currently having trouble where I am ingesting a deep link in my application, but after further review of the URL, I want to push the URL back to the web browser to display since my application does not provide the capability of using it. When I try to open the URL in a web browser, nothing happens since I have it defined to be a deep link. I tried sanitizing in the manifest with android:pathPrefix="/#!/foo", but the # character is not supported and causes the whole thing to not work.
AndroidManifest.xml
<activity
android:name=".activities.IntentForwardingActivity"
android:launchMode="singleTask"
>
<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="www.example.com"
android:scheme="https"
/>
</intent-filter>
</activity>
IntentForwardingActivity.java
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
String action = intent.getAction();
if (action != null && action.equals(Intent.ACTION_VIEW)) {
Uri data = intent.getData();
handleDeepLinking(data.toString());
}
}
private void handleDeepLinking(String url) {
Intent intent;
if (url.contains("/#!/foo")) {
intent = HomeActivity.newIntentForFoo(this, url);
} else {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}
startActivity(intent);
finish();
}

How to fix null Uri data = intent.getData() in Android

I want Open this link in my application, not open in browser. for this job i want use DeepLink.
But when start application, show me null for URI.
My link : Link
I write this code in manifest :
<activity
android:name=".Activities.PostShow_page"
android:screenOrientation="portrait"
android:theme="#style/AppThemeWithStatus">
<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="www.kolony.ir"
android:scheme="http" />
<data
android:host="kolony.ir"
android:scheme="http" />
</intent-filter>
</activity>
Activity codes:
// Deep Linking
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
Log.e("Deep", "Link : " + data);
but when running application, in LogCat show this : Link : null
How can i fix null for this URI and show uri in logCat ?
Simply instead of using getIntent() use intent parameter of onNewIntent(Intent intent) event handler
Try this:
Intent intent = getIntent();
Uri data = (Uri) intent.getExtras().get(Intent.ACTION_VIEW);
Try this
intent.getStringExtra(Intent.EXTRA_TEXT)
You will get the exact location. It helps me hope so it helps you too.
String action = intent.getAction();
String data = intent.getDataString();
if (Intent.ACTION_VIEW.equals(action) && data != null) {
String recipeId = data.substring(data.lastIndexOf("/") + 1);
}

how to get URL from ACTION_SEND?

My app is registering an intent to receive URLs so when the user shares a url, my app will be in the list of apps.
<intent-filter
android:label="my app">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
-
in my MainActivity's onCreate() method:
String action = intent.getAction();
if (action.equalsIgnoreCase(Intent.ACTION_SEND)) {
Uri data = intent.getData();
String s = data.toString();
output.setText(s); //output: a TextView that holds the URL
}
-
The problem I got is: data is null which is strange. Since this code works perfectly with ACTION_VIEW. However, it didn't work with ACTION_SEND.
How could I modify it to work?
You can try
String action = intent.getAction();
if (action.equalsIgnoreCase(Intent.ACTION_SEND) && intent.hasExtra(Intent.EXTRA_TEXT)) {
String s = intent.getStringExtra(Intent.EXTRA_TEXT);
output.setText(s); //output: a TextView that holds the URL
}

Categories

Resources