小编igo*_*gor的帖子

添加PhoneStateListener

我正在努力建立,PhoneStateListener但我得到了一个PhoneCallListener cannot be resolved to a type.

public class ButtonView extends FrameLayout  {

     PhoneCallListener phoneListener = new PhoneCallListener();
     TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
     telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
}
Run Code Online (Sandbox Code Playgroud)

在另一个例子中,我发现它写得像这样,它正在工作

public class MainActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {

        // add PhoneStateListener
        PhoneCallListener phoneListener = new PhoneCallListener();
        TelephonyManager telephonyManager = (TelephonyManager) this
            .getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
}
Run Code Online (Sandbox Code Playgroud)

我应该在代码中更改什么才能使其正常工作?

android phone-call phone-state-listener

9
推荐指数
1
解决办法
3万
查看次数

通话后回到应用程序

我正试图通过该应用程序拨打电话

我希望它在通话结束后返回应用程序

我在这个论坛上问过这个问题,但我不明白答案

如何在Android中拨打电话并在通话结束后回到我的活动中?

public void call() {
        try {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:048598077"));
            getContext().startActivity(callIntent);

        } catch (ActivityNotFoundException activityException) {
            Log.e("dialing-example", "Call failed", activityException);}
        finally {           
            EndCallListener callListener = new EndCallListener();
            TelephonyManager mTM = (TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE);
            mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
        }
    }



    private class EndCallListener extends PhoneStateListener {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            if(TelephonyManager.CALL_STATE_RINGING == state) {
                Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
            }
            if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
                //wait for phone to go offhook (probably set a boolean …
Run Code Online (Sandbox Code Playgroud)

android telephony get call back

3
推荐指数
1
解决办法
4773
查看次数

Android图片不会出现在Fragment中

我做了一个扩展活动的应用程序,一切正常.为了改进应用程序,我将活动更改为Fragment(使用onCreateView,onActivityCreated),但现在所有图像都没有显示.我没有得到任何错误.

我使用FragmentStatePagerAdapter在FragmentActivity中打开Fragments.

有什么我想念的吗?

片段XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:padding="10dp"
    >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="170dp"
        android:maxWidth="170dp"
        android:minHeight="170dp"
        android:maxHeight="170dp"
        app:srcCompat="@drawable/logo_pic"
        android:id="@+id/iv_profile_img"
        android:layout_below="@+id/relativeview_search_bar"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="12dp"
        android:background="@drawable/circle_image"
        />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

片段类:

public class TempActivity extends Fragment {

    private static final String TAG = "SearchCars";

    ArrayList<ListUser> userChatItems;
    MessagesAdapter mAdapter;

    FragmentActivity con;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_listview_users_profiles, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //con = this.getContext();
        con = this.getActivity();

        Log.v(TAG, "Initializing ...");

        View v = …
Run Code Online (Sandbox Code Playgroud)

android android-fragments fragmentstatepageradapter

1
推荐指数
1
解决办法
1411
查看次数

C++ 11枚举类命名空间块

我有一个enum classC++ 11:

enum class eDays{ SUNDAY, MONDAY, /*...*/ };
Run Code Online (Sandbox Code Playgroud)

enum class这些值的命名空间,以便它有套使用,如:

eDays::SUNDAY
Run Code Online (Sandbox Code Playgroud)

我想设置一个名称空间块,所以我不需要每次都指定名称空间:

namespace eDays {
    vector<eDays> vec = { MONDAY, SUNDAY, /*...*/ };
}
Run Code Online (Sandbox Code Playgroud)

代替:

vector<eDays> vec = { eDays::MONDAY, eDays::SUNDAY, /*...*/ };
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

c++ namespaces c++11 enum-class

0
推荐指数
1
解决办法
78
查看次数