简体   繁体   English

从我的Android应用中打开另一个应用

[英]opening another app from my app in android

I have a method to open a twitter posting page, but once a click the button to do this, nothing happens. 我有一种打开Twitter发布页面的方法,但是一旦单击该按钮,就什么也没有发生。 No response no anything. 没有回应,没有任何反应。 I have even tried a simple method just to open any other installed app from my app but it does't work. 我什至尝试了一种简单的方法,只是从我的应用程序中打开任何其他已安装的应用程序,但是它不起作用。

The app doesn't crash, it's just like a dummy. 该应用程序不会崩溃,就像一个假人。 It won't do anything. 它什么也不会做。

Any idea what the problem could be? 知道可能是什么问题吗?

Here is the code: 这是代码:

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;
        }
    }

Error log: 错误日志:

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.

Try this: I have work it like this, 试试这个:我已经这样工作了,

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

}

(or) (要么)

    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);

Here replace package name with your's. 在此用您的包裹名称替换。 Hope it helps someone. 希望它可以帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM