Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ANDROID-从广播接收器启动其他应用程序_Android_Broadcastreceiver_Android C2dm - Fatal编程技术网

ANDROID-从广播接收器启动其他应用程序

ANDROID-从广播接收器启动其他应用程序,android,broadcastreceiver,android-c2dm,Android,Broadcastreceiver,Android C2dm,我需要从广播接收器启动/打开设备中安装的一个apk 代码如下: 公共类C2DMMessageReceiver扩展了BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Log.w("C2DM", "Message Receiver called"); if ("com.google.a

我需要从广播接收器启动/打开设备中安装的一个apk

代码如下:

公共类C2DMMessageReceiver扩展了BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    Log.w("C2DM", "Message Receiver called");
    if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
        Log.w("C2DM", "Received message");
        ComponentName toLaunch = new ComponentName("es.mypackage","es.mypackage.myapplication");
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER); 
        intent.setComponent(toLaunch); 
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(intent);
我的设备接收到广播,但由于意外问题而失败

启动其他apk的代码在应用程序的其他部分工作正常

是否可以从广播启动其他应用程序


非常感谢。

根据我的经验,您不能从C2DM接收器启动活动,我找到了解决方法,创建一个服务并从该服务启动活动,启动活动后停止服务


谢谢,

我可以从C2DM接收器启动一个活动:Intent Intent=new Intent();Intent.setFlags(Intent.FLAG_activity_new_TASK | Intent.FLAG_activity_CLEAR_TOP);Intent.setClass(context,MuestraTexto.class);context.startActivity(Intent);这很好,打开了我的应用程序窗口。只有当我尝试启动安装的外部应用程序时,我发布的第一个代码才失败。谢谢:)