I have created an Intent filter to open my application when clicking on an specified link such as "http://www.myapp.com/1234". When I click on the link I am asked to open the app, and OK, everything works well. Then, I quit from the app by clicking repeatedly in the back button until all activities are closed. But:
After launching the app again from the launcher, it receives the same Intent data than
before when I clicked the link. How do avoid it?
When I open my app from a link, ie. from WhatsApp, as I can see in the app manager, WhatsApp is the application which is opened! why?
Here is my current manifest code:
<activity
android:name="com.x.y.SplashActivity"
android:label="#string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<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" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="#string/app_host"
android:pathPrefix="/events/"
android:scheme="http" />
</intent-filter>
</activity>
and in my onCreate():
// Retrieve the Intent
Intent intentUri = getIntent();
// Check URI
Uri uri = intentUri.getData();
if (uri != null) {
// Try to extract the data
// For now, data could be a public event id, so parse it
List<String> pathSegments = uri.getPathSegments();
// Check validity
if (pathSegments.size() > 2) {
// Finally, get the public event id
String publicEventId = pathSegments.get(2);
// Set poll as responded
user.setPollEventId(publicEventId);
}
// Remove the intent to prevent further calls
setIntent(null);
}
// Open the main activity normally
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
Related
I know that many similarly phrased questions have been downvoted. However, I have viewed many threads here and several pages on the Android Developer website (including https://developer.android.com/guide/components/intents-filters.html and https://android-developers.googleblog.com/2009/11/integrating-application-with-intents.html ) and have been unable to work out how to apply the guidance to my situation.
I wish to transfer location data (latitude and longitude) from an app that I am writing to a mapping app that I have written.
The receiving app's package name is com.prepbgg.mymap and it's main activity is .MyMap. The Manifest includes:
<activity android:name=".MyMap"
android:label="#string/app_name"
android:configChanges ="orientation" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.prepbgg.mymap.action.GEO"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="geo" android:host="mymap.prepbgg.com"/>
</intent-filter>
</activity>
The main activity (MyMap.java) includes:
Intent intent = getIntent();
Uri myMapData = intent.getData();
try {
Toaster.Toast(myMapData.toString(),"Long");
Log.i("nba",myMapData.toString());
} catch(Exception e) {
Toaster.Toast("No data received","Long");
Log.i("nba","No data received");
}
The sending app includes this code:
val btnMyMap = findViewById<ImageButton>(R.id.btnMyMap)
btnMyMap.setOnClickListener() {
var mmUriString = "geo:51.3,-0.31" // Lat and Long hard-coded for test purposes
var mmIntentUri = Uri.parse(mmUriString)
val mmIntent = Intent("com.prepbgg.mymap.action.GEO",mmIntentUri)
mmIntent.setPackage("com.prepbgg.mymap")
startActivity(mmIntent)
}
When I click the relevant button in the sending app it fails with the exception:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.prepbgg.mymap.action.GEO dat=geo:51.3,-0.31 pkg=com.prepbgg.mymap }
Replace:
<data android:scheme="geo" android:host="mymap.prepbgg.com"/>
with:
<data android:scheme="geo" />
A geo Uri does not have a host, and you are not using a host in your Uri. But, your <intent-filter> is mandating a host of mymap.prepbgg.com, so your filter does not match the Intent.
https://example.com/public/change_phone?email_recovery_code=F08fjfU39Ea6RSlDzM8ZZJFVwyjAE
<activity android:name=".view.activity.sign_in_new_number.SignInNewNumberActivity">
<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"
android:pathPrefix="/public/change_phone"/>
</intent-filter>
</activity>
I used the manifest setting's like above but it does not work for Gmail app, the URL does not redirect me on my app just open's the link in Gmail app
if splash screen is the first screen in your app..then use this on onCreate() of your splash activity :
First get the url you are getting through deep linking
Intent intent = getIntent();
Uri data = intent.getData();
if (!isTaskRoot()) {//this will resume your app from last loaded screen if you pressed home button earlier
Log.e("splashfin", "hello");
if (data != null) {
//open that activity through your url or do what ever you want
}else{}
}else{
if(data!=null){
//open that activity through your url or do what ever you want
}
}
in order for myapp://wallet to point to WalletActivity I wrote the below code, and it worked:
<activity
android:name=".ui.WalletActivity"
android:label="#string/title_activity_wallet"
android:screenOrientation="portrait"
android:theme="#style/MaterialThemeNoActionBar"
android:launchMode="singleTop"
android:exported="true">
<intent-filter android:label="#string/title_activity_link_wallet" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="myapp"
android:host="wallet" />
</intent-filter>
</activity>
I do a similar thing for UserProfileActivity but it crashes (obviously) inside the function onCreate in the line: String id = intent.getExtras().getString("id"); because I am not sending any value for id to that activity's intent.
So, is there a way for me to pass the id to the intent of the called activity in this case, which I would have done in normal cases using intent.putExtra("id", id); in the calling activity (where intent is of the called activity)
String id = intent.getExtras().getString("id") for the deeplink is wrong.
You can retrieve the Uri associated with the Intent using
Uri uri = getIntent().getData();
you can then using one of the getter available to retrieve your id, if you provide one. E.g. myapp://wallet/test?id=100
String id = data.getQueryParameter("id");
should give you 100
I would like to start MyBrowser, an application that show web pages like the built-in Browser app, from another application, IntentsLab.
I followed Launch custom android application from android browser to setup the intent, and also the official Intent and Intent-filters guide which does says "You need to include CATEGORY_DEFAULT to receive implicit intents".
So my intent-filter is so written:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.categroy.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
The code of the parent activity in IntentsLab to start the new activity is:
Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
String title = "Use Browser";
Intent chooserIntent = Intent.createChooser(baseIntent, title);
if(chooserIntent != null) startActivity(chooserIntent);
The MyBrowser application does not show up on the chooser dialog. However, when I created an Activity inside the IntentsLab and added to it a same intent-filter, this activity shows up in the chooser dialog. Is there anything wrong with the code? Or is there any difference between implicit intent towards Activities in a same Application with those in a different one?
Provided my AndroidManifest.xml for the MyBrowserActivity. It works perfectly for me. Even I am doing the coursera Android programming class :)
<activity android:name=".MyBrowserActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- TODO - Add necessary intent filter information so that this
Activity will accept Intents with the
action "android.intent.action.VIEW" and with an "http"
schemed URL -->
</activity>
Hello friends there's a option in whatsapp through which we can change the background wallpaper of whatsapp chat. I am making a project in which i am giving so many wallpapers and i want to set the wallpaper from my wallpaper list
I used this code but the code is not working
Intent shareIntent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
Uri uri = Uri.parse("android.resource://com.mypackagename/"+R.drawable.image);
shareI
ntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share via"));Intent = new
There are two thing you have to define for allow other application to call your application or request..
Define <intent-filter> in Mainfest.xml
Check for Intent at onCreate method..
Intent to host activity with Activity RESULT
If you want to share your image/text to other application on other call there are two way..
Share image your with host application on call
For this you have to use android.intent.action.SEND filter
Answer to host application for image request
For this you have to use android.intent.action.PICK filter
Manifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/image1"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- share your image with host application -->
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<!-- answer to host application for image request -->
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.OPENABLE"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:mimeType="image/*"/>
</intent-filter>
</activity>
</application>
OnCreate in MainActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get intent from host activity
Intent intent = getIntent();
if(!intent.getAction().equals("android.intent.action.MAIN")){
// check about request
if (intent.getAction().equals("android.intent.action.PICK")) {
// return to activity with result OK and image selected image
Intent result = new Intent("com.example.RESULT_ACTION", Uri.parse("content://result_uri"));
setResult(Activity.RESULT_OK, result);
finish();
}
}
}