调用系统自带的程序android,Android怎么打开和调用系统自带的程序示例(06)

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

// 打电话

public void call(View view) {

Intent intent = new Intent();

intent.setAction(intent.ACTION_CALL);

// intent.setAction("android.intent.action.CALL");

// 以下各项皆如此,都有两种写法。

intent.setData(Uri.parse("tel:10086"));

startActivity(intent);

}

// 调用拨号面板:

public void dial(View view) {

Intent intent = new Intent();

intent.setAction(intent.ACTION_DIAL);

intent.setData(Uri.parse("tel:10086"));

startActivity(intent);

}

// 利用 Uri 打开浏览器、打开地图等:

public void page(View view) {

// Uri uri = Uri.parse("http://www.google.com"); // 浏览器

Uri uri = Uri.parse("geo:39.899533,116.036476"); // 打开地图定位

Intent intent = new Intent();

intent.setAction(intent.ACTION_VIEW);

intent.setData(uri);

startActivity(intent);

}

// 打开视频

public void video(View view) {

Intent intent = new Intent();

Uri uri = Uri.parse("/mnt/sdcard/papa.mp4");

intent.setDataAndType(uri, "video/*");

startActivity(intent);

}

// 打开发送短信的程序

public void sms(View view) {

Intent intent = new Intent();

intent.setAction(intent.ACTION_VIEW);

intent.setType("vnd.android-dir/mms-sms");

intent.putExtra("sms_body", "短信内容");

startActivity(intent);

}

// 发送短信

public void send(View view) {

Uri uri = Uri.parse("smsto:10086");

Intent intent = new Intent();

intent.setAction(intent.ACTION_SENDTO);

intent.setData(uri);

intent.putExtra("sms_body", "短信内容");

startActivity(intent);

}

// 发送彩信 , 设备会提示选择合适的程序发送

public void sendcai(View view) {

Uri uri = Uri.parse("/mnt/sdcard/aaa.png");

Intent intent = new Intent();

intent.setAction(Intent.ACTION_SEND);

intent.setType("image/png");

intent.putExtra("sms_body", " 内容 ");

intent.putExtra(Intent.EXTRA_STREAM, uri);

startActivity(intent);

}

// 打开系统的wifi

public void wifi(View view) {

Intent intent = new Intent();

intent.setAction(Settings.ACTION_WIRELESS_SETTINGS);

startActivity(intent);

}

// 打开系统的声音设置

public void voice(View view) {

Intent intent = new Intent();

intent.setAction(Settings.ACTION_SOUND_SETTINGS);

startActivity(intent);

}

// 返回主界面

public void openhome(View view) {

Intent intent = new Intent();

intent.setAction(intent.ACTION_MAIN);

intent.addCategory(intent.CATEGORY_HOME);

startActivity(intent);

}

// 打开系统的图片

public void openimage(View view) {

Intent intent = new Intent();

intent.setAction(intent.ACTION_VIEW);

// 如果data和type同时存在,不要分开设置

intent.setDataAndType(Uri.fromFile(new File("/mnt/sdcard/papa.jsg")),

"image/*");

/*

* intent.setData(Uri.fromFile(new File("/mnt/sdcard/papa.mp4")));

* intent.setType("video/*");

*/

startActivity(intent);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Android音乐播放器的代码和布局示例: 1. 布局文件 在布局文件中,我们可以使用Android自带的播放器控件`MediaPlayer`来实现音乐播放器的UI界面。以下是一个简单的布局文件示例: ```xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <VideoView android:id="@+id/videoView" android:layout_width="match_parent" android:layout_height="match_parent" /> <LinearLayout android:id="@+id/controls" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal" android:padding="16dp"> <Button android:id="@+id/button_play" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Play" /> <Button android:id="@+id/button_pause" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Pause" /> <SeekBar android:id="@+id/seekBar" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:max="100" android:paddingLeft="16dp" android:paddingRight="16dp" /> </LinearLayout> </RelativeLayout> ``` 在上述布局文件中,我们首先使用`RelativeLayout`作为根布局,并在其中添加了一个`VideoView`控件作为播放器的UI界面。接下来,我们在底部添加了一个`LinearLayout`控件,用于放置播放控制按钮和进度条。其中,`SeekBar`控件用于显示播放进度,`Button`控件用于实现播放、暂停操作。 2. Java代码 在Java代码中,我们需要实现播放控制按钮的点击事件,以及在`SeekBar`控件上显示播放进度。以下是一个简单的Java代码示例: ```java public class MainActivity extends AppCompatActivity { private VideoView videoView; private Button buttonPlay; private Button buttonPause; private SeekBar seekBar; private int totalTime; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); videoView = findViewById(R.id.videoView); buttonPlay = findViewById(R.id.button_play); buttonPause = findViewById(R.id.button_pause); seekBar = findViewById(R.id.seekBar); // 设置播放器的视频资源 videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sample)); // 点击播放按钮开始播放 buttonPlay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { videoView.start(); } }); // 点击暂停按钮暂停播放 buttonPause.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { videoView.pause(); } }); // 显示播放进度 videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mediaPlayer) { totalTime = mediaPlayer.getDuration(); seekBar.setMax(totalTime); } }); videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer) { videoView.seekTo(0); buttonPlay.setText("Play"); } }); final Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { int currentPosition = videoView.getCurrentPosition(); seekBar.setProgress(currentPosition); handler.postDelayed(this, 1000); } }; handler.postDelayed(runnable, 1000); } } ``` 在上述Java代码中,我们首先通过`findViewById`方法获取了布局文件中的控件对象。接着,我们使用`setVideoURI`方法设置了播放器的视频资源。然后,我们实现了播放控制按钮的点击事件,通过调用`start`方法开始播放,通过调用`pause`方法暂停播放。在`SeekBar`控件上,我们通过`setOnPreparedListener`方法获取了视频的总时长,并将其设置为`SeekBar`的最大值。在播放过程中,我们通过`getCurrentPosition`方法获取当前播放位置,并将其设置为`SeekBar`的进度。最后,我们使用`Handler`和`Runnable`实现了每秒更新一次播放进度的操作。 以上是一个简单的Android音乐播放器的代码和布局示例。需要注意的是,以上示例代码仅供参考,实际情况中可能需要根据具体需求进行修改和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值