App ကို Install လုပ္နည္း
1.New Project တစ္ခုယူ ...
2. app/src/main ေအာက္မွာ assets ဆိုတဲ့နာမည္နဲ႔ folder တစ္ခုေဆာက္ၿပီး အထဲမွာ စမ္းခ်င္တဲ့ apk တခုထည့္ထားပါ ... ဥပမာ ... astro.apk
3. main.xml ထဲ ဒီကုဒ္ထည့္ပါ ...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:id="@+id/bt"
android:text="Install Apk"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
4. MainActivity.java ထဲ ဒီကုဒ္ထည့္ပါ ...
package com.ktr.inapk;
import android.app.*;
import android.os.*;
import android.content.res.*;
import java.io.*;
import android.content.*;
import android.net.*;
import android.widget.*;
import android.view.View.*;
import android.view.*;
public class MainActivity extends Activity
{
Button bt;
AssetManager aManager;
InputStream in;
OutputStream out;
byte[] buf;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt = (Button)findViewById(R.id.bt);
aManager = getAssets();
in = null;
out = null;
bt.setOnClickListener(new OnClickListener(){
public void onClick(View v){
try {
in = aManager.open("astro.apk");
out = new FileOutputStream("/sdcard/astro.apk");
buf = new byte[1024];
int read;
while((read = in.read(buf)) != -1) {
out.write(buf, 0, read);
}
in.close();
in = null;
out.flush();
out.close();
out = null;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("/sdcard/astro.apk")),
"application/vnd.android.package-archive");
startActivity(intent);
} catch(Exception e) { }//End
}
});
}
}
5. AndroidManifest.xml မွာ ...
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
6. Run ၾကည့္ပါ ...
သေဘာတရား ...
===========
assets Folder ထဲကေန ကိုယ့္ဖုန္းရဲ႕ sdcard ေပၚကူးထုတ္မယ္ ... ၿပီးမွ sdcard ေပၚက apk ဖိုင္ကို Install လုပ္ခြင့္ျပဳပါတယ္ ...
The End 😊
Tags:
Android App Making