Reputation: 3652
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 }
Upvotes: 1
Views: 299
Reputation: 1006914
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
.
Upvotes: 3