【问题标题】:Learning about the ACTION_MAIN了解 ACTION_MAIN
【发布时间】:2016-07-15 14:47:34
【问题描述】:

我正在探索 Android 编程的 Intent 世界并发现了

Intent sendIntent = new Intent(Intent.ACTION_MAIN);         
        sendIntent.setData(Uri.parse(xxx));

听说ACTION_MAIN可以打开其他app,如果可以,setData部分的xxx应该填什么?

【问题讨论】:

    标签: android eclipse android-intent


    【解决方案1】:

    你在这里有一些误解,

    ACTION_MAIN

    上面一个用于定义一个应用程序的入口点,它不需要输入也没有输出。

    official documentation

    public static final String ACTION_MAIN
    
    Added in API level 1
    Activity Action: Start as a main entry point, does not expect to receive data.
    
    Input: nothing
    
    Output: nothing
    
    Constant Value: "android.intent.action.MAIN"
    

    现在让您的查询打开另一个应用程序,

    有多种方法,但无论如何您都需要知道要启动的另一个应用程序的包名称。

    众所周知,most commonly used ways are in this answer 评分低于 1,

    Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
    startActivity(launchIntent);
    

    【讨论】:

    • 我的 getPackageManager 是错误的,据说它未定义。我在这里想念什么吗?
    • 如果你在一个片段中而不是写getActivity().getPackageManager()@Fay
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 2020-09-18
    • 2011-01-07
    • 2012-02-28
    • 2012-09-22
    • 2010-09-29
    • 2014-09-17
    相关资源
    最近更新 更多