Archive for Desember 2017
import android.app.*;
import android.os.*;
import android.widget.*;
import android.content.*;
import android.view.*;
import android.net.wifi.*;
import android.text.format.*;
{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
UNTUK TAMPILAN XML SILAHKAN SESUAIKAN SAJA SESUAI KEBUTUHAN :D
*/
btnOnWifi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);}});
/*PILIH TRUE ATAU FALSE UNTUK ON OFF*/
final TextView textView = (TextView)findViewById(R.id.text);
Button btnInfoNetwork = (Button)findViewById(R.id.info);
btnInfoNetwork.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifi.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
String macAddress = wifiInfo.getMacAddress();
String bssid = wifiInfo.getBSSID();
int rssi = wifiInfo.getRssi();
int linkSpeed = wifiInfo.getLinkSpeed();
String ssid = wifiInfo.getSSID();
int idjaringan = wifiInfo.getNetworkId();
String ipAddress = Formatter.formatIpAddress(ip);
String info = "Ip Address sobat:"+ipAddress +"\n"+"Mac Address: "+macAddress +"\n"+ "BSSID: "+bssid
+"\n"+"RSSI: "+rssi+"\n"+ "Link Speed: "+linkSpeed + "\n" + "SSID:" +ssid+"\n"+"id Jaringan:" +idjaringan;
textView.setText(info);
}
});}}
[DROID] On Off Dan Status Wifi
-MainActivity.java
-main.xml
-AndroidManifest.xml
Sesuaikan id nya dengan nama id di file MainActivity.java
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webViewApp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
web.getSettings().setJavaScriptEnabled(true);
web.setWebViewClient(new WebViewClient(){
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
});
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
[DROID] webview
import android.content.*;
import android.os.*;
import android.widget.*;
public class MainActivity extends Activity {
private static int
SPLASH_TIME_OUT = 7000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Handler().postDelayed(new Runnable() {
@Override public
void run() { Intent i = new Intent
(MainActivity.this, activity2.class);
startActivity(i); // tutup
finish(); } },
SPLASH_TIME_OUT);
}
}
[DROID] Splash Time (halaman berwaktu)
import android.content.Intent;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.app.*;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);{
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,SimpanData.class);
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
* Created by Riyan on 5/4/2017.
*/
public static final String NAMA_TABLE = "Programmer_table";
public static final String COL_2 = "NAMA";
public static final String COL_3 = "ALAMAT";
public static final String COL_4 = "NO_CELANA";
super(context, NAMA_DATABASE, null, 1);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + NAMA_TABLE + " (ID INTEGER PRIMARY KEY AUTOINCREMENT , NAMA TEXT, ALAMAT TEXT, NO_CELANA INTEGER)");
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + NAMA_TABLE);
}
public Cursor getSemuaData() {
SQLiteDatabase database = this.getWritableDatabase();
//panggil dengan perintah (Select * from + nama tabelnya apa)
Cursor res = database.rawQuery("Select * from " + NAMA_TABLE, null);
return res;
}
public boolean insertData(String nama, String alamat, String no_celana) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2, nama);
contentValues.put(COL_3, alamat);
contentValues.put(COL_4, no_celana);
long hasil = db.insert(NAMA_TABLE, null, contentValues);
db.close();
if (hasil == -1 ) {
return false;
} else {
return true;
}
}
public boolean updateData(String id, String nama, String alamat, String no_celana) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2, nama);
contentValues.put(COL_3, alamat);
contentValues.put(COL_4, no_celana);
int hasil = db.update(NAMA_TABLE, contentValues, "ID=?",new String [] {id});
db.close();
if (hasil > 0) {
return true;
} else {
return false;
}
}
//metode untuk menghapus dengan cukup memanggil nomor ID nya saja.
public Integer hapusData(String id) {
SQLiteDatabase database = this.getWritableDatabase();
int kasian_dech_lu = database.delete(NAMA_TABLE, "ID=?", new String [] {id});
return kasian_dech_lu ;
}
import android.content.DialogInterface;
import android.database.Cursor;
import android.app.AlertDialog;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.mycompany.myapp.R;
import android.content.*;
DATABASE dbSaya;
EditText edtTeksNama, edtTeksAlamat, edtTeksNoCelana;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simpan);
edtTeksAlamat = (EditText) findViewById(R.id.alamat);
edtTeksNoCelana = (EditText) findViewById(R.id.umur);
final Button btnMasukkan = (Button) findViewById(R.id.simpan);
btnMasukkan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbSaya = new DATABASE(SimpanData.this);
String alamat = edtTeksAlamat.getText().toString();
String no_celana = edtTeksNoCelana.getText().toString();
Boolean hasil = dbSaya.insertData(nama, alamat, no_celana);
if (hasil == true) {
Toast.makeText(getBaseContext(), "Data berhasil di input", Toast.LENGTH_SHORT).show();
} else if (hasil == false ) {
Toast.makeText(getBaseContext(), "Data gagal di input", Toast.LENGTH_SHORT).show();
}
}
});
public void onClick(View v) {
Intent intent = new Intent(SimpanData.this,TampilkanData.class);
Button btnCall2 = (Button) findViewById(R.id.delete);
public void onClick(View v) {
Intent intent = new Intent(SimpanData.this,HapusData.class);
import android.content.DialogInterface;
import android.database.Cursor;
import android.app.AlertDialog;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.mycompany.myapp.R;
DATABASE dbSaya;
EditText edtTeksNama, edtTeksAlamat, edtTeksNoCelana;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tampil);
btnTampilkanDataSql.setOnClickListener(new View.OnClickListener() {
@Override
btnMunculHadirkan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbSaya = new DATABASE(TampilkanData.this);
StringBuffer stringBuffer = new StringBuffer();
if (res != null && res.getCount() > 0) {
while (res.moveToNext()) {
stringBuffer.append("ID: " + res.getString(0) + "\n");
stringBuffer.append("Nama: " + res.getString(1) + "\n");
stringBuffer.append("Alamat: " + res.getString(2) + "\n");
stringBuffer.append("No Celana: " + res.getString(3) + "\n" + "\n");
}
textViewHadir.setText(stringBuffer.toString());
Toast.makeText(getBaseContext(), "Data ada", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getBaseContext(), "Data tidak ada", Toast.LENGTH_SHORT).show();
}
}
});
}
}
import android.content.DialogInterface;
import android.database.Cursor;
import android.app.AlertDialog;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.mycompany.myapp.R;
DATABASE dbSaya;
EditText edtTeksNama, edtTeksAlamat, edtTeksNoCelana;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hapus);
btnHilangkan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {*/
btnHilangkan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbSaya = new DATABASE(HapusData.this);
int hasil = dbSaya.hapusData(id);
}
});
};}
<manifest xmlns:android="http://
schemas.android.com/apk/res/android"
package="com.mycompany.myapp" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SimpanData"
android:label="@string/app_name" >
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TampilkanData"
android:label="@string/app_name" >
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.LAUNCHER" />
</activity>
<activity
android:name=".HapusData"
android:label="@string/app_name" >
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.LAUNCHER" />
</activity>
</application>
</manifest>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="simpan"
android:id="@+id/button1"
android:layout_gravity="center_horizontal"
android:layout_marginTop="200dp"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#A5A5A5">
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ems="10"
android:id="@+id/nama"
android:layout_gravity="center_horizontal"
android:layout_marginTop="47dp"
android:hint="Name"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ems="10"
android:id="@+id/alamat"
android:layout_gravity="center_horizontal"
android:hint="Adress"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ems="10"
android:id="@+id/umur"
android:layout_gravity="center_horizontal"
android:hint="Years Old"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Save"
android:id="@+id/simpan"
android:layout_gravity="center_horizontal"
android:background="#72FF00"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="View Data"
android:layout_gravity="center_horizontal"
android:background="#002AFF"
android:id="@+id/view"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Delete Data"
android:layout_gravity="center_horizontal"
android:background="#FF0F00"
android:id="@+id/delete"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
android:layout_height="match_parent"
android:layout_width="match_parent">
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button"
android:layout_gravity="center_horizontal"
android:id="@+id/lihat"/>
android:layout_height="wrap_content"
android:layout_width="300dip"
android:ems="10"
android:id="@+id/tampil"
android:layout_gravity="center_horizontal"
android:textSize="15sp"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ems="10"
android:id="@+id/tulis"
android:layout_gravity="center_horizontal"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button"
android:id="@+id/hapus"
android:layout_gravity="center_horizontal"/>
[DROID] CRUD and Database Java
import android.os.*;
import android.widget.*;
import android.view.View.*;
import android.view.*;
{
EditText edittext,edittext2;
TextView textview;
Button btn;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edittext=(EditText)findViewById(R.id.edit);
edittext2=(EditText)findViewById(R.id.edit2);
btn=(Button)findViewById(R.id.tombol);
btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
int a,b,c;
a=Integer.valueOf(edittext.getText().toString());
b=Integer.valueOf(edittext2.getText().toString());
c=a+b;
textview.setText(String.valueOf(c));}});}}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ems="10"
android:id="@+id/edit2"
android:inputType="number"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ems="10"
android:id="@+id/edit"
android:inputType="number"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button"
android:id="@+id/tombol"/>
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:id="@+id/tampil"/>
[DROID] penjumlahan Antar Nilai EditText Di Tampilkan Ke textView
import android.os.*;
import android.widget.*;
import android.view.View.*;
import android.view.*;
{
EditText edittext;
TextView textview;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edittext=(EditText)findViewById(R.id.edit);
btn=(Button)findViewById(R.id.tombol);
btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
String name =edittext.getText().toString();
textview.setText(name);}});}}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ems="10"
android:id="@+id/edit"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button"
android:id="@+id/tombol"/>
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:id="@+id/tampil"/>
[DROID] Menampilkan editText di TextView
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.app.Activity;
import java.util.zip.*;
import android.media.*;
import android.content.*;
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceStat);
setContentView(R.layout.main);
Button btShow = (Button) findViewById(R.id.tiga);
btShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.dialog);//layout yang akan di tampilkan di dialog
ImageView image=(ImageView)findViewById(R.id.c); //id ImageView yang ada di layout dialog
Button dialogButton = (Button) dialog.findViewById(R.id.b);//ini sama halnya imageViewdialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { //dan ini adalah tombol intent
Intent intent = new Intent (MainActivity.this,Activity2.class);
startActivity(intent);
}
});
}
});
}
}
[DROID] Dialog
android:layout_width ="fill_parent"
android:layout_height = "wrap_content"
layout = "@layout/yourlayout" />
Dan ganti "@layout/yourlayout" dengan nama layout 2
[DROID] Include
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
MediaPlayer audioBackground;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
audioBackground = MediaPlayer.create(this, R.raw.naruto);
//Set looping ke true untuk mengulang audio jika telah selesai
audioBackground.setLooping(true);
//Set volume audio agar berbunyi
audioBackground.setVolume(1,1);
//Memulai audio
audioBackground.start();
}
[DROID] Menambahkan audio di background layout
res - raw
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
/** Called when the activity is first created. */
private Button btnPause;
private Button btnStop;
private MediaPlayer mp;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnPause = (Button) findViewById(R.id.btnPAUSE);
btnStop = (Button) findViewById(R.id.btnSTOP);
@Override
public void onClick(View v) {
play();
btnPlay.setEnabled(false);
btnPause.setEnabled(true);
btnStop.setEnabled(true);
}
});
@Override
public void onClick(View v) {
pause();
}
});
@Override
public void onClick(View v) {
stop();
}
});
}
public void stateAwal(){
btnPlay.setEnabled(true);
btnPause.setEnabled(false);
btnStop.setEnabled(false);
}
private void play() {
/** Memanggil File MP3 "indonesiaraya.mp3" */
mp = MediaPlayer.create(this, R.raw.gara);
mp.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
stateAwal();
}
});
}
public void pause(){
if(mp.isPlaying()){
if(mp!=null){
mp.pause();
} else {
if(mp!=null){
mp.start();
}
}
public void stop(){
mp.stop();
mp.prepare();
mp.seekTo(0);
}catch (Throwable t) {
t.printStackTrace();
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Lagu Indonesia Raya"
android:id="@+id/textView"
android:layout_marginTop="59dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PLAY"
android:id="@+id/btnPLAY"
android:layout_marginTop="102dp"
android:layout_below="@+id/textView"
android:layout_toLeftOf="@+id/btnPAUSE"
android:layout_toStartOf="@+id/btnPAUSE"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="STOP"
android:id="@+id/btnSTOP"
android:layout_alignTop="@+id/btnPAUSE"
android:layout_toRightOf="@+id/btnPAUSE"
android:layout_toEndOf="@+id/btnPAUSE"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PAUSE"
android:id="@+id/btnPAUSE"
android:layout_alignTop="@+id/btnPLAY"
android:layout_centerHorizontal="true"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="by okedroid.com"
android:id="@+id/textView2"
android:layout_marginBottom="106dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
[DROID] Cara menambahkan Audio di aplikasi
Cara pindah Layout Dengan Intent yaitu dengan menyetel 2 file
-ActivityMain.java
-AndroidManifest.xml
Pertama Buat File
ActivityMain.java
Isikan Kode ini
package com.mycompany.myapp;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.mycompany.myapp.R;
import android.app.*;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);{
//EditText
Button btnCall = (Button) findViewById(R.id.button1);
//ketika menekan tombol call
btnCall.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,Activity2.class);
startActivity(intent);}});}}}
Activity2.java
Isikan kode ini
package com.mycompany.myapp;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.mycompany.myapp.R;
import android.app.*;
public class Activity2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maindua);{
//EditText
Button btnCall = (Button) findViewById(R.id.button1);
//ketika menekan tombol call
btnCall.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Activity2.this,MainActivity.class);
startActivity(intent);}});}}}
AndroidManifest.xml
Isikan Kode Ini
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp" >
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Untuk tampilannya sesuakan saja dengan Id tombol yang ada di file java
Untuk AndroidManifest di bagian android:name
Isikan dengan nama file Java
[DROID] Intent Explicit (berpindah halaman)
import android.os.Bundle;
import android.view.Window;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.melki.droid" >
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
[DROID] Cara Delete Title Bar Di android
AndroidManifest.xml file.
android:name="android.permission.INTERNET"/>
org.apache.http.HttpResponce cannot resolved
error solution then read my this tutorial for solve
this problem.
Code for MainActivity.java file.
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import
org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import
org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import
org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
EditText editTextName, editTextEmail,
editTextWebsite;
String GetName, GetEmail, GetWebsite;
Button buttonSubmit ;
String DataParseUrl = "http://web-anda.com/
insert_data.php";
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextName = (EditText)findViewById
(R.id.editText1);
editTextEmail = (EditText)findViewById
(R.id.editText2);
editTextWebsite = (EditText)findViewById
(R.id.editText3);
buttonSubmit = (Button)findViewById(R.id.button1);
buttonSubmit.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
GetDataFromEditText();
SendDataToServer(GetName, GetEmail, GetWebsite)
;
}
});
}
public void GetDataFromEditText(){
GetName = editTextName.getText().toString();
GetEmail = editTextEmail.getText().toString();
GetWebsite = editTextWebsite.getText().toString();
}
public void SendDataToServer(final String name,
final String email, final String website){
class SendPostReqAsyncTask extends
AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String QuickName = name ;
String QuickEmail = email ;
String QuickWebsite = website;
List<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair
("name", QuickName));
nameValuePairs.add(new BasicNameValuePair
("email", QuickEmail));
nameValuePairs.add(new BasicNameValuePair
("website", QuickWebsite));
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(DataParseUrl);
httpPost.setEntity(new UrlEncodedFormEntity
(nameValuePairs));
HttpResponse response = httpClient.execute
(httpPost);
HttpEntity entity = response.getEntity();
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return "Data Submit Successfully";
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Toast.makeText(MainActivity.this, "Data Submit
Successfully", Toast.LENGTH_LONG).show();
}
}
SendPostReqAsyncTask sendPostReqAsyncTask =
new SendPostReqAsyncTask();
sendPostReqAsyncTask.execute(name, email,
website);
}
}
Code for activity_main.xml layout file.
<RelativeLayout xmlns:android="http://
schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_
margin"
android:paddingLeft="@dimen/activity_horizontal_
margin"
android:paddingRight="@dimen/activity_horizontal_
margin"
android:paddingTop="@dimen/activity_vertical_
margin"
tools:context="com.submitandroiddata2server_
android_examples.com.MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:ems="10"
android:hint="Enter Your Name" >
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:ems="10"
android:hint="Enter Your Email" />
<EditText
android:id="@+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:ems="10"
android:hint="Enter Your Website" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Submit Data To Server" />
</RelativeLayout>
<manifest xmlns:android="http://
schemas.android.com/apk/res/android"
package="com.submitandroiddata2server_android_
examples.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission
android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" /
>
</intent-filter>
</activity>
</application>
</manifest>
//This script is designed by Android-Examples.com
//Define your host here.
$hostname = "mysql.hostinger.in";
//Define your database username here.
$username = "u727224026_demo";
//Define your database password here.
$password = "1234567890";
//Define your database name here.
$dbname = "u727224026_demo";
$con = mysqli_connect($hostname,$username,$
password,$dbname);
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$Sql_Query = "insert into GetDataTable
(name,email,website) values ('$name','$email','$
website')";
if(mysqli_query($con,$Sql_Query)){
echo 'Data Inserted Successfully';
}
else{
echo 'Try Again';
}
mysqli_close($con);
?>