Ok, so what I want to do is create a widget that will simply launch another application when the widget is pressed. The applications, however, are not ones I have created, i.e. the Market app, the Browser and things like that. I have already setup the AppWidgetProvider and did开发者_Python百科 all the changing in the manifest and all those things. I just need to know what I must add to the class/Java Source File that will do so. Any help is appreciated, thanks!
Try doing this:
String packageName = "com.package";
String className = "com.package.MainActivity";
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(packageName, className));
startActivity(intent);
UPDATE:
This looks like a better way of launching an application:
PackageManager pm = getPackageManager();
try
{
String packageName = "com.example.package";
Intent launchIntent = pm.getLaunchIntentForPackage(packageName);
startActivity(launchIntent);
}
catch (Exception e1)
{
}
精彩评论