2016-07-18 6 views
0

私はリアルタイムのデータをAWSに送るためにアンドロイドクライアントの使用を学び始めます。私はキネシスを使用してデータを送信します。しかし、サンプルコードは見つかりませんでした。私はAWSチュートリアルから私の理解に基づいてコードを書こうとしています(http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/getting-started-kinesis.html)。しかし、まだ2つの問題があります。1. context.getCachedDir()にエラーがあります。コンテキストを設定する方法がわかりません(スマートフォン上のdirまたはAWS上のdir?)2. protected Void doInBackground(Void ... v)return文がありません。アンドロイドはAWSにデータを送信します

は、問題を把握するための任意の提案はありますか?THX

public class MainActivity extends AppCompatActivity { 

    CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
     getApplicationContext(), // Context 
     "us-east-1:75d540bf-08c8-42fc-87a1-xxxx", // Identity Pool ID 
     Regions.US_EAST_1 // Region 
    ); 


    // working directory for the recorder 
    File directory = context.getCachedDir(); 
    // AWS Firehose region 
    Regions region = Regions.US_WEST_2; 
    // initialize a credentials provider 
    AWSCredentialsProvider provider = new CognitoCachingCredentialsProvider(
     context, 
     "us-east-1:75d540bf-08c8-42fc-87a1-xxxxx", 
     Regions.US_EAST_1); 

    KinesisFirehoseRecorder firehoseRecorder = new KinesisFirehoseRecorder(
     directory, region, provider); 


    // save some strings 
    String streamName = "my_stream"; // Firehose delivery stream name 



    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
        .setAction("Action", null).show(); 
     } 
     }); 



     firehoseRecorder.saveRecord("Hello world!\n", streamName); 
     firehoseRecorder.saveRecord("Streaming data to S3 via Firehose is easy.\n", streamName); 

     // send previously save data to Amazon Firehose 
     // Note: submitAllRecords() makes network calls, so wrap it in an AsyncTask. 

     new AsyncTask<Void, Void, Void>() { 
     @Override 
     protected Void doInBackground(Void... v) { 
      try { 

       firehoseRecorder.submitAllRecords(); 

      } catch (AmazonClientException ace) { 
       // error occurs. 
      } 
     } 
     }.execute(); 


    } 



    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
     return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 


} 

答えて

関連する問題