android 怎么获取音乐专辑图像

android 怎么获取音乐专辑图像,第1张

这是抽取专辑的方法,扫描歌曲的时候自己把歌曲的id和专辑的id传进去就能获取

private static final Uri sArtworkUri = Uri

parse("content://media/external/audio/albumart");

/

将MP3里读取出来

@param context

@param songid

@param albumid

@return

/

public static Bitmap getMusicBitemp(Context context, long songid,

long albumid) {

Bitmap bm = null;

// 专辑id和歌曲id小于0说明没有专辑、歌曲,并抛出异常

if (albumid < 0 && songid < 0) {

throw new IllegalArgumentException(

"Must specify an album or a song id");

}

try {

if (albumid < 0) {

Uri uri = Uriparse("content://media/external/audio/media/"

+ songid + "/albumart");

ParcelFileDescriptor pfd = contextgetContentResolver()

openFileDescriptor(uri, "r");

if (pfd != null) {

FileDescriptor fd = pfdgetFileDescriptor();

bm = BitmapFactorydecodeFileDescriptor(fd);

}

} else {

Uri uri = ContentUriswithAppendedId(sArtworkUri, albumid);

ParcelFileDescriptor pfd = contextgetContentResolver()

openFileDescriptor(uri, "r");

if (pfd != null) {

FileDescriptor fd = pfdgetFileDescriptor();

bm = BitmapFactorydecodeFileDescriptor(fd);

} else {

return null;

}

}

} catch (FileNotFoundException ex) {

}

return bm;

}

另一种:

// 查找sdcard卡上的所有歌曲信息

public List> getMultiData() {

ArrayList> musicList = new ArrayList>();

// 加入封装音乐信息的代码

// 查询所有歌曲

ContentResolver musicResolver = thisgetContentResolver();

Cursor musicCursor = musicResolverquery(

MediaStoreAudioMediaEXTERNAL_CONTENT_URI, null, null, null,

null);

int musicColumnIndex;

if (null != musicCursor && musicCursorgetCount() > 0) {

for (musicCursormoveToFirst(); !musicCursorisAfterLast(); musicCursor

moveToNext()) {

Map musicDataMap = new HashMap();

Random random = new Random();

int musicRating = Mathabs(randomnextInt()) % 10;

musicDataMapput("musicRating", musicRating);

// 取得音乐播放路径

musicColumnIndex = musicCursor

getColumnIndex(MediaStoreAudioAudioColumnsDATA);

musicPath = musicCursorgetString(musicColumnIndex);

musicDataMapput("musicPath", musicPath);

// 取得音乐的名字

musicColumnIndex = musicCursor

getColumnIndex(MediaStoreAudioAudioColumnsTITLE);

musicName = musicCursorgetString(musicColumnIndex);

musicDataMapput("musicName", musicName);

// 取得音乐的专辑名称

musicColumnIndex = musicCursor

getColumnIndex(MediaStoreAudioAudioColumnsALBUM);

musicAlbum = musicCursorgetString(musicColumnIndex);

musicDataMapput("musicAlbum", musicAlbum);

// 取得音乐的演唱者

musicColumnIndex = musicCursor

getColumnIndex(MediaStoreAudioAudioColumnsARTIST);

musicArtist = musicCursorgetString(musicColumnIndex);

musicDataMapput("musicArtist", musicArtist);

// 取得歌曲对应的专辑对应的Key

musicColumnIndex = musicCursor

getColumnIndex(MediaStoreAudioAudioColumnsALBUM_KEY);

musicAlbumKey = musicCursorgetString(musicColumnIndex);

String[] argArr = { musicAlbumKey };

ContentResolver albumResolver = thisgetContentResolver();

Cursor albumCursor = albumResolverquery(

MediaStoreAudioAlbumsEXTERNAL_CONTENT_URI, null,

MediaStoreAudioAudioColumnsALBUM_KEY + " = ",

argArr, null);

if (null != albumCursor && albumCursorgetCount() > 0) {

albumCursormoveToFirst();

int albumArtIndex = albumCursor

getColumnIndex(MediaStoreAudioAlbumColumnsALBUM_ART);

musicAlbumArtPath = albumCursorgetString(albumArtIndex);

if (null != musicAlbumArtPath

&& !""equals(musicAlbumArtPath)) {

musicDataMapput("musicAlbumImage", musicAlbumArtPath);

} else {

musicDataMapput("musicAlbumImage",

"file:///mnt/sdcard/albjpg");

}

} else {

// 没有专辑定义,给默认

musicDataMapput("musicAlbumImage",

"file:///mnt/sdcard/albjpg");

}

musicListadd(musicDataMap);

}

}

return musicList;

}

1、实现原理:用户打开相册或相机选择相片后,相片经过压缩并设置在控件上,在本地sd卡存一份(如果有的话,没有则内部存储,所以还

需要判断用户是否挂载了sd卡),然后在服务器上存储一份该,当下次再次启动应用时,会默认去sd卡加载该,如果本地没有,再会去联网请求

2、使用了picasso框架以及自定义BitmapUtils工具类

3、记得加上相关权限

<uses-permission android:name="androidpermissionINTERNET"></uses-permission>

<uses-permission android:name="androidpermissionCAMERA"/>

<uses-permission android:name="androidpermissionWRITE_EXTERNAL_STORAGE"></uses-permission>

/

public class MainActivity extends AppCompatActivity implements ViewOnClickListener {

private ImageView iv;//要设置的头像

private Button btn_photo;//调用相册按钮

private Button btn_camera;//调用相机按钮

@Override

protected void onCreate(Bundle savedInstanceState) {

superonCreate(savedInstanceState);

setContentView(Rlayoutactivity_main);

iv=(ImageView) findViewById(Ridiv);

btn_photo = (Button) findViewById(Ridbtn_photo);

btn_camera = (Button) findViewById(Ridbtn_camera);

btn_photosetOnClickListener(this);

btn_camerasetOnClickListener(this);

}

@Override

public void onClick(View v) {

switch (vgetId()) {

case Ridbtn_photo://打开系统相册

Intent intent=new Intent(IntentACTION_PICK, MediaStoreImagesMediaEXTERNAL_CONTENT_URI);

startActivityForResult(intent,100);

break;

case Ridbtn_camera://打开系统相机

Intent intent2=new Intent(MediaStoreACTION_IMAGE_CAPTURE);

startActivityForResult(intent2,200);

break;

}

}

@RequiresApi(api = BuildVERSION_CODESKITKAT)

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

superonActivityResult(requestCode, resultCode, data);

if(requestCode==100&&resultCode==RESULT_OK&&data!=null){//系统相册

Uri imageData = datagetData();

String path=getPath(imageData);

Bitmap bitmap = BitmapFactorydecodeFile(path);

Bitmap bitmap1 = BitmapUtilszoom(bitmap, ivgetWidth(), ivgetHeight());

Bitmap bitmap2 = BitmapUtilscircleBitmap(bitmap1);

//加载显示

ivsetImageBitmap(bitmap2);

//bitmap上传到服务器

//bitmap保存到本地

saveImage(bitmap2);

}else if(requestCode==200&&resultCode==RESULT_OK&&data!=null){//系统相机

Bitmap bitmap = (Bitmap) datagetExtras()get("data");

BitmapUtilszoom(bitmap,ivgetWidth(),ivgetHeight());

bitmap=BitmapUtilscircleBitmap(bitmap);

//加载显示

ivsetImageBitmap(bitmap);

//bitmap上传到服务器

//bitmap保存到本地

saveImage(bitmap);

}

}

/

数据的存储。(5种)

Bimap:内存层面的对象。

存储--->内存:

BitmapFactorydecodeFile(String filePath);

BitmapFactorydecodeStream(InputStream is);

内存--->存储:

bitmapcompress(BitmapCompressFormatPNG,100,OutputStream os);

/

private void saveImage(Bitmap bitmap) {

File filesDir;

if(EnvironmentgetExternalStorageState()equals(EnvironmentMEDIA_MOUNTED)){//判断sd卡是否挂载

//路径1:storage/sdcard/Android/data/包名/files

filesDir = thisgetExternalFilesDir("");

}else{//手机内部存储

//路径:data/data/包名/files

filesDir = thisgetFilesDir();

}

FileOutputStream fos = null;

try {

File file = new File(filesDir,"iconpng");

fos = new FileOutputStream(file);

bitmapcompress(BitmapCompressFormatPNG, 100,fos);

} catch (FileNotFoundException e) {

eprintStackTrace();

}finally{

if(fos != null){

try {

fosclose();

} catch (IOException e) {

eprintStackTrace();

}

}

}

}

//如果本地有,就不需要再去联网去请求

private boolean readImage() {

File filesDir;

if(EnvironmentgetExternalStorageState()equals(EnvironmentMEDIA_MOUNTED)){//判断sd卡是否挂载

//路径1:storage/sdcard/Android/data/包名/files

filesDir = getExternalFilesDir("");

}else{//手机内部存储

//路径:data/data/包名/files

filesDir = getFilesDir();

}

File file = new File(filesDir,"iconpng");

if(fileexists()){

//存储--->内存

Bitmap bitmap = BitmapFactorydecodeFile(filegetAbsolutePath());

ivsetImageBitmap(bitmap);

return true;

}

return false;

}

@RequiresApi(api = BuildVERSION_CODESKITKAT)

private String getPath(Uri uri) {

int sdkVersion = BuildVERSIONSDK_INT;

//高于442的版本

if (sdkVersion >= 19) {

Loge("TAG", "uri auth: " + urigetAuthority());

if (isExternalStorageDocument(uri)) {

String docId = DocumentsContractgetDocumentId(uri);

String[] split = docIdsplit(":");

String type = split[0];

if ("primary"equalsIgnoreCase(type)) {

return EnvironmentgetExternalStorageDirectory() + "/" + split[1];

}

} else if (isDownloadsDocument(uri)) {

final String id = DocumentsContractgetDocumentId(uri);

final Uri contentUri = ContentUriswithAppendedId(Uriparse("content://downloads/public_downloads"),

LongvalueOf(id));

return getDataColumn(this, contentUri, null, null);

} else if (isMediaDocument(uri)) {

final String docId = DocumentsContractgetDocumentId(uri);

final String[] split = docIdsplit(":");

final String type = split[0];

Uri contentUri = null;

if ("image"equals(type)) {

contentUri = MediaStoreImagesMediaEXTERNAL_CONTENT_URI;

} else if ("video"equals(type)) {

contentUri = MediaStoreVideoMediaEXTERNAL_CONTENT_URI;

} else if ("audio"equals(type)) {

contentUri = MediaStoreAudioMediaEXTERNAL_CONTENT_URI;

}

final String selection = "_id=";

final String[] selectionArgs = new String[]{split[1]};

return getDataColumn(this, contentUri, selection, selectionArgs);

} else if (isMedia(uri)) {

String[] proj = {MediaStoreImagesMediaDATA};

Cursor actualimagecursor = thismanagedQuery(uri, proj, null, null, null);

int actual_image_column_index = actualimagecursorgetColumnIndexOrThrow(MediaStoreImagesMediaDATA);

actualimagecursormoveToFirst();

return actualimagecursorgetString(actual_image_column_index);

}

} else if ("content"equalsIgnoreCase(urigetScheme())) {

// Return the remote address

if (isGooglePhotosUri(uri))

return urigetLastPathSegment();

return getDataColumn(this, uri, null, null);

}

// File

else if ("file"equalsIgnoreCase(urigetScheme())) {

return urigetPath();

}

return null;

}

/

uri路径查询字段

@param context

@param uri

@param selection

@param selectionArgs

@return

/

public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {

Cursor cursor = null;

final String column = "_data";

final String[] projection = {column};

try {

cursor = contextgetContentResolver()query(uri, projection, selection, selectionArgs, null);

if (cursor != null && cursormoveToFirst()) {

final int index = cursorgetColumnIndexOrThrow(column);

return cursorgetString(index);

}

} finally {

if (cursor != null)

cursorclose();

}

return null;

}

private boolean isExternalStorageDocument(Uri uri) {

return "comandroidexternalstoragedocuments"equals(urigetAuthority());

}

public static boolean isDownloadsDocument(Uri uri) {

return "comandroidprovidersdownloadsdocuments"equals(urigetAuthority());

}

public static boolean isMediaDocument(Uri uri) {

return "comandroidprovidersmediadocuments"equals(urigetAuthority());

}

public static boolean isMedia(Uri uri) {

return "media"equals(urigetAuthority());

}

/

@param uri The Uri to check

@return Whether the Uri authority is Google Photos

/

public static boolean isGooglePhotosUri(Uri uri) {

return "comgoogleandroidappsphotoscontent"equals(urigetAuthority());

}

/

判断本地是否有该,没有则去联网请求

/

@Override

protected void onResume() {

superonResume();

if(readImage()){

return;

}

}

}

//BitmapUtils工具类public class BitmapUtils { /

该方法用于将进行圆形处理

/ public static Bitmap circleBitmap(Bitmap source){ //默认只对宽进行处理 int width=sourcegetWidth(); Bitmap bitmap=BitmapcreateBitmap(width,width,BitmapConfigARGB_8888); Canvas canvas=new Canvas(bitmap); Paint paint=new Paint(); //设置抗锯齿 paintsetAntiAlias(true); canvasdrawCircle(width/2,width/2,width/2,paint); paintsetXfermode(new PorterDuffXfermode(PorterDuffModeSRC_IN)); canvasdrawBitmap(source,0,0,paint); return bitmap; } / 该方法用于压缩处理,注意width、height参数的类型必须是float / public static Bitmap zoom(Bitmap source,float width,float height){ Matrix matrix=new Matrix(); //进行压缩处理 matrixpostScale(width/sourcegetWidth(),height/sourcegetHeight()); Bitmap bitmap = BitmapcreateBitmap(source, 0, 0, sourcegetWidth(), sourcegetHeight(), matrix, false); return bitmap; }}

以上所述是小编给大家介绍的Android实现调用系统图库与相机设置头像并保存在本地及服务器 ,希望对大家有所帮助

String path = cursorgetString(column_index);改为

String path = cursorgetString(column_index-1);试试

最近做项目要通过的绝对路径找到的URI,然后删除,小小总结一下获取URI的方法,亲自试验在

android 413的系统上都是可用的。

1将所有的路径取出,遍历比较找到需要的路径,取出URI,效率较低

其中 MediaStoreMediaColumnsDATA 字段存的就是的绝对路径,

最后mImageUri得到的就是的URI

1 Uri mUri = Uriparse("content://media/external/images/media");

2 Uri mImageUri = null;

3 Cursor cursor = managedQuery(

4 MediaStoreImagesMediaEXTERNAL_CONTENT_URI, null, null, null,

5 MediaStoreImagesMediaDEFAULT_SORT_ORDER);

6 cursormoveToFirst();

7

8 while (!cursorisAfterLast()) {

9 String data = cursorgetString(cursor

10 getColumnIndex(MediaStoreMediaColumnsDATA));

11 if (picPathequals(data)) {

12 int ringtoneID = cursorgetInt(cursor

13 getColumnIndex(MediaStoreMediaColumns_ID));

14 mImageUri = UriwithAppendedPath(mUri, "" + ringtoneID);

15 break;

16 }

17 cursormoveToNext();

18 }

2直接从媒体数据库根据字段取出相应的记录,效率较高

1 //TYLT: add by duanyf 20121027 start

2 String type = UtilsensureNotNull(intentgetType());

3 Logd(TAG, "uri is " + uri);

4 if (urigetScheme()equals("file") && (typecontains("image/")))

{

5 String path = urigetEncodedPath();

6 Logd(TAG, "path1 is " + path);

7 if (path != null) {

8 path = Uridecode(path);

9 Logd(TAG, "path2 is " + path);

10 ContentResolver cr = thisgetContentResolver();

11 StringBuffer buff = new StringBuffer();

12 buffappend("(")

13 append(ImagesImageColumnsDATA)

14 append("=")

15 append("'" + path + "'")

16 append(")");

17 Cursor cur = crquery(

18 ImagesMediaEXTERNAL_CONTENT_URI,

19 new String[] { ImagesImageColumns_ID },

20 bufftoString(), null, null);

21 int index = 0;

22 for (curmoveToFirst(); !curisAfterLast(); cur

23 moveToNext()) {

24 index = curgetColumnIndex(ImagesImageColumns_ID);

25 // set _id value

26 index = curgetInt(index);

27 }

28 if (index == 0) {

29 //do nothing

30 } else {

31 Uri uri_temp = Uri

32 parse("content://media/external/images/media/"

33 + index);

34 Logd(TAG, "uri_temp is " + uri_temp);

35 if (uri_temp != null) {

36 uri = uri_temp;

37 }

38 }

39 }

40 }

41 //TYLT: add by duanyf 20121027 end

3直接根据路径通过 ContentProvider 的 delete() 方法删除,两行代码搞定,效率最高

1 String params[] = new String[]{filepath};

2

ctxgetContentResolver()delete(MediaStoreImagesMediaEXTERNAL_CONTENT_URI,

MediaStoreImagesMediaDATA + " LIKE ", params);

在Android开发中,我经常会遇到需要获取手机通讯录联系人信息,Android手机的通讯录联系人全部都存在系统的数据库中,如果须要获得通讯里联系人的信息就须要访问系统的数据库,才能将信息获取出来。

下面直接贴出代码供大家参考:

程序文件java代码:

import javaioInputStream;

import javautilArrayList;

import androidappListActivity;

import androidcontentContentResolver;

import androidcontentContentUris;

import androidcontentContext;

import androidcontentIntent;

import androiddatabaseCursor;

import androidgraphicsBitmap;

import androidgraphicsBitmapFactory;

import androidnetUri;

import androidosBundle;

import androidproviderContactsContract;

import androidproviderContactsContractCommonDataKindsPhone;

import androidproviderContactsContractCommonDataKindsPhoto;

import androidtextTextUtils;

import androidviewLayoutInflater;

import androidviewView;

import androidviewViewGroup;

import androidwidgetAdapterView;

import androidwidgetBaseAdapter;

import androidwidgetImageView;

import androidwidgetListView;

import androidwidgetTextView;

import androidwidgetAdapterViewOnItemClickListener;

public class ContactsActivity extends ListActivity {

Context mContext = null;

/获取库Phon表字段/

private static final String[] PHONES_PROJECTION = new String[] {

PhoneDISPLAY_NAME, PhoneNUMBER, PhotoPHOTO_ID,PhoneCONTACT_ID };

/联系人显示名称/

private static final int PHONES_DISPLAY_NAME_INDEX = 0;

/电话号码/

private static final int PHONES_NUMBER_INDEX = 1;

/头像ID/

private static final int PHONES_PHOTO_ID_INDEX = 2;

/联系人的ID/

private static final int PHONES_CONTACT_ID_INDEX = 3;

/联系人名称/

private ArrayList<String> mContactsName = new ArrayList<String>();

/联系人头像/

private ArrayList<String> mContactsNumber = new ArrayList<String>();

/联系人头像/

private ArrayList<Bitmap> mContactsPhonto = new ArrayList<Bitmap>();

ListView mListView = null;

MyListAdapter myAdapter = null;

@Override

public void onCreate(Bundle savedInstanceState) {

mContext = this;

mListView = thisgetListView();

/得到手机通讯录联系人信息/

getPhoneContacts();

myAdapter = new MyListAdapter(this);

setListAdapter(myAdapter);

mListViewsetOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView<> adapterView, View view,

int position, long id) {

//调用系统方法拨打电话

Intent dialIntent = new Intent(IntentACTION_CALL, Uri

parse("tel:" + mContactsNumberget(position)));

startActivity(dialIntent);

}

});

superonCreate(savedInstanceState);

}

/得到手机通讯录联系人信息/

private void getPhoneContacts() {

ContentResolver resolver = mContextgetContentResolver();

// 获取手机联系人

Cursor phoneCursor = resolverquery(PhoneCONTENT_URI,PHONES_PROJECTION, null, null, null);

if (phoneCursor != null) {

while (phoneCursormoveToNext()) {

//得到手机号码

String phoneNumber = phoneCursorgetString(PHONES_NUMBER_INDEX);

//当手机号码为空的或者为空字段 跳过当前循环

if (TextUtilsisEmpty(phoneNumber))

continue;

//得到联系人名称

String contactName = phoneCursorgetString(PHONES_DISPLAY_NAME_INDEX);

//得到联系人ID

Long contactid = phoneCursorgetLong(PHONES_CONTACT_ID_INDEX);

//得到联系人头像ID

Long photoid = phoneCursorgetLong(PHONES_PHOTO_ID_INDEX);

//得到联系人头像Bitamp

Bitmap contactPhoto = null;

//photoid 大于0 表示联系人有头像 如果没有给此人设置头像则给他一个默认的

if(photoid > 0 ) {

Uri uri =ContentUriswithAppendedId(ContactsContractContactsCONTENT_URI,contactid);

InputStream input = ContactsContractContactsopenContactPhotoInputStream(resolver, uri);

contactPhoto = BitmapFactorydecodeStream(input);

}else {

contactPhoto = BitmapFactorydecodeResource(getResources(), Rdrawablecontact_photo);

}

mContactsNameadd(contactName);

mContactsNumberadd(phoneNumber);

mContactsPhontoadd(contactPhoto);

}

phoneCursorclose();

}

}

/得到手机SIM卡联系人人信息/

private void getSIMContacts() {

ContentResolver resolver = mContextgetContentResolver();

// 获取Sims卡联系人

Uri uri = Uriparse("content://icc/adn");

Cursor phoneCursor = resolverquery(uri, PHONES_PROJECTION, null, null,

null);

if (phoneCursor != null) {

while (phoneCursormoveToNext()) {

// 得到手机号码

String phoneNumber = phoneCursorgetString(PHONES_NUMBER_INDEX);

// 当手机号码为空的或者为空字段 跳过当前循环

if (TextUtilsisEmpty(phoneNumber))

continue;

// 得到联系人名称

String contactName = phoneCursor

getString(PHONES_DISPLAY_NAME_INDEX);

//Sim卡中没有联系人头像

mContactsNameadd(contactName);

mContactsNumberadd(phoneNumber);

}

phoneCursorclose();

}

}

class MyListAdapter extends BaseAdapter {

public MyListAdapter(Context context) {

mContext = context;

}

public int getCount() {

//设置绘制数量

return mContactsNamesize();

}

@Override

public boolean areAllItemsEnabled() {

return false;

}

public Object getItem(int position) {

return position;

}

public long getItemId(int position) {

return position;

}

public View getView(int position, View convertView, ViewGroup parent) {

ImageView iamge = null;

TextView title = null;

TextView text = null;

if (convertView == null) {

convertView = LayoutInflaterfrom(mContext)inflate(

Rlayoutcolorlist, null);

iamge = (ImageView) convertViewfindViewById(Ridcolor_image);

title = (TextView) convertViewfindViewById(Ridcolor_title);

text = (TextView) convertViewfindViewById(Ridcolor_text);

}

//绘制联系人名称

titlesetText(mContactsNameget(position));

//绘制联系人号码

textsetText(mContactsNumberget(position));

//绘制联系人头像

iamgesetImageBitmap(mContactsPhontoget(position));

return convertView;

}

}

}

android如何获取联络人所有资讯 获取联络人必须新增许可权

<uses-permission android:name="androidpermissionREAD_CONTACTS" />

如何获取手机联络人资讯

根据ContactsContractContactsCONTENT_URI查询ContentResolver里面的资料,逐个取值即可。

如何获取sim卡的联络人资讯

根据目前查询的资讯来看,sim联络人的uri有两种:

content:i/adn

content:sim/adn

挨个去取即可。

如何获取联络人所有栏位

package ihopemozyhomeutil;import javautilArrayList;import javautilList;import jsonJSONException;import jsonJSONObject;import androidcontentContext;import androiddatabaseCursor;import androidproviderContactsContractCommonDataKindsEmail;import androidproviderContactsContractCommonDataKindsEvent;import androidproviderContactsContractCommonDataKindsIm;import androidproviderContactsContractCommonDataKindsNickname;import androidproviderContactsContractCommonDataKindsNote;import androidproviderContactsContractCommonDataKindsOrganization;import androidproviderContactsContractCommonDataKindsPhone;import androidproviderContactsContractCommonDataKindsStructuredName;import androidproviderContactsContractCommonDataKindsStructuredPostal;import androidproviderContactsContractCommonDataKindsWebsite;import androidproviderContactsContractData;import androidutilLog;import ihopemozyhomedomainContacts;public class GetContactsInfo {private List<Contacts> list;private Context context;private JSONObject contactData;private JSONObject jsonObject;public GetContactsInfo(Context context) { thiscontext = context;}public String getContactInfo() throws JSONException { 获得通讯录资讯 ,URI是ContactsContractContactsCONTENT_URI list = new ArrayList<Contacts>(); contactData = new JSONObject(); String mimetype = ""; int oldrid = -1; int contactId = -1; Cursor cursor = contextgetContentResolver()query(DataCONTENT_URI,null, null, null, DataRAW_CONTACT_ID); int numm=0; while (cursormoveToNext()) { contactId = cursorgetInt(cursorgetColumnIndex(DataRAW_CONTACT_ID)); if (oldrid != contactId) { jsonObject = new JSONObject(); contactDataput("contact" + numm, jsonObject); numm++; oldrid = contactId; } 取得mimetype型别 mimetype = cursorgetString(cursorgetColumnIndex(DataMIMETYPE)); 获得通讯录中每个联络人的ID 获得通讯录中联络人的名字 if (StructuredNameCONTENT_ITEM_TYPEequals(mimetype)) { String display_name = cursorgetString(cursorgetColumnIndex(StructuredNameDISPLAY_NAME)); String prefix = cursorgetString(cursorgetColumnIndex(StructuredNamePREFIX)); jsonObjectput("prefix", prefix); String firstName = cursorgetString(cursorgetColumnIndex(StructuredNameFAMILY_NAME)); jsonObjectput("firstName", firstName); String middleName = cursorgetString(cursorgetColumnIndex(StructuredNameMIDDLE_NAME)); jsonObjectput("middleName", middleName); String lastname = cursorgetString(cursorgetColumnIndex(StructuredNameGIVEN_NAME)); jsonObjectput("lastname", lastname); String suffix = cursorgetString(cursorgetColumnIndex(StructuredNameSUFFIX)); jsonObjectput("suffix", suffix); String phoicFirstName = cursorgetString(cursorgetColumnIndex(StructuredNamePHONETIC_FAMILY_NAME)); jsonObjectput("phoicFirstName", phoicFirstName); String phoicMiddleName = cursorgetString(cursorgetColumnIndex(StructuredNamePHONETIC_MIDDLE_NAME)); jsonObjectput("phoicMiddleName", phoicMiddleName); String phoicLastName = cursorgetString(cursorgetColumnIndex(StructuredNamePHONETIC_GIVEN_NAME)); jsonObjectput("phoicLastName", phoicLastName); } 获取电话资讯 if (PhoneCONTENT_ITEM_TYPEequals(mimetype)) { 取出电话型别 int phoneType = cursorgetInt(cursorgetColumnIndex(PhoneTYPE)); 手机 if (phoneType == PhoneTYPE_MOBILE) { String mobile = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("mobile", mobile); } 住宅电话 if (phoneType == PhoneTYPE_HOME) { String homeNum = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("homeNum", homeNum); } 单位电话 if (phoneType == PhoneTYPE_WORK) { String jobNum = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("jobNum", jobNum); } 单位传真 if (phoneType == PhoneTYPE_FAX_WORK) { String workFax = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("workFax", workFax); } 住宅传真 if (phoneType == PhoneTYPE_FAX_HOME) { String homeFax = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("homeFax", homeFax); } 寻呼机 if (phoneType == PhoneTYPE_PAGER) { String pager = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("pager", pager); } 回拨号码 if (phoneType == PhoneTYPE_CALLBACK) { String quickNum = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("quickNum", quickNum); } 公司总机 if (phoneType == PhoneTYPE_COMPANY_MAIN) { String jobTel = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("jobTel", jobTel); } 车载电话 if (phoneType == PhoneTYPE_CAR) { String carNum = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("carNum", carNum); } ISDN if (phoneType == PhoneTYPE_ISDN) { String isdn = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("isdn", isdn); } 总机 if (phoneType == PhoneTYPE_MAIN) { String tel = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("tel", tel); } 无线装置 if (phoneType == PhoneTYPE_RADIO) { String wirelessDev = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("wirelessDev", wirelessDev); } 电报 if (phoneType == PhoneTYPE_TELEX) { String telegram = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("telegram", telegram); } TTY_TDD if (phoneType == PhoneTYPE_TTY_TDD) { String tty_tdd = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("tty_tdd", tty_tdd); } 单位手机 if (phoneType == PhoneTYPE_WORK_MOBILE) { String jobMobile = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("jobMobile", jobMobile); } 单位寻呼机 if (phoneType == PhoneTYPE_WORK_PAGER) { String jobPager = cursorgetString(cursorgetColumnIndex(PhoneNUMBER)); jsonObjectput("jobPager", jobPager); } 其他通讯地址 if (postalType == StructuredPostalTYPE_OTHER) { String otherStreet = cursorgetString(cursorgetColumnIndex(StructuredPostalSTREET)); jsonObjectput("otherStreet", otherStreet); String otherCity = cursorgetString(cursorgetColumnIndex(StructuredPostalCITY)); jsonObjectput("otherCity", otherCity); String otherBox = cursorgetString(cursorgetColumnIndex(StructuredPostalPOBOX)); jsonObjectput("otherBox", otherBox); String otherArea = cursorgetString(cursorgetColumnIndex(StructuredPostalNEIGHBORHOOD)); jsonObjectput("otherArea", otherArea); String otherState = cursorgetString(cursorgetColumnIndex(StructuredPostalREGION)); jsonObjectput("otherState", otherState); String otherZip = cursorgetString(cursorgetColumnIndex(StructuredPostalPOSTCODE)); jsonObjectput("otherZip", otherZip); String otherCountry = cursorgetString(cursorgetColumnIndex(StructuredPostalCOUNTRY)); jsonObjectput("otherCountry", otherCountry); } } } cursorclose(); Logi("contactData", contactDatatoString()); return contactDatatoString();}}

拍拍贷如何获取联络人

拍拍贷app 可以获取你的通讯录,新浪有借也一样

而且更加好用

它的话是利息按日计,随时还款。

而一般的网贷如借10000,按照目前不低的年化收益率10%来计算的话, 一个月利息是83左右。 计算公式你记一下 10000x10%=1000(这里得出的是一年的收益) 1000/12=83 (除以12个月,才得到你一个月的)

微锁屏获取联络人资讯有风险吗

国内的很多软体都申请了很多不需要的许可权,锁屏软体应该是不需要读取联络人资讯的,可以安装一些软体取消锁屏软体的读取联络人许可权。

android怎么获取联络人头像

必须先编辑成正方形,或你的联络人有自动减取功能,不然头像肯定变形!

手机常显示易信正在尝试获取联络人资讯

这应该是易信在读取你的联络人,以便获取已经用手机号码注册了易信的手机上的联络人,可以考虑解除安装易信(如果不经常用的话)其实很多软体都喜欢读取个人资讯。。

为什么百度HI新增联络人时总是正在获取联络人资讯

应该是网速慢,如果你确定你的网速正常,那有可能是百度系统出错了。

我也遇到过这种情况。

还有一种可能,就是你新增的联络人不存在,或名字输入错误。

什么软体可以汇出联络人所有资讯

360手机卫士、qq都提供了云端备份通讯录的功能。现在备份到云端伺服器上是最安全的,永远不会丢失,换手机前备份一下,新手机上就可以下载到。平日经常备份联络人资讯,安全可靠有保障。

android开发怎样获取通讯录联络人资讯

public class ContactsActivity extends ListActivity {

Context mContext = null;

/获取库Phon表字段/

private static final String[] PHONES_PROJECTION = new String[] {

PhoneDISPLAY_NAME, PhoneNUMBER, PhotoPHOTO_ID,PhoneCONTACT_ID };

/联络人显示名称/

private static final int PHONES_DISPLAY_NAME_INDEX = 0;

/电话号码/

private static final int PHONES_NUMBER_INDEX = 1;

/头像ID/

private static final int PHONES_PHOTO_ID_INDEX = 2;

/联络人的ID/

private static final int PHONES_CONTACT_ID_INDEX = 3;

/联络人名称/

private ArrayList<String> mContactsName = new ArrayList<String>();

/联络人头像/

private ArrayList<String> mContactsNumber = new ArrayList<String>();

/联络人头像/

private ArrayList<Bitmap> mContactsPhonto = new ArrayList<Bitmap>();

ListView mListView = null;

MyListAdapter myAdapter = null;

@Override

public void onCreate(Bundle savedInstanceState) {

mContext = this;

mListView = thisgetListView();

/得到手机通讯录联络人资讯/

getPhoneContacts();

myAdapter = new MyListAdapter(this);

setListAdapter(myAdapter);

mListViewsetOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView<> adapterView, View view,

int position, long id) {

呼叫系统方法拨打电话

Intent dialIntent = new Intent(IntentACTION_CALL, Uri

parse("tel:" + mContactsNumberget(position)));

startActivity(dialIntent);

}

});

superonCreate(savedInstanceState);

}

/得到手机通讯录联络人资讯/

private void getPhoneContacts() {

ContentResolver resolver = mContextgetContentResolver();

获取手机联络人

Cursor phoneCursor = resolverquery(PhoneCONTENT_URI,PHONES_PROJECTION, null, null, null);

if (phoneCursor != null) {

while (phoneCursormoveToNext()) {

得到手机号码

String phoneNumber = phoneCursorgetString(PHONES_NUMBER_INDEX);

当手机号码为空的或者为空栏位 跳过当前回圈

if (TextUtilsisEmpty(phoneNumber))

continue;

得到联络人名称

String contactName = phoneCursorgetString(PHONES_DISPLAY_NAME_INDEX);

得到联络人ID

Long contactid = phoneCursorgetLong(PHONES_CONTACT_ID_INDEX);

得到联络人头像ID

Long photoid = phoneCursorgetLong(PHONES_PHOTO_ID_INDEX);

得到联络人头像Bitamp

Bitmap contactPhoto = null;

photoid 大于0 表示联络人有头像 如果没有给此人设定头像则给他一个预设的

if(photoid > 0 ) {

Uri uri =ContentUriswithAppendedId(ContactsContractContactsCONTENT_URI,contactid);

InputStream input = ContactsContractContactsopenContactPhotoInputStream(resolver, uri);

contactPhoto = BitmapFactorydecodeStream(input);

}else {

contactPhoto = BitmapFactorydecodeResource(getResources(), Rdrawablecontact_photo);

}

mContactsNameadd(contactName);

mContactsNumberadd(phoneNumber);

mContactsPhontoadd(contactPhoto);

}

phoneCursorclose();

}

}

/得到手机SIM卡联络人人资讯/

private void getSIMContacts() {

ContentResolver resolver = mContextgetContentResolver();

获取Sims卡联络人

Uri uri = Uriparse("content:i/adn");

Cursor phoneCursor = resolverquery(uri, PHONES_PROJECTION, null, null,

null);

if (phoneCursor != null) {

while (phoneCursormoveToNext()) {

得到手机号码

String phoneNumber = phoneCursorgetString(PHONES_NUMBER_INDEX);

当手机号码为空的或者为空栏位 跳过当前回圈

if (TextUtilsisEmpty(phoneNumber))

continue;

得到联络人名称

String contactName = phoneCursor

getString(PHONES_DISPLAY_NAME_INDEX);

Sim卡中没有联络人头像

mContactsNameadd(contactName);

mContactsNumberadd(phoneNumber);

}

phoneCursorclose();

}

}

class MyListAdapter extends BaseAdapter {

public MyListAdapter(Context context) {

mContext = context;

}

public int getCount() {

设定绘制数量

return mContactsNamesize();

}

@Override

public boolean areAllItemsEnabled() {

return false;

}

public Object getItem(int position) {

return position;

}

public long getItemId(int position) {

return position;

}

public View getView(int position, View convertView, ViewGroup parent) {

ImageView iamge = null;

TextView title = null;

TextView text = null;

if (convertView == null) {

convertView = LayoutInflaterfrom(mContext)inflate(

Rlayoutcolorlist, null);

iamge = (ImageView) convertViewfindViewById(Ridcolor_image);

title = (TextView) convertViewfindViewById(Ridcolor_title);

text = (TextView) convertViewfindViewById(Ridcolor_text);

}

绘制联络人名称

titlesetText(mContactsNameget(position));

绘制联络人号码

textsetText(mContactsNumberget(position));

绘制联络人头像

iamgesetImageBitmap(mContactsPhontoget(position));

return convertView;

}

}

}

实现思维路径:

以进入相机拍照的思维路线为例子:

1进入app

2判断之前是否保存头像,如果有就显示历史图像 (下面代码中在getOldAvatar();方法中执行这个逻辑)

3点击更换图像的Button或者布局,启动对话框(下面代码中在dialogueBox();方法执行这个逻辑)

4系统版本判断授权方式(静态还是动态授权),判断之前是否已经授权 (setPermissions(Permissions_CAMERA_KEY);这个方法执行授权逻辑)

5如果是首次授权,就执行首次授权完成后马上运行的回调方法 onRequestPermissionsResult

5判断完成不管是否是首次授权还是之前就是授权过了都要执行enterCamera();方法启动相机并且发送携带数据的请求

6启动相机完成后,并且拍照完成退出相机,都要运行Intent返回数据请求回调方法onActivityResult。将传入的数据传入到cropPhoto(datagetData());方法里去执行剪裁。

7在cropPhoto方法里将携带数据跳转到裁剪界面中裁剪,裁剪完成后又要回到onActivityResult回调方法里,执行裁剪完的数据回调工作。

8在onActivityResult回调方法里,裁剪完的将运行setPicToView 方法保存。保存的将在下次启动activity时作为历史头像调用。

package comexamplelenovomydemoapp;

import androidappActivity;

import androidcontentIntent;

import androidcontentpmPackageManager;

import androidgraphicsBitmap;

import androidgraphicsBitmapFactory;

import androidgraphicsdrawableBitmapDrawable;

import androidgraphicsdrawableDrawable;

import androidnetUri;

import androidosBuild;

import androidosEnvironment;

import androidosStrictMode;

import androidproviderMediaStore;

import androidsupportannotationNonNull;

import androidsupportv4appActivityCompat;

import androidsupportv4contentContextCompat;

import androidsupportv7appAlertDialog;

import androidsupportv7appAppCompatActivity;

import androidosBundle;

import androidutilLog;

import androidviewLayoutInflater;

import androidviewView;

import androidwidgetImageView;

import androidwidgetLinearLayout;

import androidwidgetTextView;

import androidwidgetToast;

保存到本地的Lua代码需要经过以下步骤:

1 导入相关库文件

首先需要导入相关库文件,包括cocos2d-x库和io库。这可以通过在代码开头添加以下代码实现:

local FileUtils = ccFileUtils:getInstance()

local io = require("io")

2 获取数据

接下来需要获取需要保存的的数据。这可以通过使用cocos2d-x中的Sprite类来实现:

local sprite = ccSprite:create("imagepng")

local texture2D = sprite:getTexture()

local size = texture2D:getContentSizeInPixels()

local data = texture2D:getData()

3 将数据写入文件

最后一步是将获取到的数据写入文件。这可以通过使用io库中的文件 *** 作函数来实现:

local path = FileUtils:getWritablePath() "imagepng"

local file = ioopen(path, "wb")

file:write(data, size)

file:close()

这段代码会将获取到的数据写入一个名为imagepng的文件中,保存在应用的可写目录下。需要注意的是,在写入文件之前需要先创建一个io文件对象,并且在写入完成之后需要关闭文件对象。

以上就是将保存到本地的Lua代码的详细步骤。

以上就是关于android 怎么获取音乐专辑图像全部的内容,包括:android 怎么获取音乐专辑图像、安卓从手机相册获取照片作为头像缓存地址、安卓开发 获得图片路径失败等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9277797.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存