我创建了一个带有abstract class
的呼叫接收器,通过接收呼叫开始录音并在通话端停止录音,此流程工作完美。困难的是通话结束后,我想打开我的表单,该表单也有效,但有时会产生问题,意图没有启动,是有人帮助我出了什么问题,我的activity
有时没有打开。使用以下代码启动activity
。
Intent dialogIntent = new Intent();
dialogIntent.setAction(Intent.ACTION_MAIN);
dialogIntent.addCategory(Intent.CATEGORY_LAUNCHER);
dialogIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName cn = new ComponentName(context, CustomerEntery.class);
dialogIntent.setComponent(cn);
context.startActivity(dialogIntent);
任何帮助将不胜感激。提前致谢
将您的组件行替换为:
ComponentName cn = new ComponentName("The package name of the activity that you wish to launch","Its fully qualified class name");
喜欢
final ComponentName cn = new ComponentName(“com.android.settings”, “com.android.settings.fuelgauge.CustomerEntery”)
试一试,希望有帮助!
编辑:实现相同目的的另一种方法:
public boolean openActivity(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new ActivityNotFoundException();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
return true;
} catch (ActivityNotFoundException e) {
return false;
}
}
然后:
openActivity(this, “com.android.settings.fuelgauge.CustomerEntery”);