Last active
December 27, 2015 09:59
-
-
Save ntkachov/7307531 to your computer and use it in GitHub Desktop.
Gist to check if Skitch is installed and supports the Action_Edit intent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SkitchVersionChecker { | |
private static final String SKITCH_PACKAGE = "com.evernote.skitch"; | |
private static final String TAG = "Skitch Checker"; | |
/**Build the intent to send to send the edit intent to skitch. | |
* If Skitch is not installed or isn't up to date, it will take | |
* the user to the market and ask them to install skitch. | |
* @param context expects an activity context (not an application context) | |
* @param imagePath A Uri that expects an image. This should point to a file | |
* not to a ContentResovler. | |
*/ | |
public void sendIntentToSkitch(Context context, Uri imagePath){ | |
Intent sendIntent = getEditIntent(); | |
sendIntent.setData(imagePath); | |
if(doesSkitchSupportEditIntent(context)){ | |
context.startActivity(sendIntent); | |
} else { | |
Toast.makeText(context, "Please update or install Skitch", Toast.LENGTH_LONG).show(); | |
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+ SKITCH_PACKAGE)); | |
context.startActivity(marketIntent); | |
} | |
} | |
/** Returns true if skitch supports the Edit intent | |
* @param context any system context | |
* @return True if skitch is up to date and has the right version. | |
*/ | |
public boolean doesSkitchSupportEditIntent(Context context){ | |
PackageManager pm = context.getPackageManager(); | |
List<ResolveInfo> editActivities = pm.queryIntentActivities(getEditIntent(), PackageManager.MATCH_DEFAULT_ONLY); | |
for(ResolveInfo info : editActivities){ | |
if(info.activityInfo.packageName.equals(SKITCH_PACKAGE)){ | |
return true; | |
} | |
} | |
return false; | |
} | |
/** Returns true if any version of skitch is installed | |
* @param context any system context | |
* @return True if skitch is installed. | |
*/ | |
public boolean isSkitchInstalled(Context context) { | |
PackageManager pm = context.getPackageManager(); | |
try { | |
pm.getPackageInfo(SKITCH_PACKAGE, 0); | |
return true; | |
} catch (NameNotFoundException nnfe) { | |
Log.d(TAG, SKITCH_PACKAGE + " is not installed"); | |
} | |
return false; | |
} | |
private Intent getEditIntent(){ | |
Intent sendIntent = new Intent(); | |
sendIntent.setAction(Intent.ACTION_EDIT); | |
sendIntent.setType("image/*"); | |
sendIntent.setPackage(SKITCH_PACKAGE); | |
return sendIntent; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it really working? I have tried it but it didn't work for me. Can you please provide me a working sample?
Skitch tools for image annotations are the actual things which I am looking for quite long time.