您的位置:首页 > 其它

Intent.使用小结

2017-12-07 10:32 218 查看

打电话

Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(“tel:12345678”));

startActivity(callIntent);

权限拒绝后就不能再拨打电话了,6.0后可以加一个权限管理对于这种危险权限

通过一个url跳转到一个网页

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new MyListener());
final Uri uri = Uri.parse("http://weibo.cn/qlyh");
intent = new Intent(Intent.ACTION_VIEW, uri);
timer = new Timer();
}
class MyTimerTask extends TimerTask {
@Override
public void run() {
startActivity(intent);
}
}
class MyListener implements OnClickListener {
public void onClick(View v) {
if(task != null)
task.cancel();
task = new MyTimerTask();
timer.schedule(task, 1000);
}
}


使用Intent在onReceive中跳转

package com.jack.buttonkeytest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyReceiver extends BroadcastReceiver{

@Override
public void onReceive( Context context, Intent intent) {
final Context c = context;
new Thread(){
@Override
public void run() {
super.run();
Intent intent = new Intent(c, ShowActivity.class);
c.startActivity(intent);
}
}.start();
}
}


推荐阅读:

Intent或持久化存储处理复杂对象
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: