在我的Android应用程序中打开另一个应用程序

时间:2013-12-04 12:42:17

标签: android twitter

我有一个打开推特帖子页面的方法,但是一旦点击按钮执行此操作,就没有任何反应。没有任何回应。我甚至尝试过一种简单的方法,只是从我的应用程序打开任何其他已安装的应用程序,但它不起作用。

该应用程序不会崩溃,它就像一个假人。它什么都不做。

知道问题可能是什么?

以下是代码:

public void openTwitter(View v) {


        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
            (String) v.getTag(R.string.app_name));
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,
            (String) v.getTag(R.drawable.ic_launcher));
    PackageManager pm = v.getContext().getPackageManager();
    List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent,
            0);
    for (final ResolveInfo app : activityList) {
        if ("com.twitter.android.PostActivity"
                .equals(app.activityInfo.name)) {
            final ActivityInfo activity = app.activityInfo;
            final ComponentName name = new ComponentName(
                    activity.applicationInfo.packageName, activity.name);
            shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            shareIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            shareIntent.setComponent(name);
            v.getContext().startActivity(shareIntent);
            break;
        }
    }

错误日志:

12-04 20:36:57.229: ERROR/DataRouter(1689): DSR is ON. Don't send DTR ON.
12-04 20:36:57.414: ERROR/lights(1849): write_int: path  /sys/devices/virtual/sec/sec_touchkey/brightness, value 1
12-04 20:36:58.914: ERROR/lights(1849): write_int: path /sys/devices/virtual/sec/sec_touchkey/brightness, value 2
12-04 20:36:59.229: ERROR/DataRouter(1689): usb connection is true 
12-04 20:36:59.229: ERROR/DataRouter(1689): DSR is ON. Don't send DTR ON.
12-04 20:36:59.999: ERROR/AlarmManagerService(1849): android_server_AlarmManagerService_set to type=3, 8893.012000000
12-04 20:37:01.229: ERROR/DataRouter(1689): usb connection is true 
12-04 20:37:01.229: ERROR/DataRouter(1689): DSR is ON. Don't send DTR ON.
12-04 20:37:01.739: ERROR/AlarmManagerService(1849): android_server_AlarmManagerService_set to type=3, 8951.273000000
12-04 20:37:03.234: ERROR/DataRouter(1689): usb connection is true 
12-04 20:37:03.234: ERROR/DataRouter(1689): DSR is ON. Don't send DTR ON.
12-04 20:37:05.234: ERROR/DataRouter(1689): usb connection is true 
12-04 20:37:05.234: ERROR/DataRouter(1689): DSR is ON. Don't send DTR ON.
12-04 20:37:06.919: ERROR/Watchdog(1849): !@Sync 296
12-04 20:37:07.234: ERROR/DataRouter(1689): usb connection is true 
12-04 20:37:07.234: ERROR/DataRouter(1689): DSR is ON. Don't send DTR ON.

1 个答案:

答案 0 :(得分:0)

试试这个: 我这样做了,

Intent i;
PackageManager manager = getPackageManager();
try {
    i = manager.getLaunchIntentForPackage("app package name");
    if (i == null)
        throw new PackageManager.NameNotFoundException();
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(i);
} catch (PackageManager.NameNotFoundException e) {

}

(或)

    Intent intent = new Intent("android.intent.action.MAIN");
    intent.setComponent(ComponentName.unflattenFromString("com.google.android.maps.mytracks/com.google.android.apps.mytracks.MyTracks"));
    intent.addCategory("android.intent.category.LAUNCHER");
    startActivity(intent);

这里用您的包替换包名。 希望它可以帮到某人。