开发者

Launch another app from android widget?

开发者 https://www.devze.com 2023-03-23 00:31 出处:网络
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 Bro

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)
{
}
0

精彩评论

暂无评论...
验证码 换一张
取 消