android linkify intent - android

I have a ListView that uses Linkify to create a link to another activity in my app. the url looks something like content://com.myapp/activitiy/view?param=blah
this works fine every time.
however, in another view, I'm trying to call some code like this:
Intent i = new Intent("content://com.myapp/activity/view?param=blah");
i.setAction(Intent.ACTION_VIEW);
startActivity(i);
but for some reason this doesn't seem to work. It doesn't trigger my activity (and in fact it blows up if i dont include the setAction() call. How am I supposed to create the Intent such that it acts the same way that Linkify does...?
Now i realize i can setup the extras and then handle it in the activity, but that just seems like duplicated effort. So instead i'll spend the time it would have taken to do that, and post this question. SO any help much appreciated. :)

ah. just figured it out:
String uri = "content://...";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);

Related

Taking audio uri from intent

I'm stuck, and I can't manage to find a solution to it :/
What I'm doing is an app of sounds effects with sounds preloaded and choosen by the user, so I have default buttons with default sounds and the possibility of adding (as many as you want) buttons with sounds choosen by you.
So here's my part of code of the add-button:
public void add (View v){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("audio/*");
startActivity(Intent.createChooser(intent, "Select music"));
}
The output should be an uri and I need to get that (I'll use it to take the path of the file choosen by the user), but I don't know how.
Oh, I understood :)
For those who are trying to find a solution to that as me:
You don't have to use startActivity() but startActivityForResult() and then use the getData() method on the intent parameter of the onActivityResult() callback.
Here's the guide:
https://developer.android.com/training/basics/intents/result.html

Start Wikipedia via Intent

I tried to start the Wikipedia App via Intent but I always get an InvocationTargetException, because the Activity can't be found. I can detect that Wikipedia is installed, but I can't start it. I know that I can also use the Intent Filter and call the Wikipedia URL, but then the user can decide between app and browser (both works different with the search param, which is not very useful) and I want to decide it for the user.
I tried it with following code:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "searchString");
intent.setType("text/plain");
intent.setPackage("org.wikipedia");
Can somebody tell me, what I am doing wrong there or is it just not possible to start the wikipedia app? :-/
Finally I come to a solution after I was looking in the wikipedia code on github (https://github.com/wikimedia/apps-android-wikipedia). The app listens only for View Intents, which means that following code works:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(searchUri);
intent.setPackage("org.wikipedia");
The problem here is, that only URI's for existing articles were handled and no search operation can be used. After watching a little bit more in the code, I found a PageActivity which also listens for ACTION_SEARCH Intents. This would work, when in the AndroidManifest.xml this Intent Filter would be also available.

Make Intent.ACTION_VIEW accept multiple URIs

I want to launch some apps which accept geo coordinates (http://developer.android.com/training/sharing/send.html). The problem is that they want different URIs.
Example (pseudo code):
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.addSomeUri("http://maps.google.com/maps/?daddr="+myAddress);
intent.addSomeUri("http://someotherservice.com/?coordinates="+myLat+":"+myLng+"&address=myAddress");
EDIT:
Of course the goal is for both apps to appear in the same activity chooser.
How can I achieve it?
How can I achieve it?
Call startActivity() (or startService() or whatever) once per Uri.
Do you really want to launch every app?
If not, you have simpler way
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:30.0, 120.0"));
startActivity(intent);

No Activity found to handle Intent, Android

I am developing a project on Android that deals with images either from the camera or from the sd-card. I had this working fine until earlier I was fiddling with the code and broke it. It was too late to undo and I can't seem to find the solution.
After the image is selected and processed, a list should be returned but now I get an Activity not Found exception, here is a picture.
If anybody has any idea whats going on I'd appreciate it!
EDIT
Just got it, was a silly mistake, I had
Intent intent = new Intent(Results)
Instead of
Intent intent = new Intent(this, Results.class)
It was a silly mistake, I had
Intent intent = new Intent(Results)
Instead of
Intent intent = new Intent(this, Results.class)
Try adding "" to the calling Activity.

how to do something like multiple views ..stack in iOS on Android?

I was wondering about the following situation:
in iOS:
I have viewA which goes to viewB on button press. from view B based on some computations, I can either go to viewC or go back to viewA.
I have done this nicely on iOS.
I am wondering how to do the same in Android. Can anyone kindly help me out ? Thanks.
You mean the Task stack on android. Take a look to this, it will be what you're looking for.
For example (I've encapsulate this in a Navigation Manager instance, that handles all my navigation logic, but given your context, something like this could be useful:
Intent intent = new Intent(this.activityC, ActivityA.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //THIS IS THE TASK MANAGEMENT
if (!params.isEmpty())
intent.putExtras(params);
this.activity.startActivity(intent);
The Task Stack in Android is correct. If you need to specifically know how to move from one activity to another then just use intents like this to change to a new activity:
Intent startActivity = new Intent(view.getContext(), TargetActivity.class);
startActivityForResult(startActivity, 0);

Categories

Resources