我目前正在为Android开发一个应用程序,但是..有一个我的活动,用户应点击一个按钮,它将打开安装在用户设备上的Android终端EMulator,但是现在,我有一个问题,我的代码不工作..检查出来
ClockWorkModFlash.java
package com.loadedgeek.myupgrade;
导入android.os.Bundle; import android.app.Activity;进口 android.os.Handler; import android.content.Intent;进口 android.widget.Button; import android.view.View;
公共类ClockWorkModFlash扩展了Activity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.clockworkmod_activate); Button bClock = (Button) findViewById(R.id.FlashClockWork); bClock.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(Intent.ACTION_MAIN); PackageManager managerclock = getPackageManager(); i = managerclock.getLaunchIntentForPackage(jackpal.androidterm); i.addCategory(Intent.CATEGORY_LAUNCHER); startActivity(i); } }); }}
Eclipse不允许我编译应用程序,因为这是最后一个活动,它说Packagemanager和OnClickListner无法解决......任何想法?
答案 0 :(得分:0)
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(ComponentName.unflattenFromString("application Package name /application launcher activity name"));
intent.addCategory("android.intent.category.LAUNCHER");
startActivity(intent);
答案 1 :(得分:0)
PackageManager managerclock = getPackageManager();
Intent i = managerclock.getLaunchIntentForPackage(jackpal.androidterm);
i.addAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
或
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(ComponentName.unflattenFromString("jackpal.androidterm");
intent.addCategory("android.intent.category.LAUNCHER");
startActivity(intent);
顺便说一下,你的错误“ Packagemanager和OnClickListener无法解析”,我想你可以改变代码:
bClock.setOnClickListener(new OnClickListener() {…}
为:
bClock.setOnClickListener(new View.OnClickListener() {…}