开放系统应用程序使用意向 [英] Opening System Application Using Intent

查看:155
本文介绍了开放系统应用程序使用意向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个简单的应用程序,它会向用户发送从主屏幕或应用程序的抽屉用户点击,当特定的(系统安装)应用程序(系统设置,日历,浏览器等)。

I am trying to make a simple application which will send the user to a specific (system installed) app (system settings, calendar, browser, etc.) when clicked by the user from the home screen or app drawer.

例如,目前我正在试图打开时我的应用程序启动的系统设置,就像对于设置的快捷操作。

For instance, I am currently trying to open the system settings whenever my app is launched, just like a shortcut for settings does.

是否有可能实现这一点,我想要的方式?有没有人有什么建议?

Is it possible to implement this the way I want it? Does anyone have any suggestions?

下面是我的code:

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;


public class MainActivity extends Activity {

    public void  LaunchComponent (String packageName, String name){
        Intent i = new Intent(Intent.ACTION_MAIN);
        PackageManager manager = getPackageManager();
        i = manager.getLaunchIntentForPackage("com.sec.android.app.controlpanel");
        i.addCategory(Intent.CATEGORY_LAUNCHER);
        startActivity(i);

    }
}

我目前还没有一个布局文件,如main.xml中,在我的应用程序,因为它不具有任何UI或布局元素。所有应该做的是向用户发送到另一个应用程序的活动。我一直在使用本教程(丢失的链接),我已经实现了所有的code例子,我不出来,我是新的android开发和java是不是我的最好的语言。打开任何的批评或建议。

I currently do not have a layout file, such as main.xml, in my app, as it doesn't have any UI or layout elements. All it should do is send the user to another app activity. I have been using this tutorial (missing link) and I've implemented all the code examples and I cannot figure it out, I am new to android development and java is not my best language. Open to any criticism or suggestions.

推荐答案

您必须使呼叫LaunchComponent可以在第一的onCreate生命周期的回调函数来完成

You have to make the call to LaunchComponent which can be done in onCreate first life-cycle callback function

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
     LaunchComponent (packageName, name);
}

更新

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;


public class MainActivity extends Activity {

public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
         LaunchComponent ("com.sec.android.app.controlpanel", "abc?");
    }


public void  LaunchComponent (String packageName, String name){
    Intent i = new Intent(Intent.ACTION_MAIN);
    PackageManager manager = getPackageManager();
    i = manager.getLaunchIntentForPackage(packageName);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(i);

}

这篇关于开放系统应用程序使用意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆