In my app manifest i wrote this code to open some links with my app adding the intent-filter:
<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="https" android:host="example.com" />
</intent-filter>
I tried to send via email to myself a link; for example: http://www.example.com/1234. click over the link i open the app.. That's great. Now, is it possible take the 1234 part of the link and put it into a textview? Something like:
mTextView.setText(textFromLink);
thanks
Did you already get access to the URL inside your app? If not, you can get it e.g. in your onCreate method with
Uri link = getIntent().getData();
which returns a Uri object:
http://developer.android.com/reference/android/net/Uri.html
This object has several methods to get the specific parts of the URL. In your case it will probably be
String content = link.getLastPathSegment():
http://developer.android.com/reference/android/net/Uri.html#getLastPathSegment()
This returns a string that you can set in your TextView:
mTextView.setText(content);
Related
I need to get some parameters that are coming from an external campaign, where when a user clicks on an external banner on browser my app needs to open,
currently it is happening as expected, my app is opening perfectly... but I need to get all the parameters that came with it.
My XML manifest ->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="external"
android:host="deeplink"
/>
</intent-filter>
URL I'm accessing when I click on the banner -> external://deeplink/?utm_source=abc&utm_medium=abc&utm_campaign=abc
code that I'm using in the deeplink receiver class ->
Intent appLinkIntent = getIntent();
Uri appLinkData = appLinkIntent.getData();
Log.d("taguison", "URI --->" + appLinkData);
Log.d("taguison", "utm_source--->" + appLinkData.getQueryParameter("utm_source"));
Log.d("taguison", "utm_media --->" + appLinkData.getQueryParameter("utm_media"));
Log.d("taguison", "utm_campaign --->" + appLinkData.getQueryParameter("utm_campaign"));
return ->logcat return image
what do i need to do to be able to access the remaining parameters that gave null
utm_media and utm_campaign ?
I want to associate files of particular extension (say, any file with the extension .xyz) with my app. This means, when user taps SaveFile1.xyz in File explorer (or other places, like gmail, drive etc.), my app should launch and the Uri of the file will be passed in an intent to my activity.
While this is the expected behavior, I don't know how to associate custom files. I have read and understood how intent matching works and the possible values in data tag, but it didn't work. I have checked some stackoverflow answers (Ex, this and this), but they use file scheme and pathPatterns.
We cannot use the pathPattern because we get a content uri (Uri with scheme=content), which is the abstracted path and will not have any extensions.
The mime type setting can be used only for the predefined values (like image/png can associate all png images with the app).
I could set the mime type as "*/*", but I don't want my app to accept every file (and then reject it in onCreate or something).
Has anyone solved this problem? Any help will be greatly appreciated.
I have the following in the activity tag of the manifest file.
<activity
android:name=".MainActivity"
android:exported="true">
<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.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<!--<data android:mimeType="application/pdf"/>
<data android:mimeType="image/png"/>-->
<!--<data android:scheme="content" android:mimeType="*/*"/>-->
</intent-filter>
</activity>
Edit1:
I set the mime type as "*/*" and added the following line in Activity.onCreate to see the type in the intent (and set it in the manifest file) ...
Intent dataIntent = getIntent();
Log.i(TAG, "dataIntent.getType() = " + dataIntent.getType());
.... but got the following as output.
dataIntent.getType() =
Its not even null.
I am developing an application for searching for places. In the application there is a button where user can share a specific place with other user. I was thinking about sharing a link that when other user, "the invited one", clicks on it, my application opens on the shared place page. Just like Clash Royale game, if you know it. The idea is that. How can I do so? Does anyone have idea how to implement this?
Thanks in advance.
To achieve this you need to Create Deep Links to App Content
Code would be something like this:
1) Add intent filter in your activity
<activity android: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="example.com"
android:scheme="schemeName" />
</intent-filter>
</activity>
2) Get data in you activity
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
3) Create sharable URL
eg - http://example.com?data=<your data to share>
4) Now you need to write some script for your page (http://example.com)
that will receive your header data and redirect to open app.
for this get some idea from here
* This is not a complete code but hope will help you.
I am new in android development, I want to build a music player but the problem in front of me is how do i make my app open from gallery.
For example,
if we want to open any music file then we select it, the the android mobile ask which player do we want to use.
so how can I add my app in that option.
please help.
If you want your app to be in the list for opening an audio file, you need to tell the system your app can open those files. You can do that by adding something like the following to your activity tag in your AndroidManifest.xml:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:mimeType="audio/*"/>
<data android:mimeType="application/ogg"/>
<data android:mimeType="application/x-ogg"/>
<data android:mimeType="application/itunes"/>
</intent-filter>
Intent filters are part of the core principles in Android development. You should try to get some knowledge on these basic topics before getting started.
It helps you
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
Actually you can open activity not app at self just simply add action intent filter in mainfest like this
<activity class=".foo" android:label="#string/title_notes_list">
<intent-filter>
<action android:name="com.me.love" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
other app code :
Intent intent = new Intent("com.me.love");
startActivity(intent);
however if you want to tell android system that your activity can handle some actions like share or send data you just have to add "send" action to your activity in mainfest like so :
<activity class=".boo" android:label="#string/title_notes_list">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
so now when ever user click share button android system will check all activitys that have action string "android.intent.action.SEND" then give the user list of activitys that have send action and if you did added same action as boo activity dose to your activity then it will be one of chooses in the list.
As in WhatsApp, if you click on a name to call, down the list you will find the WhatsApp logo in front of the number if you want to txt using WhatsApp.
Can we add the easyPhoneCard in that list, so the user can directly call using that option without clicking on the prompt to call.
You have to add in your manifest some rules.
In that way, Android will be able to list your application as compatible with a specific action (here is call action)
I think it will be something like
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<data android:scheme="tel" />
</intent-filter>
(add this in your activity node that will handle operations)