I am trying to make an app that opens android market page of selected app & lets user download it.I have used below intent to open market.
Intent intent = new Intent (Intent.ACTION_VIEW);
intent.setData (Uri.parse ("market://details?id=" + PackageName ));
intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult (intent, 13);
but I always get resultcode 0 in onActivityResult.StackTrace says:
I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.VIEW dat=market://details?id=com.google.android.apps.unveil flg=0x10000000 cmp=com.an
droid.vending/.AssetInfoActivity }
W/ActivityManager( 79): Activity is launching as a new task, so cancelling activity result.
What I want is that market returns me some response that user downloaded the app or just cancelled.
EDIT: @CommonsWare I am trying to access added package here But cant figure what should be key to get packagename from extras of ACTION_PACKAGE_ADDED
public class ServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//Do this when the system sends the intent
Bundle b = intent.getExtras();
String packagename = b.get(?); //cant figure what should be key to get packagename //from extras
}
}
The Android Market is not set up to support startActivityForResult()
. Also, bear in mind that the download and installation happen asynchronously (i.e., user clicks Install, and the download occurs in the background, and they finish the install via the Notification
).
@CommonsWare Superb!
Your solution proved helpful & it also landed me to another very useful page http://devdaily.com/java/jwarehouse/android/core/java/com/android/internal/content/PackageMonitor.java.shtml
Below is a code snippet from above link source to get package name of currently installed app from broadcast intent:
String getPackageName(Intent intent) {
Uri uri = intent.getData();
String pkg = uri != null ? uri.getSchemeSpecificPart() : null;
return pkg;
}
Thanks Commonsware.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With