【问题标题】:Android 2.2: How to make an app to run automaticly on startup & how to make an app start another appAndroid 2.2:如何让一个应用在启动时自动运行以及如何让一个应用启动另一个应用
【发布时间】:2010-12-30 20:58:58
【问题描述】:

这个话题几乎说明了一切。

【问题讨论】:

    标签: java android autostart bootcompleted


    【解决方案1】:

    使用BroadcastReceiver 接收动作意图BOOT_COMPLETED

    在 onReceive() 方法中为您的活动创建一个 Intent:

    @Override
    public void onReceive(Context context, Intent intent) {
    
     Intent myIntent = new Intent(context, YourActivity.class);
     context.startActivity(myIntent);
    }
    

    【讨论】:

    • 我已经添加了权限,但是我把这段代码放在哪里呢?抱歉,但我今天开始开发应用程序 :) 谢谢
    • 当然是在你的 BroadcastReceiver 中。请参阅链接。抱歉,它是俄语,但两个代码示例就足够了。 ondroid.info/primer-ispolzovaniya-broadcast-receiver-v-android
    【解决方案2】:

    对于启动时的应用,需要添加权限

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    

    到您的清单。 然后按照弗拉基米尔写的去做。

    要启动另一个应用程序,您需要知道(希望是官方的)启动它的意图。否则请参阅我对问题的回复 calling an activity that is in another package(android)

    例如,启动 LastFM 应用程序是这样的:

    final Intent i = new Intent("android.intent.action.MAIN");                
    i.setComponent(new ComponentName("fm.last.android","fm.last.android.LastFm"));
    startActivity(i);
    

    【讨论】:

    • 好的,但是我在哪里可以找到我想要运行的应用程序中的“fm.last.android”和“fm.last.android.LastFm”?例如 Doplhin 网络浏览器。
    • 定期打开 dolphin 浏览器,当你这样做时,通过“adb shell logcat”检查 logcat,然后你会在日志中看到调用了哪个意图。然后使用 ComponentName 中的值。你想要哪只海豚?高清、迷你还是普通的?
    • 对于 Dolphin HD,尝试: new ComponentName("mobi.mgeek.TunnyBrowser","mobi.mgeek.TunnyBrowser.BrowserActivity") - 对于常规 Dolphin,尝试: new ComponentName("com.mgeek. android.DolphinBrowser.Browser","com.mgeek.android.DolphinBrowser.Browser.BrowserActivity")
    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多