Not much to say, directly on the code, this article contains some basic and commonly used jump tools, take a look at it.
First, this is the corresponding permission required.
<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 "/>
Code:
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;
/** * Created by Joy on 2016/7/21. * Tool Collection/public class Mainactivity extends Appcompatactivity {private String mimagepath;//the picture path returned by private final Stati
c 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); /** * Open micro-letter/Findviewbyid (r.id.btn_open_weixin). Setonclicklistener (New View.onclicklistener () {@Override public voi D OnClick (View v) {Intent Intent = GetpAckagemanager (). Getlaunchintentforpackage ("com.tencent.mm");
StartActivity (Intent);
}
}); /** * Jump to the QQ chat interface * * Findviewbyid (R.ID.BTN_OPEN_QQ). Setonclicklistener (New View.onclicklistener () {@Override public vo
ID 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)));
}
}); /** * Jump to contact interface * * Findviewbyid (r.id.btn_people_interface). Setonclicklistener (New View.onclicklistener () {@Override P
ublic void OnClick (View v) {Intent Intent = new Intent ();
Intent.setclassname ("Com.android.contacts", "com.android.contacts.activities.PeopleActivity");
StartActivity (Intent);
}
});
/** * Jump to dial interface/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);
}
}); /** * Direct call/Findviewbyid (R.id.btn_telephone). Setonclicklistener (New View.onclicklistener () {@Override public voi
D OnClick (View v) {String phone = "157*****737";
Intent Intentphone = new Intent (Intent.action_call, Uri.parse ("Tel:" + phone));
StartActivity (Intentphone);
}
}); /** * Jump to SMS Interface * * Findviewbyid (r.id.btn_message_interface). Setonclicklistener (New View.onclicklistener () {@Override P
ublic void OnClick (View v) {Intent Intent = new Intent (Intent.action_view);
Intent.settype ("vnd.android-dir/mms-sms");
StartActivity (Intent);
}
});
/** * Jump to SMS Interface * Specify number and SMS content/Findviewbyid (r.id.btn_message). Setonclicklistener (New View.onclicklistener () {@Override
public void OnClick (View v) {String phone = "157*****737";
String message = "This is a custom content";
Intent Intent = new Intent (intent.action_sendto, Uri.parse ("Smsto:" + phone));
Intent.putextra ("Sms_body", message); StartActivity (intent);
}
}); /** * Jump to the Settings interface * * Findviewbyid (r.id.btn_setting_interface). Setonclicklistener (New View.onclicklistener () {@Override P
ublic void OnClick (View v) {Intent Intent = new Intent (settings.action_settings);
StartActivity (Intent);
}
});
/** * Jump to Bluetooth interface * * 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);
}
}); /** * Call Browser/Findviewbyid (r.id.btn_browser). Setonclicklistener (New View.onclicklistener () {@Override public void O
Nclick (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);
}
}); /** * Open Camera/Findviewbyid (R.id.btn_camera). Setonclicklistener (New View.onclicklistener () {@Override public void on Click (View v) {Mimagepath = Chooseimagefromcamera (Mainactivity.this, Request_code_camera, "cameraimage");
}
}); /** * Open Album and get picture Address * * 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/*");
Startactivityforresult (Intent, request_code_gallery);
}
}); public string Chooseimagefromcamera (activity activity, int requestcode, String imagename) {Intent cameraintent = NE
W Intent (Android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File File = new file (environment.getexternalstoragedirectory () + "/images");
if (!file.exists ()) {file.mkdirs (); String Savepath = environment.getexternalstoragedirectory () + "/images/" + imagename + string.valueof (System.currentTi
Memillis ()) + ". jpg";
Uri MUri = uri.fromfile (new File (Savepath));
Cameraintent.putextra (Android.provider.MediaStore.EXTRA_OUTPUT, MUri); Cameraintent.putextra ("Return-data", true);
Activity.startactivityforresult (Cameraintent, Requestcode);
return savepath; Public String onactivityresultforchooseimagefromgallery (context context, int requestcode, int resultcode, Intent da
TA) {String imagepath = null; if (data!= null) {if ("File". Equals (Data.getdata (). Getscheme ())} {/** Some lower-version models return a URI pattern of file*/ImagePath = Data.getdat
A (). 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.onactivityresu
Lt (Requestcode, ResultCode, data); Switch (Requestcode) {Case Request_code_gallery:mimagepath = Onactivityresultforchooseimagefromgallery (Mainactivity.this, RequestCode, R
Esultcode, data); if (Mimagepath!= null && mimagepath.length () > 0) {toast.maketext (Mainactivity.this, Mimagepath, Toast.lengt
H_short). Show ();
} break; Case Request_code_camera:if (mimagepath!= null && mimagepath.length () > 0) {toast.maketext (mainactivity.th
is, Mimagepath, Toast.length_short). Show ();
} break; }
}
}
Summarize
Summary android (Android) commonly used in the jump tool to this end, this article collation of these jump tool classes are very common, so is the most practical, I hope this article on the day-to-day development of Android can help.