Kotlin - Google Maps Direction by Static Url - android-studio

So, I have a Static Google Map, like the following:
Static Google Map Link
And I want it to, when I click on the image view, that contains that static map, to start Google Maps with that direction.
I've used Intent... but it always breaks & don't work.
Code:
binding.imgview.setOnClickListener {
val uri = Uri.parse(https://maps.googleapis.com/maps/api/staticmap?center=Madrid&zoom=14&size=600x300&maptype=roadmap&key=YOUR_API_KEY&markers=Madrid)
val googleMapsPackage = "com.google.android.apps.maps"
val intent = Intent(Intent.ACTION_VIEW, uri)
intent.setPackage(googleMapsPackage)
context?.startActivity(intent)
}
Any quest, feel free to ask :)
Thanks.

Try this
val uri =Uri.parse("https://maps.googleapis.com/maps/api/staticmap?center=Madrid&zoom=14&size=600x300&maptype=roadmap&key=YOUR_API_KEY&markers=Madrid")
val intent = Intent(Intent.ACTION_VIEW, uri)
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity")
startActivity(intent)

Related

"Null" value while retrieving data from intent in kotlin

I am passing some value through intent from FirstActivity to MainActivity. But, when I try to retrieve that value from second activity (i.e. MainActivity) I am not able to do so.
FirstActivity
var i = Intent()
launcher?.launch(Intent(this, MainActivity::class.java))
i.putExtra("key", cold)
startActivity(i)
MainActivity
val initialCold = intent.getStringExtra("key")
Your problem is in this line launcher?.launch(Intent(this, MainActivity::class.java)) this is another intent, not i and you launched it without the extra key string, so you can't get it in your MainActivity, the right way if you want to launch activity for result
val intent = Intent(this, MainActivity::class.java)
intent.putExtra("key", cold)
launcher?.launch(intent)
Or like this if you want to start the MainActivity without result
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)

How can I share Intent contents using a link?

I want to share something (like a text, image, etc) using a link with Android Intents.
For example:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, someTextView.getText());
sendIntent.setType("text/plain");
Intent shareIntent = Intent.createChooser(sendIntent, null);
startActivity(shareIntent);
This code allows me to share a text. But I want that this content will be shared with a link, like this:
https://my-aplication/someText
And then, when the user enters in the page, gets the current shared text.
How can I do that? I investigated about using Android App Links, but I didn't understand very well.
Also I tried to search in other places but I didn't find anything.
Thanks for helping!
After investigating about this topic, I found Google Firebase Dynamic Links. I watched some videos about this topic. This code generates a key which can be shared by a link. First, you must create a dynamic link in you firebase console. Then, you add these methods. Here's the first method to get Dynamic link data:
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()).addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// getting deep link
Uri deeplink = null;
if(pendingDynamicLinkData != null){
deeplink = pendingDynamicLinkData.getLink();
}
// getting deeplink content
if(deeplink != null)
{
String sharedList = deeplink.getQueryParameter("sharedList");
userReference[0] = database.getReference(sharedList);
}
else userReference[0] = database.getReference().push();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(MainActivity.this, "Ooops, we couldn't get the link data :(", Toast.LENGTH_SHORT).show();
}
});
And here's the second one, to generate a link:
// generating dynamic link
private void GenerateLink(String listId) {
System.out.println("Generating link: " + listId);
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://www.your_dynamic_link.com/?your_variable_to_share=" + value))
.setDomainUriPrefix("https://your_short_url.page.link")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder("com.example.your_package")
.setMinimumVersion(1)
.build())
.buildDynamicLink();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "I share you my list: " + dynamicLink.getUri());
sendIntent.setType("text/plain");
startActivity(sendIntent);
}

How to refer to a file in Android studio

I'm using retrofit to connect my app to the server, and for that I need to refer the link of the server. However, I don't want to put said link hardcoded, I would be better if it referred to a file. How should I do this?
Here is the where I want to replace the string with the file:
object RetrofitClient {
private val client = OkHttpClient.Builder().build()
private val retrofit = Retrofit.Builder()
.baseUrl("SERVER_LINK__Replace with file")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
fun<T> buildService(service: Class<T>): T{
return retrofit.create(service)
}
}

How to save Sparks MatrixFactorizationModel recommendProductsForUsers to Hbase

I am new to spark and I am want to save the output of recommendProductsForUsers to Hbase table. I found an example (https://sparkkb.wordpress.com/2015/05/04/save-javardd-to-hbase-using-saveasnewapihadoopdataset-spark-api-java-coding/) showing to use JavaPairRDD and saveAsNewAPIHadoopDataset to save.
How can I convert JavaRDD<Tuple2<Object, Rating[]>> to JavaPairRDD<ImmutableBytesWritable, Put> so that I can use saveAsNewAPIHadoopDataset?
//Loads the data from hdfs
MatrixFactorizationModel sameModel = MatrixFactorizationModel.load(jsc.sc(), trainedDataPath);
//Get recommendations for all users
JavaRDD<Tuple2<Object, Rating[]>> ratings3 = sameModel.recommendProductsForUsers(noOfProductsToReturn).toJavaRDD();
By using mapToPair. From the same source you provided example(i changed types by hand):
JavaPairRDD<ImmutableBytesWritable, Put> hbasePuts = javaRDD.mapToPair(
new PairFunction<Tuple2<Object, Rating[]>, ImmutableBytesWritable, Put>() {
#Override
public Tuple2<ImmutableBytesWritable, Put> call(Tuple2<Object, Rating[]> row) throws Exception {
Put put = new Put(Bytes.toBytes(row.getString(0)));
put.add(Bytes.toBytes("columFamily"), Bytes.toBytes("columnQualifier1"), Bytes.toBytes(row.getString(1)));
put.add(Bytes.toBytes("columFamily"), Bytes.toBytes("columnQualifier2"), Bytes.toBytes(row.getString(2)));
return new Tuple2<ImmutableBytesWritable, Put>(new ImmutableBytesWritable(), put);
}
});
It goes like this, you cretne new instance of put supplying it with row key in constructor, and then for each column you call add. and then you return the put created.
This is how i solved the above problem, hope this will be helpful to someone.
JavaPairRDD<ImmutableBytesWritable, Put> hbasePuts1 = ratings3
.mapToPair(new PairFunction<Tuple2<Object, Rating[]>, ImmutableBytesWritable, Put>() {
#Override
public Tuple2<ImmutableBytesWritable, Put> call(Tuple2<Object, Rating[]> arg0)
throws Exception {
Rating[] userAndProducts = arg0._2;
System.out.println("***********" + userAndProducts.length + "**************");
List<Item> items = new ArrayList<Item>();
Put put = null
String recommendedProduct = "";
for (Rating r : userAndProducts) {
//Some logic here to convert Ratings into appropriate put command
// recommendedProduct = r.product;
}
put.addColumn(Bytes.toBytes("recommendation"), Bytes.toBytes("product"),Bytes.toBytes(recommendedProduct)); Bytes.toBytes("product"),Bytes.toBytes(response.getItems().toString()));
return new Tuple2<ImmutableBytesWritable, Put>(new ImmutableBytesWritable(), put);
}
});
System.out.println("*********** Number of records in JavaPairRdd: "+ hbasePuts1.count() +"**************");
hbasePuts1.saveAsNewAPIHadoopDataset(newApiJobConfig.getConfiguration());
jsc.stop();
We just open sourced Splice Machine and we have examples integrating MLIB with querying and storage into Splice Machine. I do not know if this will help but thought I would let you know.
http://community.splicemachine.com/use-spark-libraries-splice-machine/
Thanks for the post, very cool.

Lost headers when using UnZipResultSplitter

I'm using the Spring Integration Zip extension and it appears that I'm losing headers I've added upstream in the flow. I'm guessing that they are being lost in UnZipResultSplitter.splitUnzippedMap() as I don't see anything that explicitly copies them over.
I seem to recall that this is not unusual with splitters but I can't determine what strategy one should use in such a case.
Yep!
It looks like a bug.
The splitter contract is like this:
if (item instanceof Message) {
builder = this.getMessageBuilderFactory().fromMessage((Message<?>) item);
}
else {
builder = this.getMessageBuilderFactory().withPayload(item);
builder.copyHeaders(headers);
}
So, if those splitted items are messages already, like in case of our UnZipResultSplitter, we just use message as is without copying headers from upstream.
Please, raise a JIRA ticket (https://jira.spring.io/browse/INTEXT) on the matter.
Meanwhile let's consider some workaround:
public class MyUnZipResultSplitter {
public List<Message<Object>> splitUnzipped(Message<Map<String, Object>> unzippedEntries) {
final List<Message<Object>> messages = new ArrayList<Message<Object>>(unzippedEntries.size());
for (Map.Entry<String, Object> entry : unzippedEntries.getPayload().entrySet()) {
final String path = FilenameUtils.getPath(entry.getKey());
final String filename = FilenameUtils.getName(entry.getKey());
final Message<Object> splitMessage = MessageBuilder.withPayload(entry.getValue())
.setHeader(FileHeaders.FILENAME, filename)
.setHeader(ZipHeaders.ZIP_ENTRY_PATH, path)
.copyHeaders(unzippedEntries/getHeaders())
.build();
messages.add(splitMessage);
}
return messages;
}
}

Resources