2013-11-03 3 views
1

현재 이미지를 공유해야하는 앱을 만들고 있습니다. XML을 완료하고 공유 단추가 나타나지만 클릭 할 수 없습니다. 나는 메뉴 팽창 곳작업 표시 줄에 공유 버튼이 있습니까?

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:id="@+id/menu_item_scan" 
      android:icon="@drawable/scanlogo" 
      android:showAsAction="ifRoom" 
      android:title="Scan" /> 
    <item android:id="@+id/menu_item_share" 
      android:showAsAction="ifRoom" 
      android:title="Share" 
      android:actionProviderClass="android.widget.ShareActionProvider" /> 
</menu> 

이는 다음과 같습니다 :

다음은 XML에있는 버튼에 대한 내 코드입니다

public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.action_bar_share_menu, menu); 
    return true; 
} 

이 모든 일을하고 나타나 있지만 클릭 할 수 없습니다. 클릭 가능하도록 시도하는 부분은 다음과 같습니다.

public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle presses on the action bar items 
     switch (item.getItemId()) { 
      case R.id.menu_item_share: 
       Intent ShareIntent = new Intent(); 
       String pathofBmp = MediaStore.Images.Media.insertImage(getContentResolver(), QRMap,"QRCode", null); 
       Uri bmpUri = Uri.parse(pathofBmp); 
       ShareIntent.setAction(Intent.ACTION_SEND); 
       ShareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); 


    ShareIntent.setType("image/png"); 
      mShareActionProvider.setShareIntent(ShareIntent); 
      return true; 

     default: 
      return super.onOptionsItemSelected(item); 
    } 
} 

어떤 도움을 주실 수 있나요?

답변

1

onOptionsItemSelected() 방법의 R.id.menu_item_share 사례를 삭제하십시오. 해당 코드를 onCreateOptionsMenu()과 같이 앱의 다른 곳으로 이동하여 ShareActionProvider이 표시되기 전에 구성하십시오.

예를 들어, 여기 one of my sample projects에서 ShareActionProvider를 구성 활동 :이 ActionBarSherlock의를 사용하는 내 경우에는

/*** 
    Copyright (c) 2012 CommonsWare, LLC 
    Licensed under the Apache License, Version 2.0 (the "License"); you may not 
    use this file except in compliance with the License. You may obtain a copy 
    of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required 
    by applicable law or agreed to in writing, software distributed under the 
    License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
    OF ANY KIND, either express or implied. See the License for the specific 
    language governing permissions and limitations under the License. 

    From _The Busy Coder's Guide to Android Development_ 
    http://commonsware.com/Android 
*/ 

package com.commonsware.android.sap; 

import android.content.Intent; 
import android.os.Bundle; 
import android.text.Editable; 
import android.text.TextWatcher; 
import android.widget.EditText; 
import android.widget.Toast; 
import com.actionbarsherlock.app.SherlockActivity; 
import com.actionbarsherlock.view.Menu; 
import com.actionbarsherlock.view.MenuInflater; 
import com.actionbarsherlock.widget.ShareActionProvider; 

public class MainActivity extends SherlockActivity implements 
    ShareActionProvider.OnShareTargetSelectedListener, TextWatcher { 
    private ShareActionProvider share=null; 
    private Intent shareIntent=new Intent(Intent.ACTION_SEND); 
    private EditText editor=null; 

    @Override 
    public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.activity_main); 

    shareIntent.setType("text/plain"); 
    editor=(EditText)findViewById(R.id.editor); 
    editor.addTextChangedListener(this); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
    new MenuInflater(this).inflate(R.menu.actions, menu); 

    share= 
     (ShareActionProvider)menu.findItem(R.id.share) 
           .getActionProvider(); 
    share.setOnShareTargetSelectedListener(this); 

    return(super.onCreateOptionsMenu(menu)); 
    } 

    @Override 
    public boolean onShareTargetSelected(ShareActionProvider source, 
             Intent intent) { 
    Toast.makeText(this, intent.getComponent().toString(), 
        Toast.LENGTH_LONG).show(); 

    return(false); 
    } 

    @Override 
    public void afterTextChanged(Editable s) { 
    shareIntent.putExtra(Intent.EXTRA_TEXT, editor.getText()); 
    share.setShareIntent(shareIntent); 
    } 

    @Override 
    public void beforeTextChanged(CharSequence s, int start, int count, 
           int after) { 
    // ignored 
    } 

    @Override 
    public void onTextChanged(CharSequence s, int start, int before, 
          int count) { 
    // ignored 
    } 
} 

,하지만 같은 프로세스는 기본 작업 표시 줄에 대한 보유하고 있습니다.

+0

아직 죽은 것을 클릭해도 밝혀지지 않은 것을 추가하지 않았습니다. –

+0

@SteveSmith : 'text/plain' 공유를 지원하는 장치가있는 샘플 앱이 작동한다고 말할 수 있습니다. – CommonsWare

+0

이미지를하려고합니다. –

관련 문제