Skip to content

Instantly share code, notes, and snippets.

@ntkachov
Last active December 27, 2015 09:59
Show Gist options
  • Save ntkachov/7307531 to your computer and use it in GitHub Desktop.
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
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;
}
}
@rishabhMaltare
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment