Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Create & Run Shortcuts

This is really two questions.

1. I would like to launch a menu for you to create a shortcut much like how the code below launchers a menu which you can create a shortcut in the normal way

Intent pickIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); 
startActivityForResult(pickIntent, 5);

Only thing is when I use the code above and I check the data, it doesn't seem to contain data. I'm not sure if I needed the following permissions but I have put it in my manifest anyway:

<uses-permission> android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

I want to save the data used to run a shortcut in a file so I can run the shortcut from my app .

2. How would I run a shortcut code, is it basically like running a intent with extra flags, etc

I have seen a app that can do what I have just said and I have managed to look in one of the files it saved on my SD Card:

The following is an example of what I found:

Intent;action=com.sonyericsson.android.camera.action.FRONT_STILL_IMAGE_CAMERA;
component=com.sonyericsson.android.camera/.CameraActivity;
S.com.sonyericsson.camera.intent.extra.CAPTURING_MODE=front_normal;
end{[SName}]Front camera

I positive the above runs a shortcut that opens the camera app with it ready to take a photo from the front camera, but not sure how to run it.

Any help is much appreciated.

like image 288
Reg Avatar asked Feb 18 '23 15:02

Reg


1 Answers

After searching a lot I found what I was looking for:

  1. http://www.jp-z.jp/changelog/2011-07-12-1.html - Will show you how to launch shortcuts to get there Intents

  2. Once you have the intent you can do the following:

Covert to string:

String uri = intent.toURI().ToString()

Save this where ever you wish, file, sqlite, etc

To get it back and run the intent then do

try {
startActivity(Intent.getIntent(uri));
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Found how to do here: Any workaround to save an Intent in settings?

So what the following looked like

Intent;action=com.sonyericsson.android.camera.action.FRONT_STILL_IMAGE_CAMERA;
component=com.sonyericsson.android.camera/.CameraActivity;
S.com.sonyericsson.camera.intent.extra.CAPTURING_MODE=front_normal;
end{[SName}]Front camera

should of looked like this when being run:

try {startActivity(Intent.getIntent("#Intent;action=com.sonyericsson.android.camera.action.FRONT_STILL_IMAGE_CAMERA;component=com.sonyericsson.android.camera/.CameraActivity;S.com.sonyericsson.camera.intent.extra.CAPTURING_MODE=front_normal;end"));
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
like image 173
Reg Avatar answered Feb 27 '23 13:02

Reg