2016-04-06 4 views
0

私はTaskerアプリのAndroidプラグインの作成を始めようとしています。私は 'トースト'の例をダウンロードし、ドキュメントを読むことから始めました。私はまだ模範を演奏していますが、トーストアクションをコメントアウトして、それをアラートダイアログ(これは他の多くのアプリでやったことがあります)を作成するコードに置き換えると、タスク担当者のプラグインは、 。私はAndroid Studioを使用しています。Android Tasker PluginのFireReceiverヘルプ

誰でも知っていますか?私のコードは以下の通りです:

public class FireReceiver extends BroadcastReceiver 
    { 

     /** 
     * @param context {@inheritDoc}. 
     * @param intent the incoming {@link com.twofortyfouram.locale.Intent#ACTION_FIRE_SETTING} Intent. This 
     *   should contain the {@link com.twofortyfouram.locale.Intent#EXTRA_BUNDLE} that was saved by 
     *   {@link EditActivity} and later broadcast by Locale. 
     */ 
     @Override 
     public void onReceive(final Context context, final Intent intent) 
     { 
    /* 
    * Always be strict on input parameters! A malicious third-party app could send a malformed Intent. 
    */ 

      if (!com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) 
      { 
       if (Constants.IS_LOGGABLE) 
       { 
        Log.e(Constants.LOG_TAG, 
          String.format(Locale.US, "Received unexpected Intent action %s", intent.getAction())); //$NON-NLS-1$ 
       } 
       return; 
      } 
    BundleScrubber.scrub(intent); 

    final Bundle bundle = intent.getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE); 
    BundleScrubber.scrub(bundle); 

    if (PluginBundleManager.isBundleValid(bundle)) 
    { 
     final String message = bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE); 
     //Toast.makeText(context, message, Toast.LENGTH_LONG).show(); 

     AlertDialog.Builder builder = new AlertDialog.Builder(context); 

     builder.setMessage("Yes, this worked!") 
       .setIcon(R.drawable.ic_launcher) 
       .setTitle(R.string.dialog_title); 

     builder.setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       // User clicked OK button 
       //Toast.makeText(context, "You clicked yes", Toast.LENGTH_LONG).show(); 
      } 
     }); 
     builder.setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       // User cancelled the dialog 
       //Toast.makeText(getApplicationContext(), "You clicked no", Toast.LENGTH_LONG).show(); 
      } 
     }); 


     AlertDialog dialog = builder.create(); 
     dialog.show(); 

    } 

} 

答えて

0

この問題を抱えている人のために、私は最後に問題を解決しました。基本的にFireReceiverはAlertsなどのようなものを表示することはできませんので、FireReceiverを使用して別のアクティビティを開く必要があります。

これは私のために働いています(私はパッケージ名を変更しましたが、要点は分かります)。 NewActiviyは、FireRecieverを開くためにアクティビティが呼び出されたものです。それで、それと一緒に変数を渡すための私のコードを示します。これはかなり標準的です: