我是Android的新手。我有一个任务是在没有应用程序背景的情况下从应用程序拨打电话,或者在拨打GSM电话后重新启动应用程序。
这是我的代码:
class DialInAndOpenApp extends AsyncTask<Void, Void, ProgressDialog> {
ProgressDialog mProrgessDialog = new ProgressDialog(getActivity());
@Override
protected void onPreExecute() {
super.onPreExecute();
mProrgessDialog.setMessage("loading");
mProrgessDialog.setIndeterminate(true);
mProrgessDialog.show();
//make the GSM call
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + 123));
startActivity(callIntent);
Log.e("Async", "we made the call");
}
@Override
protected ProgressDialog doInBackground(Void... params) {
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
Log.e("Async", "backgrounded");
return mProrgessDialog;
}
@Override
protected void onPostExecute(ProgressDialog result) {
super.onPostExecute(result);
//open the app
Intent openAppIntent = new Intent(getActivity(), SplashScreen.class);
startActivity(openAppIntent);
mProrgessDialog.dismiss();
Log.e("Async", "opened the app");
}
}
我在OnClick方法中调用它。它在Lollipop上完成了工作,但在非Lollipop设备上它并没有将应用程序带到前面。有什么建议?提前谢谢。