I'm developing a lite version for an app on the Android. How can I start an Intent to open the Android Market, preferably with the full version of my app displayed? This is difficult to test on an emulator (which is the closest thing to a device I have), as there seems to be no legal way of installing the Market on it.
That query above works, but when I tried it, it looked like it was bringing up search results based on the name.
If you use something like
intent.setData(Uri.parse("market://details?id=com.wolinlabs.SuperScorepad"));
instead, it will go right to the Android Market page for your app.
I think that's more what you wanted (?)
Found answer in the end:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://search?q=pname:MyApp"));
startActivity(intent);
No way of testing on emulator, though.
Hi I was trying the achieve the same but with one small difference
I DIDN'T WANT TO OPEN IT EMBEDDED ON MY APP
public void start(JSONArray args, CallbackContext callback) {
Intent launchIntent;
String packageName;
String activity;
String uri;
ComponentName comp;
try {
packageName = args.getString(0); //com.android.vending
activity = args.getString(1); //com.google.android.finsky.activities.LaunchUrlHandlerActivity
uri = args.getString(2); //'market://details?id=com.triplingo.enterprise'
launchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage(packageName);
comp = new ComponentName(packageName, activity);
launchIntent.setComponent(comp);
launchIntent.setData(Uri.parse(uri));
this.cordova.getActivity().startActivity(launchIntent);
callback.success();
} catch (Exception e) {
callback.error(e.toString());
}
}
THE BIG DIFFERENCE HERE IS THAT YOU START A NEW APP NOT JUST SHOW GOOGLE PLAY IN YOUR
APP
This code is part of a Cordova plugin but is pretty obvious what you need to do to use it natively.
THE IMPORTANT LINES
launchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage(packageName);
comp = new ComponentName(packageName, activity);
launchIntent.setComponent(comp);
launchIntent.setData(Uri.parse(uri));
Regards
Related
I have read a lot of information on various sites, but not a single method works. There are also a lot of old solutions on the sites that don't work either. Here is my code:
Uri stickerAssetUri = Uri.parse("https://firebasestorage.googleapis.com/v0/b/schooly-47238.appspot.com/o/miners%2Ffimw.png?alt=media&token=9798e9ea-15a0-4ef2-869b-63ce4dc95b78");
String sourceApplication = "com.egormoroz.schooly";
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
intent.putExtra("source_application", sourceApplication);
intent.setType("image/зтп");
intent.putExtra("interactive_asset_uri", stickerAssetUri);
intent.putExtra("top_background_color", "#33FF33");
intent.putExtra("bottom_background_color", "#FF00FF");
Activity activity = getActivity();
activity.grantUriPermission(
"com.instagram.android", stickerAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
activity.startActivityForResult(intent, 0);
}
When this part of the code is triggered, nothing happens to the application. It remains on the same screen.
Based on official documentation from https://developers.facebook.com/docs/instagram/sharing-to-stories/.
You can change this
intent.setType("image/зтп");
to
intent.setType("image/*");
or
intent.setType(MEDIA_TYPE_JPEG);
I think sourceApplication should be your Facebook App ID, not your package name.
hi guys some of my previous questions have been marked down so please be nice.
what i want to know is if there is a bit of code i can use that tell the user of my app that an apk is installed. then to open it within my app.
i have a listview, inside the list view is an list of available apps for download. i have worked out how to find out if the apk is there install instead of download. but i cant seam to figure out the installed bit.
ive tried this
public static boolean isPackageInstalled(Context context, String packageName) {
final PackageManager packageManager = context.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
if (intent == null) {
return false;
}
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
then using
ispackageinstalled();
but this asks for Context, and string
so i tried add this to constructor
Context shb;
private Static String Showbox = "com.tk.Showbox";
then tried
ispackageinstalled(shb,Showbox);
and the app just crashes lol im obviously writing something wrong. also i would like for the selection to turn red if it installed if possible. but getting the app to open would be a great help cheers guys
You need to pass in an actual Context to the method. Your Activity subclass that is hosting the ListView is a Context. Pass the Activity into your ispackageinstalled() method.
found this worked the way i wanted
private boolean isCallable(Intent intent) {
if (intent == null) {
return false;
}
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
then making an Intent with the package details like this
Intent AllcastOpen = getPackageManager().getLaunchIntentForPackage("com.koushikdutta.cast");
then an if statement
if (isCallable(AllcastOpen) == true) {
AllcastInstalled.equals(true);
startActivity(AllcastOpen);
the allcastInstalled is a seperate method that changes the color of the selection if its installed/downloaded depending
i try to show user location in my android app , but it dosnt work! package manager is always null.
private void openPrefredLocationInMap (){
String location =
PreferenceManager.getDefaultSharedPreferences(this)
.getString(getString(R.string.pref_location_key)
, getString(R.string.pref_defult));
Uri geoLocation = Uri.parse("geo:0,0?").buildUpon()
.appendQueryParameter("q", location).build();
Intent intent= new Intent(Intent.ACTION_VIEW,geoLocation);
if (intent.resolveActivity(getPackageManager()) != null)
startActivity(intent);
else
Log.d("package","couldnt call"+location);
}
Your device does not have an application that could handle such intent. Install an application that can handle that intent or make one yourself. To be more specific, you might not have a map application that would be able to display geoLocation intent.
Try installing Google Maps for example.
I am developing an Android App which requires speech to text conversion. Currently I have used Google voice search for this purpose but using google requires internet connection and moreover it gives highly inaccurate results for eg. when I say '1' it prints "when"..
Therefore, I want to define my own grammar such that when I give a voice command it searches the grammar defined by me to find the best possible match instead of searching the internet. Using grammar for speech recognition can be done easily for windows 8 phone but I want to know how I can make this work for Android phones.
Kindly take a look at below codes!..
**Using Intent:::**
Intent intent = new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
try {
startActivityForResult(intent, RESULT_SPEECH);
txtText.setText("");
} catch (ActivityNotFoundException a) {
Toast t = Toast.makeText(getApplicationContext(),
"Opps! Your device doesn't support Speech to Text",
Toast.LENGTH_SHORT);
t.show();
}
Without Using Intent::
Step 1: Implement RecognitionListener in your class.
Step 2. Add the Below codes:
private SpeechRecognizer speech = null;
private Intent speechIntent=null;
/**
* Speech Result is used to Store the Voice Commands
*/
private ArrayList<String> speechResult;
inside onCreate() --- >
speech = SpeechRecognizer.createSpeechRecognizer(this);
speech.setRecognitionListener(this);
Trigger this after your button Click:
if (SpeechRecognizer.isRecognitionAvailable(this)) {
if(speechIntent==null ){
speechIntent=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
speechIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
speechIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,12);
speech.startListening(speechIntent);
}else{
if(speech!=null){
speech.startListening(speechIntent);
}
}
}
Replace the onResults link this:
public void onResults(Bundle results) {
speechResult = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if(speechResult!=null){
if(speechResult.size()>0 ){
String command=speechResult.get(0).toString();
}
}
}
I want to add a shortcut to my application, but I cannot manage not to duplicate native handly created one (by using drag and drop on application Icon in Application Menu to Home Screen for example).
Here is my code:
public void addShortcut(Context context)
{
this.manageShortcutAction(context, "com.android.launcher.action.INSTALL_SHORTCUT");
}
public void deleteShortcut(Context context)
{
this.manageShortcutAction(context, "com.android.launcher.action.UNINSTALL_SHORTCUT");
}
private void manageShortcutAction(Context context, String intentAction)
{
Context applicationContext = context.getApplicationContext();
Intent shortcut = new Intent(intentAction);
ApplicationInfo appInfo = applicationContext.getApplicationInfo();
PackageManager packageManager= applicationContext.getPackageManager();
String applicationName = (String) packageManager.getApplicationLabel(appInfo);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, applicationName); // Shortcut name
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, packageManager.getLaunchIntentForPackage(appInfo.packageName));// Setup activity should be shortcut object
shortcut.putExtra("duplicate", false); // Just create once
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(applicationContext, appInfo.icon));// Set shortcut icon
applicationContext.sendBroadcast(shortcut);
}
And my manifest required permissions:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
By the way, I had overwritten the Application code which is now MainApplication extending Application.
I have already tried to create a component to create the Intent.EXTRA_SHORTCUT_INTENT, without the expecting result.
If anyone has an idea...
I found out that in order to prevent the app from creating a duplicate of the shortcut created at app installation (or by copying from the menu), I have to create one with the same parameters of the existing one - using the same shortcut name is not enough.
After a lot of testing and thanks to the logcat, I've been able to create an exact replica as follows:
private void installShortcut() {
final Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
final Intent intent = new Intent();
intent.putExtra("duplicate", false);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
}
The difference with other answers I found on SO is in these 3 lines:
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
which I figured out by looking at the log entry printed when manually launching the app using the system created shortcut
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.myapp/.activities.main.MainActivity bnds=[365,73][475,191] } from pid 279
After having discuss with Sony's developers, there is no way not to duplicate manually created shortcuts...
I found some methods for Samsung but these were not generic.