I am trying to get a button on my app go to the market place when clicked. Not to another app, but to my publisher area with all my apps. Can anyone help, it just seems to force close at the moment?
final String APP_MARKET_URL = "market://developer?pub=PUB+ID+HERE";
I think that the correct string is market://search?q=pub:PUB+ID+HERE
If your string is correct too, try doing it with this code
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_MARKET_URL));
market.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(market);
Related
I make an app that like android dialer. I need to show my app on "open with" list when someone click on number on android (like default dialer or get contact), and how to get the number clicked and put it on textview on my app..?
Im sorry if there was a same question, but i tried to find the sollution then still nothing.
I know it's a bit late to answer, but, in case somebody else is looking for the short answer, this code worked for me:
Intent intent = getIntent();
Uri returnUri = intent.getData();
String phoneNumber = returnUri.toString().replace("%20", "").replace("tel:","");
Log.i("PHONE_NUMBER", phoneNumber);
I am trying to add a search bar into an Android app that will open a browser to search Google. How would this be done in the simplest way?
You need an Edittext and a Button and if someone click on the button get the text from the edittext (getText()), and cear the EditText. After that you can create the url string from "www.google.com/#q=" plus the text and finally you can do:
Uri uri = Uri.parse(urlString);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
That's all, I hope it's helped.
Now i am working on a Home Launcher application.I want to clear defaults of default home launcher(eg: Samsung Home). ie.I want to show Settings-> Applications->Manage Application->Samsung Home->clear defaults programmatically.
How to show this through code?
Thanks in Advance
NOTE: Since this question is limited to accessing the Manage Application Settings options, my answer covers just that. You will have to figure out a way of getting the actual Package Name.
Also, if the idea is to also Clear the Defaults automatically via code, then that, to the best of my knowledge, cannot be done. Someone can correct me if I am wrong on this.
That being said, this piece of code will open the specific application's Manage Application screen from your app (the package name must be supplied).
Intent showSettings = new Intent();
showSettings.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uriAppSettings = Uri.fromParts("package", "THE_APP_PACKAGE_NAME", null);
showSettings.setData(uriAppSettings);
startActivity(showSettings);
For example, if the package name of the Google Maps application is com.google.android.apps.maps, the replace THE_APP_PACKAGE_NAME with it and the code will open the Manage Application screen for the Google Maps application.
UPDATE:
The PackageManager has a method, clearPackagePreferredActivities used to clear the default via code. However, that doesn't seem to work in newer Android versions: https://stackoverflow.com/a/10246711/450534
Other posts worth reading:
https://stackoverflow.com/a/7750187/450534
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/Rzv8VU-EUAw
Just for complete the picture, for getting "THE_APP_PACKAGE_NAME" youc can use something like that :
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
String packageName = resolveInfo.activityInfo.packageName;
hi everybody i've a little problem..i'm trying to share a text using google plus app, but the lastest version give me a problem.
when i call with an intent "com.google.android.apps.plus", android display me this dialog
so if i choose the first one, text will be shared correctly, but the second one do nothing.
if the app is not intalled i redirect the user to the market, at g+ download page (this work fine)
if (v == plus) {
social(2);
targetedShareIntent.putExtra(
android.content.Intent.EXTRA_TEXT, user);
targetedShareIntent
.setPackage("com.google.android.apps.plus");
startActivity(targetedShareIntent);
}
"v" is a button and social check if app is installed
any sugestion?
both options open google+ application?
I suppose show two options because google+ app have two activities with category.LAUNCHER.... the app and the chat app
PSDT: sorry for my bad english!
I was able to get the G+ dialog to launch with the following code (after querying the package manager to make sure the app was actually installed and passing in the currentContext as a parameter):
Intent appIntent = new Intent(Intent.ACTION_SEND);
String shareText = "Share text goes here";
appIntent.setType("text/plain");
appIntent.putExtra(Intent.EXTRA_TEXT, shareText);
//Filters so only the G+ app will launch
appIntent.setPackage("com.google.android.apps.plus");
try {
currentContext.startActivity(appIntent);
} catch (android.content.ActivityNotFoundException e) {
Log.d(e.getMessage());
}
Drove me bananas figuring this out, so I figured I'd try to save someone else the hassle.
I would like to start a default application: browser, contact-book, phone, email, music app, etc. I have found many q/a, like browser opening a specific URL or blank, and here the answer is even "No not possible". But I would like to just open/launch it without telling it to go to a specific URL or sending a mail to someone, etc.
However, I also saw some Home applications where this seems to be working (at least for some apps). On my colleague's device there is for example a different contact-book (no google) which is detected and opened correctly.
I have seen in the Android documentation some intent categories that point to these problems, but these are only >= API.11. So I can't use/test them on my device.
Question: Is it not somehow possible to launch a default application (having the app chooser is of course ok) without providing extra data? If no, what do you think are these Home apps doing (perhaps workarounds are somehow possible).
PS: for the phone app I think, I have a workaround using Intent.ACTION_DIAL without any other information which will open simply the dialer.
UPDATE: I modified the title. Some applications like the address book may not be the same on different devices. So in this case I would like to start the address-book app, whichever this is.
This answer is not a 100% answer, but some workarounds on some typical applications.
Still open are: music player, address book
Browser: I get a list of applications that handle "http"-data intents, and then I look if one is available in the list of preferred applications.
Intent appFilter = new Intent(Intent.ACTION_VIEW);
appFilter.setData(Uri.parse("http://www.google.com"));
List<ResolveInfo> browserInfoList = pm.queryIntentActivities(appFilter, 0);
List<IntentFilter> outFilters = new ArrayList<IntentFilter>();
List<ComponentName> outActivities = new ArrayList<ComponentName>();
pm.getPreferredActivities(outFilters, outActivities, null);
if(outActivities.size() > 0) {
for(ComponentName cn : outActivities) {
String cnClass = cn.getClassName();
String cnPkg = cn.getPackageName();
for (ResolveInfo info : browserInfoList) {
if(info.activityInfo.name.equals(cnClass) &&
info.activityInfo.packageName.equals(cnPkg)) {
return cn;
}
}
}
}
In case no default is found, I open a browser chooser dialog, see here.
Phone: as described in the question:
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);
You can start apps by the function "startActivity" if you know about the canonical app name
like "android.com.browser". Do this simple by searching for AndroidManifest.xml in the app
source code (look at Codeaurora.com or at github/Cyanogenmod) and grab the app name you want.
After you know about the App name ("Activity") implement the code as follows:
Intent intent = new Intent();
intent.setClassName(this, "com.android.browser");
intent.setCategory(Intent.ACTION_MAIN);
startActivity(intent);
THIS is only a example, sometimes you have to put intent extras or data values, this information can be found in the app's AndroidManifest.xml too.