1
다음 코드로 홈 바로 가기를 만듭니다. 나는 앱이 시작된 인스턴스와 같은 인스턴스 (존재하는 경우)를 가져오고 싶습니다. 새 인스턴스가 아닙니다.Android : 동일한 인스턴스 시작
public void createShortcut() {
if (app.prefs.getBoolean("prefs_ShortcutCreated", false) == false) {
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(this, this.getClass().getName());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "test");
addIntent.putExtra("duplicate", false);
File image = new File(app.DEFAULT_APP_FOLDER_MAIN, "icon.png");
AssetManager assets = app.getApplicationContext().getResources().getAssets();
try {
copy(assets.open("icon.png"), image);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap theBitmap = BitmapFactory.decodeFile(app.DEFAULT_APP_FOLDER_MAIN + "icon.png");
Bitmap scaledBitmap = Bitmap.createScaledBitmap(theBitmap, 128, 128, true);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, scaledBitmap);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(addIntent);
theBitmap.recycle();
scaledBitmap.recycle();
Editor editor = app.prefs.edit();
editor.putBoolean("prefs_ShortcutCreated", true);
editor.commit();
}
}
도움 주세페? 내 대답이 충분하지 않은 경우 더 자세하게 게시 할 수 있습니다. – OceanLife
방금 너무 늦게 대답을 읽었습니다. 고마워요. – Giuseppe