2
The application in the case is the Telegram and it works with a simple system of reference to users, channels, groups.
I would like to click on hyperlink (clickable textView) which has the user link @Fulano, which opens Telegram and already directs it to the user in question.
If Telegram was not installed, the corresponding link on Google Play https://play.google.com/store/apps/details?id=org.telegram.messenger&hl=pt was opened, so the user could install it.
I’ve seen this kind of thing happen in other apps, even in Youtube comments and in my smatphone’s own browser. The option to "open with".
-------------------------------------------------------------------------------------------------------
Edit:
I tried so, with the code suggested by the extension, this time there were no errors of execution, but with the testing device that has Telegram, did not open the same, but the camera.
Activity:
package genesysgeneration.hl;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView tvLink03;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvLink03=(TextView)findViewById(R.id.tvLink03);
PackageLinkMovementMethod.makerHyperlink(tvLink03);
tvLink03.setMovementMethod(new PackageLinkMovementMethod("org.telegram.messenger"));
}
}
Inherited class (Packagelinkmovementmethod):
package genesysgeneration.hl;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.view.MotionEvent;
import android.widget.TextView;
public class PackageLinkMovementMethod extends LinkMovementMethod{
private String packageName;
public PackageLinkMovementMethod(String packageName){
}
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event){
if (event.getAction()==MotionEvent.ACTION_UP){
Context context = widget.getContext();
Intent laucnkIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (laucnkIntent==null){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id="+ packageName));
context.startActivity(intent);
}else {
context.startActivity(laucnkIntent);
}
return true;
}
return super.onTouchEvent(widget, buffer, event);
}
public static void makerHyperlink(TextView textView){
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(textView.getText());
ssb.setSpan(new URLSpan("#"), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ssb, TextView.BufferType.SPANNABLE);
}
}
need to put android:linksClickable in textview?
– Boneco Sinforoso
You have to implement an onClickListener for Textview.
– ramaral
can do this using the
setMovementMethod(LinkMovementMethod.getInstance())
?– Boneco Sinforoso
added a Intent I named launchIntent with Telegram’s Internet, but clicking on the textView gives error and the app stops. I made some mistake, I should have posted the code earlier
– Boneco Sinforoso
the Launch Intent code hasn’t worked, I’ll try it with the inherited class you said
– Boneco Sinforoso
All examples have been tested and worked. When not "funnel" you should report the error that occurs.
– ramaral
in the inherited class only thing it accused was in public Static void makerHyperlink => "Inner classes cannot have Static declarations"
– Boneco Sinforoso
Write the class in a separate java file.
– ramaral
I went to test on my device (in it I have Telegram installed) and opened the camera!?!?!!
– Boneco Sinforoso
How can you open the camera if you’re like this:
.setMovementMethod(new PackageLinkMovementMethod("org.telegram.messenger"));
?– ramaral
nn do the least ideiai. if you want put the code.
– Boneco Sinforoso