日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android设置来电铃声和分享操作

發布時間:2024/1/8 Android 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android设置来电铃声和分享操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? ? ? 之前項目里寫的設置來電鈴聲和分享音頻文件如下:

//設置來電鈴聲public void setAsRingTone(String path) {Log.d(TAG, "setAsRingTone--path:" + path);File file = new File(path);if (file.exists()) {Uri newUri = null;ContentValues values = new ContentValues();values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());values.put(MediaStore.MediaColumns.TITLE, file.getName());values.put(MediaStore.Audio.Media.IS_RINGTONE, false);values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);values.put(MediaStore.Audio.Media.IS_ALARM, false);values.put(MediaStore.Audio.Media.IS_MUSIC, false);Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;//查詢媒體數據庫中存不存在對應文件路徑的數據Cursor cursor = this.getContentResolver().query(uri, null,MediaStore.MediaColumns.DATA + "=?",new String[] {file.getAbsolutePath()}, null);try {//如果存在則跟新媒體數據庫,否則插入媒體數據庫if (cursor.moveToFirst() && cursor.getCount() > 0) {String _id = cursor.getString(0);getContentResolver().update(uri, values, MediaStore.MediaColumns.DATA + "=?",new String[] {file.getAbsolutePath()});newUri = ContentUris.withAppendedId(uri, Long.valueOf(_id));} else {newUri = this.getContentResolver().insert(uri, values);}Log.i(TAG, "newUri=" + newUri);RingtoneManager.setActualDefaultRingtoneUri(this,RingtoneManager.TYPE_RINGTONE, newUri);Toast.makeText( getApplicationContext (),"鈴聲設置成功!",Toast.LENGTH_SHORT ).show(); } catch (Exception e) {// TODO: handle exceptionLog.e(TAG, "Exception:" + e.toString());} finally {if (cursor != null) {cursor.close();}}} else {Toast.makeText( getApplicationContext (),"文件不存在,鈴聲設置失敗!",Toast.LENGTH_SHORT ).show(); }}//分享音頻文件public void share(String path) {Log.d(TAG, "Share--path:" + path);File file = new File(path);if (file.exists()) {Intent intent = new Intent(Intent.ACTION_SEND);intent.setType("audio/*");Uri uri = Uri.parse("file://" + path);intent.putExtra(Intent.EXTRA_STREAM, uri);startActivity(Intent.createChooser(intent, "分享"));} else {Toast.makeText( getApplicationContext (),"文件不存在,分享失敗!",Toast.LENGTH_SHORT ).show(); }}? ? ? ? ?當然,分享類型還有很多如:分享文字、圖片等等,這里推薦一篇文章寫的很詳細了:

http://blog.csdn.net/xyz_lmn/article/details/16856843

總結

以上是生活随笔為你收集整理的Android设置来电铃声和分享操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。