1
.method private a()Landroid/content/Intent;
.locals 5

.prologue
.line 297
:try_start_0
iget-object v0, p0, Lcom/myapp/c/f;->b:Lcom/myapp/context/ApplicationContext;

iget-object v0, v0, Lcom/myapp/context/ApplicationContext;->o:Lcom/myapp/context/b;

iget-object v0, v0, Lcom/myapp/context/b;->b:Ljava/util/List;

iget v1, p0, Lcom/myapp/c/f;->c:I

.line 298
invoke-interface {v0, v1}, Ljava/util/List;->get(I)Ljava/lang/Object;

move-result-object v0

check-cast v0, Lcom/myapp/data/weblink;

.line 299
new-instance v1, Landroid/content/Intent;

const-string v2, "android.intent.action.SEND"

invoke-direct {v1, v2}, Landroid/content/Intent;-><init>(Ljava/lang/String;)V

.line 300
const-string v2, "text/plain"

invoke-virtual {v1, v2}, Landroid/content/Intent;->setType(Ljava/lang/String;)Landroid/content/Intent;

.line 301
const-string v2, "android.intent.extra.SUBJECT"

.line 302
invoke-virtual {v0}, Lcom/myapp/data/weblink;->getTitle()Ljava/lang/String;

move-result-object v3

.line 301
invoke-virtual {v1, v2, v3}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;

.line 303
const-string v2, "android.intent.extra.TEXT"

new-instance v3, Ljava/lang/StringBuilder;

invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

.line 304
invoke-virtual {v0}, Lcom/myapp/data/weblink;->getTitle()Ljava/lang/String;

move-result-object v4

invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v3

const-string v4, " "

invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v3

invoke-virtual {v0}, Lcom/myapp/data/weblink;->getLink()Ljava/lang/String;

move-result-object v0

invoke-virtual {v0}, Ljava/lang/String;->toString()Ljava/lang/String;

move-result-object v0

invoke-virtual {v3, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v0

invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v0

.line 303
invoke-virtual {v1, v2, v0}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

move-object v0, v1

.line 309
:goto_0
return-object v0

.line 307
:catch_0
move-exception v0

invoke-static {v0}, Lcom/myapp/d/e;->a(Ljava/lang/Exception;)V

.line 309
const/4 v0, 0x0

goto :goto_0
.end method

.method static synthetic a(Lcom/myapp/c/f;)Lcom/myapp/context/ApplicationContext;
.locals 1

.prologue
.line 51
iget-object v0, p0, Lcom/myapp/c/f;->b:Lcom/myapp/context/ApplicationContext;
return-object v0
.end method

This is a smali code which returns a Title and a Link from 'weblink' inside a database file. I want to return a static value (example 'This is the link www.google.com ' ) instead of Title and Link from database file. How can I do that? What code should I change? This is similar to this question here ( How to return a static result in smali function ) and I already tried that solution. But app is force closing. can somebody help?

Community
  • 1
  • 1
user3548321
  • 523
  • 2
  • 8
  • 18
  • 2
    Install https://github.com/ollide/intellij-java2smali and create a java class with a method that returns what you want. Convert it to smali and learn from it – Pedro Oliveira Apr 13 '16 at 06:02
  • solved it by half. I was able to change link to title and add my own text to const-string v4 . Now link is gone from shareable text but title is added twice. I tried to remove both title and link and show only value in the const-string v4 . But when I do it, app is force closing...Any idea? – user3548321 Apr 13 '16 at 11:28
  • 1
    Use a debugger (DDMS) to log the exception. We can't help you without it. – Luca D'Amico Apr 13 '16 at 17:21
  • I tried intellij java2smali but i'm facing problem. When I click "compile to smali", nothing is happening.. There's no smali code.. It shows "cleaning output directors finished, saving... " But no smali file is generated. I don't know what's wrong. Using intellijidea 2016.1.1 – user3548321 Apr 18 '16 at 02:05

1 Answers1

3

Simply override the content of the string object before it's appended to the StringBuilder.

.line 304
invoke-virtual {v0}, Lcom/myapp/data/weblink;->getTitle()Ljava/lang/String;

move-result-object v4

# Add following line to override v4 before it's appended to the StringBuilder
const-string v4, "This is the link"

invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

Similarly, you can do the same for the link

invoke-virtual {v0}, Lcom/myapp/data/weblink;->getLink()Ljava/lang/String;

move-result-object v0

invoke-virtual {v0}, Ljava/lang/String;->toString()Ljava/lang/String;

move-result-object v0

# Add following line to override v0 before it's appended to the StringBuilder
const-string v0, "www.google.com"

invoke-virtual {v3, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

Actually, you can override the whole string at once before it's put to the intent.

invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v0

# Add this line
const-string v0, "The whole text you want, including the title and link"

.line 303
invoke-virtual {v1, v2, v0}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

I hope you are not doing something bad.

Landice Fu
  • 81
  • 4
  • Wowww... I don't know how to thank you for this. I thought i'll give up with my last solution ie, setting two gettitle instead of link. Your answer solved my issue. Now i can set title and a custom text instead of link. btw, I'm not doing anything bad. I just want to add a "shared via(app name) text instead of the link. No bad intention at all. Thanks a lot. – user3548321 Apr 21 '16 at 04:49