Search code examples
androidpocket

Share to Pocket


I´m trying to share some text to Pocket app, but it keeps telling me:

"Could not be saved to Pocket. The shared content did not contain any valid web addresses"

I use this snippet to share:

Intent intent = new Intent(android.content.Intent.ACTION_SEND); 
intent.setClassName(info.activityInfo.packageName, info.activityInfo.name); 
intent.setType("text/plain"); 
intent.putExtra(Intent.EXTRA_SUBJECT, subject); 

if(info.activityInfo.packageName.contains("pocket"))  { 
    intent.putExtra(Intent.EXTRA_TEXT, link); 
}

((Activity)context).startActivity(intent);

It works for GMail or Evernote, but something is wrong with sharing to Pocket. I bet it is connected with putExtra() and what to put there. Could anyone explain this?

Thanks!


Solution

  • The problem is here:

    if(info.activityInfo.packageName.contains("pocket"))  { 
      intent.putExtra(Intent.EXTRA_TEXT, link); 
    }
    

    You are checking to see if the package name for your current activity contains the word "pocket". If it doesn't, your intent will not contain EXTRA_TEXT which the Pocket app needs.

    Why not always provide EXTRA_TEXT?

    If you truly only want to populate EXTRA_TEXT if the Pocket app is installed, you could do something like:

    PackageManager pm = getPackageManager(); 
    try {
           pm.getPackageInfo("com.ideashower.readitlater.pro", PackageManager.GET_ACTIVITIES);
           intent.putExtra(Intent.EXTRA_TEXT, link); 
    } catch (PackageManager.NameNotFoundException e) { 
          // Pocket app not installed
    }