2012-03-05 18 views
1

私はさまざまな機能を実行できるアプリケーションを持っています。私は自分のAndroid携帯電話のホーム画面で最も頻繁に使用される機能のショートカットを作成したいと考えています。HomeScreenでショートカットを作成

誰でもコードと実際にコードがどのように機能するのか教えてください。どのようにショートカットを作成できますか?私は多くのコード行を見てきましたが、私は理解できません。説明してください。

私は次のコードを使用しました=>主な問題は、ショートカットがホーム画面に作成されていることです。私はようにそれにトースト表示メッセージをクリックすると、しかし、「アプリケーションがお使いの携帯電話にインストールされていない」.ANDは、ログにエラーメッセージがある

1)/ ActivityManager(58)WARN:許可 拒否されました:checkComponentPermissionを()reqUid = 10046 2)WARN/ActivityManager(58):許可の拒否:ProcessRecordからのインテント{act = android.intent.action.VIEW flg = 0x10000000 cmp = aaa/.s bnds = [3,240] [77,319]}の開始ランチャーはインテントを起動する権限を持っていません{act = android.intent.action {44f19b88 123:com.android.launcher/10025}(pid = 123、uid = 10025)にはヌルが必要です 3)エラー/ランチャー(123) .view flg = 0x10000000 cmp = aaa/.s bnds = [3,240] [77,319]}。対応するアクティビティーのMAINインテントフィルターを作成するか、このアクティビティーのエクスポート属性を使用してください。 (4)ERROR/Launcher(123):java(4)エラー/ランチャー(123):java .lang.SecurityException:Permission Denial:ProcessRecord {44f19b88からのインテント{act = android.intent.action.VIEW flg = 0x10000000 cmp = aaa/.s bnds = [3,240] [77,319]} com.android.launcher/10025}(PID = 123、UID = 10025)がAndroidのホーム画面にアプリのショートカットを作成するには、ヌル


`package a.a.a; 

import android.app.Activity; 
    import android.content.Intent; 
    import android.os.Bundle; 

public class ShortActivity extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Intent i=new Intent(this,s.class); 
    Intent j=new Intent(); 
    j.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); 
    j.putExtra(Intent.EXTRA_SHORTCUT_NAME,"Sukumar"); 
    j.putExtra(Intent.EXTRA_SHORTCUT_ICON,R.drawable.icon); 
    j.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
    this.sendBroadcast(j); 


} 


}` 

答えて

0

を必要とし、私たちはただのアクションcom.android.launcher.action.INSTALL_SHORTCUTとシンプルな意思を発射する必要があります。ショートカットの名前とアイコンは、インテントのexrtaパラメータを使用して入力できます。
下記の方法を確認してください:

Intent intent = new Intent(); 
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intentActivity); 
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, textShortcut); 
Parcelable iconResource = (Parcelable) bitmap; 
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, iconResource); 
intent.putExtra("duplicate", duplicateNeed); // (duplicateNeed=false) 
// will not allow the 
// duplicate same name 
// shortcuts. 
intent.setAction(INSTALL_SHORTCUT_ACTION); 
getApplicationContext().sendBroadcast(intent); 
関連する問題