Launching installedapplication - android

How do I launch the installed application?
I have installed using below:
File file = new File(dir, "App.apk");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
Second time, I am checking if the package already installed, if yes, I want to launch.
Intent intent = new Intent(com.example.app);

i'm using this method. You should change package and class names.
private static final String GPS_STATUS_PACKAGE_NAME = "com.eclipsim.gpsstatus2";
private static final String GPS_STATUS_CLASS_NAME = "com.eclipsim.gpsstatus2.GPSStatus";
/**
* Run GpsStatus & toolbox application
*
* #param context
* which can start activity
*/
public static void runGpsStatus(Context context) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(GPS_STATUS_PACKAGE_NAME, GPS_STATUS_CLASS_NAME));
List list = context.getPackageManager().queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
if (list.size() > 0) {
// Have application
context.startActivity(intent);
} else {
// None application
}
}

Related

Open URL followed by second URL

I need to open the URL followed by another in order to remove the previous URL for viewing. The action is required in-lieu of closing the browser tab.
The first URL is opening and the second one is no where to be seen. Where I am going wrong?
Uri uri = Uri.parse(URL_STRING);
//modified the URL_STRING for security
URL_STRING = "https://myserver.com/action";
final Intent intent1 = new Intent(Intent.ACTION_VIEW, uri);
intent1.putExtra(Browser.EXTRA_APPLICATION_ID, "toto");
startActivity(intent1);
//SystemClock.sleep(1000);
String POST_URL = "http://www.google.com";
uri = Uri.parse(POST_URL);
final Intent intent2 = new Intent(Intent.ACTION_VIEW, uri);
intent2.putExtra(Browser.EXTRA_APPLICATION_ID, "toto");
Have even tried to put a sleep with varying values. Did not work.
Follow this to load two URls in the external browser.
Declare these variables as global variables.
int count = 0;
Runnable runnable=null;
Handler handler = new Handler();
Then call this method to load the Url in browser.
public void goToBrowser() {
final Uri[] uri = new Uri[1];
runnable = new Runnable() {
public void run() {
switch (count) {
case 0:
String URL_STRING = "https://myserver.com/action";
uri[0] = Uri.parse(URL_STRING);
//modified the URL_STRING for security
final Intent intent1 = new Intent(Intent.ACTION_VIEW, uri[0]);
intent1.putExtra(Browser.EXTRA_APPLICATION_ID, "toto");
startActivity(intent1);
break;
case 1:
String POST_URL = "http://www.google.com";
uri[0] = Uri.parse(POST_URL);
final Intent intent2 = new Intent(Intent.ACTION_VIEW, uri[0]);
intent2.putExtra(Browser.EXTRA_APPLICATION_ID, "toto");
startActivity(intent2);
break;
}
if (count++ <= 1){
handler.postDelayed(this, 1000);
}else {
handler.removeCallbacks(runnable);
}
}
};
handler.post(runnable);
}

Android - no app found to open link within Edittext

If I click on the HYPERLINK, I get a dialog with the message that no app was found to handle this link, but I know that my android device has some applications to handle this file, becuase I open this file already by click the file itself. Here the code snippet:
case DragEvent.ACTION_DROP:
final String DATA = event.getClipData().getItemAt(0).getText().toString();
final String RECORDS_DIR = ((ScribeApplication ) getApplication()).RECORDS_DIRECTORY_ABSOLUTE_PATH;
final Spanned HYPERLINK = Html.fromHtml("" + RECORDS_DIR + DATA + "");
editor.setMovementMethod(LinkMovementMethod.getInstance());
if (editor.length() > 0)
{
editor.append("\n");
editor.append(HYPERLINK);
}
else
editor.append(HYPERLINK);
return true;
DATA is the file name e.g. record1.3pg
RECORDS_DIR is the absolute path to the directory with the recording files.
HYPERLINK is the absolute path of a record file.
editor is an instance of Eidttext
As mentioned above, if I navigate to the records directory and click the record file itself I get an app chooser and can select an app to handle this record file. So what I did wrong that I dont get an app chooser by clicking the hyperlink within the edittext but rather an dialog with the failure that no app was found?
Many thanks in advance!
Here is my solution for the issue described by CommonsWare:
public class ClickableIntentURLSpan extends URLSpan
{
private Context context;
private Intent intent;
public ClickableIntentURLSpan(final Context CONTEXT, final String URL, final Intent INTENT)
{
super(URL);
final boolean INPUT_OK = (CONTEXT != null) && (INTENT != null);
if (INPUT_OK)
{
context = CONTEXT;
intent = INTENT;
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
else
throw new IllegalArgumentException("Illegal refer to null.");
}
#Override
public void onClick(final View VIEW)
{
context.startActivity(intent);
}
}
case DragEvent.ACTION_DROP:
final String DATA = event.getClipData().getItemAt(0).getText().toString();
final String RECORDS_DIR = ((ScribeApplication ) getApplication()).RECORDS_DIRECTORY_ABSOLUTE_PATH;
final String ABSOLUTE_URL = "file://" + RECORDS_DIR + '/' + DATA;
final Intent PLAY_RECORD_INTENT = new Intent(Intent.ACTION_VIEW);
final File RECORD_FILE = new File(RECORDS_DIR, DATA);
PLAY_RECORD_INTENT.setDataAndType(Uri.fromFile(RECORD_FILE), "audio/*");
final ClickableIntentURLSpan INTENT_URL = new ClickableIntentURLSpan(getApplicationContext(), ABSOLUTE_URL, PLAY_RECORD_INTENT);
final SpannableString HYPERLINK = new SpannableString(DATA);
HYPERLINK.setSpan(INTENT_URL, 0, DATA.length(), 0);
editor.setMovementMethod(LinkMovementMethod.getInstance());
if (editor.length() > 0)
{
editor.append("\n");
editor.append(HYPERLINK);
}
else
editor.append(HYPERLINK);
return true;

List intent available android wear

I try to start activity from a watchface or a app android.
I able to start the view to choose watchface when user tap on watchface :
#Override
public void onTapCommand(
#TapType int tapType, int x, int y, long eventTime) {
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
I want start other activities like Google Agenda, Google fit, or other ...
It's possible to list all intents available on the device ?
Thanks
This will return all of the launcher activities on a device:
public static List<ResolveInfo> gatherApps(Context context) {
if(allApps == null) {
final PackageManager packageManager = context.getPackageManager();
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> infoList = context.getPackageManager().queryIntentActivities(mainIntent, 0);
Collections.sort(infoList, new Comparator<ResolveInfo>() {
#Override
public int compare(ResolveInfo lhs, ResolveInfo rhs) {
return lhs.loadLabel(packageManager).toString().compareTo(rhs.loadLabel(packageManager).toString());
}
});
allApps = infoList;
}
return allApps;
}

How to navigate gmail app info programmatically in android

How to navigate to Google map app info settings screen in android programmatically
please see this above link.
This is my exact requirement, how to solve this problem
in 2.2 and below, there is no public APIs you can access. But you can still start the InstalledAppDetails activity just as the ManageApplications does.
// utility method used to start sub activity
private void startApplicationDetailsActivity() {
// Create intent to start new activity
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, InstalledAppDetails.class);
intent.putExtra(APP_PKG_NAME, mCurrentPkgName);
// start new activity to display extended information
startActivityForResult(intent, INSTALLED_APP_DETAILS);
}
Conclusion: you can start the "application info" screen like this i wrote:
private static final String SCHEME = "package";
private static final String APP_PKG_NAME_21 = "com.android.settings.ApplicationPkgName";
private static final String APP_PKG_NAME_22 = "pkg";
private static final String APP_DETAILS_PACKAGE_NAME = "com.android.settings";
private static final String APP_DETAILS_CLASS_NAME = "com.android.settings.InstalledAppDetails";
public static void showInstalledAppDetails(Context context, String packageName) {
Intent intent = new Intent();
final int apiLevel = Build.VERSION.SDK_INT;
if (apiLevel >= 9) { // above 2.3
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts(SCHEME, packageName, null);
intent.setData(uri);
} else { // below 2.3
final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
: APP_PKG_NAME_21);
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName(APP_DETAILS_PACKAGE_NAME,
APP_DETAILS_CLASS_NAME);
intent.putExtra(appPkgName, packageName);
}
context.startActivity(intent);
}

How do I start another application (downloaded or preinstalled) from an activity?

Basically, I want to get a list of all installed apps and pick one to run from an activity.
I've tried ACTION_PICK with Intents but that seems to leave out apps that were downloaded and it has a bunch of junk in it.
Thanks
// to get the list of apps you can launch
Intent intent = new Intent(ACTION_MAIN);
intent.addCategory(CATEGORY_LAUNCHER);
List<ResolveInfo> infos = getPackageManager().queryIntentActivities(intent, 0);
// resolveInfo.activityInfo.packageName = packageName
// resolveInfo.activityInfo.name = className
// reusing that intent
intent.setClassName(packageName, className);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(intent)
Hope that's enough to help you figure out.
final File favFile = new File(Environment.getRootDirectory(), DEFAULT_FAVORITES_PATH);
try {
favReader = new FileReader(favFile);
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "Couldn't find or open favorites file " + favFile);
return;
}//gives the path for downloaded apps in directory
private void loadApplications(boolean isLaunching) {
if (isLaunching && mApplications != null) {
return;
}
PackageManager manager = getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));
if (apps != null) {
final int count = apps.size();
if (mApplications == null) {
mApplications = new ArrayList<ApplicationInfo>(count);
}
mApplications.clear();
for (int i = 0; i < count; i++) {
ApplicationInfo application = new ApplicationInfo();
ResolveInfo info = apps.get(DEFAULT_KEYS_SEARCH_LOCAL);
application.title = info.loadLabel(manager);
application.setActivity(new ComponentName(
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name),
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
application.icon = info.activityInfo.loadIcon(manager);
mApplications.add(application);
}
}
This will help u to load all the apps downloaded.

Categories

Resources