话不多说了,直接上代码,这篇文章包含了一些基本的并且常用的跳转工具,一起来看看吧。 首先,这是需要的对应的权限。 <uses-permission Android:na
话不多说了,直接上代码,这篇文章包含了一些基本的并且常用的跳转工具,一起来看看吧。
首先,这是需要的对应的权限。
<uses-permission Android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
代码:
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import java.io.File;
import frame.zmit.cn.publicutils.R;
public class MainActivity extends AppCompatActivity {
private String mImagePath;//返回的图片路径
private final static int REQUEST_CODE_GALLERY = 0x11;
private final static int REQUEST_CODE_CAMERA = 0x12;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_open_weixin).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
startActivity(intent);
}
});
findViewById(R.id.btn_open_qq).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String MQqNumber = "98*****08";
String url11 = "mqqwpa://im/chat?chat_type=wpa&uin=" + mQqNumber + "&version=10";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url11)));
}
});
findViewById(R.id.btn_people_interface).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClassName("com.android.contacts", "com.android.contacts.activities.PeopleActivity");
startActivity(intent);
}
});
findViewById(R.id.btn_telephone_interface).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phone = "157*****737";
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
findViewById(R.id.btn_telephone).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phone = "157*****737";
Intent intentPhone = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
startActivity(intentPhone);
}
});
findViewById(R.id.btn_message_interface).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
}
});
findViewById(R.id.btn_message).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phone = "157*****737";
String message = "这是一个自定义的内容";
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + phone));
intent.putExtra("sms_body", message);
startActivity(intent);
}
});
findViewById(R.id.btn_setting_interface).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_SETTINGS);
startActivity(intent);
}
});
findViewById(R.id.btn_bluetooth_interface).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
startActivity(intent);
}
});
findViewById(R.id.btn_browser).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("Http://www.baidu.com");
intent.setData(content_url);
startActivity(intent);
}
});
findViewById(R.id.btn_camera).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mImagePath = chooseImageFromCamera(MainActivity.this, REQUEST_CODE_CAMERA, "cameraImage");
}
});
findViewById(R.id.btn_gallery).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image
imagePath = data.getData().getPath();
} else {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imagePath = cursor.getString(columnIndex);
cursor.close();
}
return imagePath;
} else {
return null;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_GALLERY:
mImagePath = onActivityResultForChooseImageFromGallery(MainActivity.this,
requestCode, resultCode, data);
if (mImagePath != null && mImagePath.length() > 0) {
Toast.makeText(MainActivity.this, mImagePath, Toast.LENGTH_SHORT).show();
}
break;
case REQUEST_CODE_CAMERA:
if (mImagePath != null && mImagePath.length() > 0) {
Toast.makeText(MainActivity.this, mImagePath, Toast.LENGTH_SHORT).show();
}
break;
}
}
}
总结
总结安卓(Android)中常用的跳转工具到这就结束了,这篇文章整理的这些跳转工具类很常见,所以才是最实用的,希望本文对大家日常开发Android能有所帮助。
您可能感兴趣的文章:Android View进行手势识别详解Android 屏幕双击事件的捕获简单示例Android中图片的三级缓存机制Android自定义View实现圆环交替效果Android 调试工具用法详细介绍Android自定义view实现水波纹进度球效果Android 源码如何编译调试轻松实现安卓(Android)九宫格解锁Android禁止横屏竖屏切换的有效方法Android Service判断设备联网状态详解
--结束END--
本文标题: 总结安卓(Android)中常用的跳转工具
本文链接: https://lsjlt.com/news/24188.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0