1、使用广播接受者来设置应用程序开机自动启动
public class MyBroadCast extends BroadcastReceiver{
static final String ACTION="android.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(ACTION))
{
Intent Preciousintent=new Intent(context,MainActivity.class);
Preciousintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(Preciousintent);
}
}
}
2、广播接受者在AndroidManifest.xml中需要配置的代码
<receiver android:name="com.bwie.broadcast.MyBroadCast">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
3、需要设置的权限
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
4、隐式跳转到打电话
Uri uri=Uri.parse("tel:"+tel);
Intent intent=new Intent(Intent.ACTION_CALL,uri);
startActivity(intent);