How to fix null Uri data = intent.getData() in Android - 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);
}

Related

How to show my app in every possible sharing intents and receive them?

I want my app to be shown in every kind of sharing like plain text, images, videos or any files.
I also want to handle them accordingly. How can I do that? I'm completely new with sharing related stuff and I can't find any proper documentation for it.
Add this intent filter for receiving all types of sharing intent.
<activity
android:name=".YourActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
And in your receiving activity
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
} else {
Uri fileUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
}
}
You will get shared text and file Uri using the above code

Android deep linking is not working

Android deep linking is not working
===================================
Android link:-notification://id=notificationid
1:-In manifest
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="id"
android:scheme="notification" />
</intent-filter>
2:-and coding side
#Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
String string=intent.getAction();
Uri data = intent.getData();
Log.d("hello","cgbdsuyfdkv");
}
but its not working please any body can help me !!!!!
you can simply modify your url
Android link:-notification://id=notificationid instead of
Android link:-notification://page?id=notificationid //page is host name
I tried a lot and find out this is working for me.
manifest code
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="page"
android:scheme="notification" />
</intent-filter>
2.java code #get your notification id here
Intent intent = getIntent();
String string = intent.getAction();
Uri data = intent.getData();
if (data != null) {
String path = data.getPath();
String path1 = data.getPath();
providerUrl = intent.getData().toString();
UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
sanitizer.setAllowUnregisteredParamaters(true);
sanitizer.parseUrl(providerUrl);
String id = sanitizer.getValue("id");
if (id != null)
Log.d("notification id", id);
}
Add onNewIntent() method to your Activity and then use intent object which is variable in OnNewintent() method , which has updated method.
onNewIntent() is meant as entry point for singleTop or singleTask activities which already run somewhere else in the stack and therefore can't call onCreate(). From activities lifecycle point of view it's therefore needed to call onPause() before onNewIntent(). I suggest you to rewrite your activity to not use these listeners inside of onNewIntent(). For example most of the time my onNewIntent() methods simply looks like this:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
//use this intent object to get notificationid for second time
}
1st step:
<intent-filter>
<data android:scheme="your_uri_scheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
2nd step:
Uri data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
String uri = this.getIntent().getDataString();
Log.i("MyApp", "Deep link clicked " + uri);
}
I think you Intent Filter is incomplete
<!-- To open app using link -->
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:scheme="http"
android:host="yourdomain.com"
android:pathPrefix="/someurlparam">
</data>
</intent-filter>

Cannot Get ACTION_VIEW Data From Intent

In my manifest file I have the following:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="audio/*" />
</intent-filter>
At the top of my main activity in onCreate, I have:
mIntent = new Intent(Intent.ACTION_VIEW);
In my onResume in main activity, I have:
if(mIntent != null){
if(mIntent.getExtras() != null){
Log.d("INTENTDATA", "" +mIntent.getExtras());
}
}
Even though mIntent isn't null, mIntent.getExtras() returns null. When I tried mIntent.getData(), it also returned null.
Is there something wrong with my syntax?
Use getIntent at onCreate instead of creating a new one.
SOLUTION:
I needed to call getIntent();
mIntent = getIntent();
if (Intent.ACTION_VIEW.equals(mIntent.getAction())) {
Log.d("INTENTDATA", "ACTION_VIEW");
if(mIntent.getData() != null){
Log.d("INTENTDATA", "" +mIntent.getData());
}
}

Enable deep linking for android for various structured urls

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);
}

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